Install Anaconda without root privilege on CentOS

Without root privilege, the installation may occur some unexpected incidents which really drive me crazy

So I listed error cases and solutions, hope they would be helpful.

Environment

First, the installation is done on remote server, which means we do not have sudo access.

Below is the OS version:

CentOS Linux release 7.7.1908 (Core)
NAME=”CentOS Linux”
VERSION=”7 (Core)”

Installation

Step 1. Download source code

From here: https://www.anaconda.com/download/#linux

I downloaded Anaconda 3.

Step 2 Install Anaconda

Open a terminal window in the same direction of where you downloaded Anaconda, and:

1
bash Anaconda3-2019.10-Linux-x86_64.sh

In the end of installation, you will see:

1
2
3
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>>

Then input yes, ENTER.

Step 3 Activate conda

The previous step add the path of conda to ~/.bashrc, however, you still need to source it. When you run:

1
source ~/.bashrc

or if it fails, then run:

1
2
anaconda3/bin/conda init tcsh
source ~/.tcshrc

This is because the .bashrc initialization is bash-specific. However, Conda does also support initialization for csh/tcsh, so if bash fails, try to use tcsh as alternatives.

Thanks for [Link]

Step 4 Verify conda

1
conda info

Step 5 Install python packages using conda

Note that python3.7 is inherently installed in anaconda3, you can install it again by running:

1
2
conda install python
conda install pip

and install other python packages by running:

1
2
conda install numpy
conda install tensorflow

or something else.

Step 6 Activate conda environment

1
conda activate py37

Error cases

Illegal variable name when source ~/.bashrc

when source ~/.bashrc returns Illegal variable name, then you can re-initialize conda by running:

1
2
anaconda3/bin/conda init tcsh
source ~/.tcshrc

where anaconda3 is the directory to where you put anaconda3.

Installing a different version of Python

1. Create the new environment

  • To create the new environment for Python 3.6, in your terminal window or an Anaconda Prompt, run:

    1
    conda create -n py36 python=3.6 anaconda
  • To create the new environment for Python 2.7, in your terminal window or an Anaconda Prompt, run:

    1
    conda create -n py27 python=2.7 anaconda

2. Activate

1
conda activate py27

or

1
conda activate py36

3. Deactivate

When you want to deactivate it, simply run:

1
conda deactivate