Installing Anaconda Python on a Remote Linux Server

Anaconda is a very popular Python distribution and a large number of packages a typical user may need are pre-installed. It is however quite large, if you just need a basic python with a small number of packages you could consider miniconda instead.

These are instructions on how to install the Anaconda Python distribution on a remote Linux server. It should not matter which operating system your local machine is running. You can also use this method to install anaconda if you are sitting at a Linux workstation.

Log on to the remote server using a ssh client (unless you are sitting at the machine you want to install anaconda on).

On your local machine go to https://www.anaconda.com/distribution/#download-section

Select the Linux version as shown in the image below.

Anaconda web page

Right click on the 'Download' button and select 'Copy link address'. Always choose Python 3.x unless there is a very good reason to choose Python 2.x which becomes unsupported in 2020 (see https://pythonclock.org).

Anaconda web page

We will use a program called 'wget' to download the installation package. In the terminal on the remote server type 'wget' then right click with the mouse in the terminal window and choose 'Paste'.

Anaconda web page

Press the return key. The anaconda installation package, which at the time of writing this was called Anaconda3-2019.07-Linux-x86_64.sh will start to download on to the remote server.

The complete command should be something like that below.

wget https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh
Anaconda web page

Install the package using the command

bash Anaconda3-2019.07-Linux-x86_64.sh
Use the tab key to complete long file names.

Anaconda web page

Accept the license terms.

Anaconda web page

Agree to the default location.

Anaconda web page

Now wait a while while the Anaconda is downloaded and installed.

Anaconda web page

Say yes to allow the installer to initialise Anaconda3 each time you log in. Log in again.

So where is my shiny new python?

If you type 'which python' you will see the default python is not the anaconda one we have just installed. So at this point we have two options.
  1. The quick and dirty solution by changing your PATH variable.
  2. The recommended method using python virtual environments.

Changing your PATH variable

Firstly for the quick and dirty method, define an alias command in your .bashrc which will put the anaconda bin directory at the start of your PATH variable meaning that the default python will be the anaconda python. Something like the following will do this
alias ana3='export PATH=/home/your username here/anaconda3/bin:${PATH}'
When you type ana3 and your PATH will be ammended to put the anaconda bin directory first, making the anaconda python the default python.

Python Virtual Environments

The recommended, and more flexible way, is to use Python Virtual Environments. The anaconda install has put the condabin directory at the start of your PATH, this directory contains only one executable which is the conda program.

Let's create a virtual environment called env1 which has a specific version of python3.

conda create -n env1 python=3.7.3 anaconda
and the appropriate packages will be installed from the anaconda repositry. Lets activate this environment so we can use it.
conda activate env1
Your prompt will change, and if you type 'which python' or 'python --version' you will find that the correct version of python is being called. You can stop using and environment or deactivate an environment using the command:
conda deactivate
If you decide that you no longer want to use this environment, you can delete it with the following command.
conda remove -n env1 --all

More Examples of Virtual Environments

Let's say you want to create a new environment to develope some some software possibly for data conversion. The comand to use would be:
 
conda create -n data_conversion_prog anaconda
Maybe you have some python2 code you want to use, despite the fact it is a bad idea, see https://pythonclock.org. You can install a version of python2 using this command:
conda create -n env_obsolete python=2.7.16 anaconda
A full description of python environments can be found at https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html.

Oh No! Making Anaconda Python the Default has Broken the x2go Software

Unfortunately, x2go does not like anaconda python as the default python.

One solution is to stop it automatically becoming the default python on login, and make a command that you type to make it the default python later.

So log on to the remote server using putty or mobaXterm not x2go.

Edit your .bashrc file using this command

nano ~/.bashrc
at the end of the file, you will see the stuff the anaconda installer put in there, it starts with
# >>> conda initialize >>>
comment that stuff out by putting a '#' at the start of each line until you get to
# <<< conda initialize <<<
then add this line:
alias ana3='export PATH=${HOME}/anaconda3/bin:$PATH'
Then save your .bashrc and log out.

Try connecting with x2go again, it should work. But when you type

which python
you get the old system python, so type
ana3
which python
you should get the anaconda python as the default python.


Rhys Morris
Last modified: Tuesday, 23 February 2021