OSETC TECH

How to Install Anaconda on CentOS 7 Or RHEL 7

This post explains that how to install Anaconda Tool for Python 3 on your CentOS 7 or RHEL 7 Linux server. How do I install and use the latest version of Anaconda3 on CentOS 7 or RHEL 7 system.

What is Anaconda?


Anaconda is a free and open-source distribution of the Python and R programming languages for scientific computing, that aims to simplify package management and deployment. You can use package management system conda to manage versions for all of packages.

The open source Anaconda Distribution is the fastest and easiest way to do Python and R data science and machine learning on Linux, Windows, and Mac OS X. It’s the industry standard for developing, testing, and training on a single machine.

Downloading Anaconda Installer


Anaconda3 or Anaconda2 package is not available on the default CentOS or RHEL repositories. So you need to get it from the official download page of Anaconda. You can use the following wget command to get the latest version of Anaconda3 or Anaconda2 installation script. The current stable version is Anaconda 2018.12. Type:

$ wget https://repo.anaconda.com/archive/Anaconda3-2018.12-Linux-x86_64.sh

Outputs:

[root@devops ~]# wget https://repo.anaconda.com/archive/Anaconda3-2018.12-Linux-x86_64.sh .
--2019-03-25 05:53:13-- https://repo.anaconda.com/archive/Anaconda3-2018.12-Linux-x86_64.sh
Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.130.3, 104.16.131.3, 2606:4700::6810:8203, ...
Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.130.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 684237703 (653M) [application/x-sh]
Saving to: ‘Anaconda3-2018.12-Linux-x86_64.sh’

100%[=========================================================================================>] 684,237,703 7.16MB/s in 92s

2019-03-25 05:54:46 (7.10 MB/s) - ‘Anaconda3-2018.12-Linux-x86_64.sh’ saved [684237703/684237703]

--2019-03-25 05:54:46-- http://./
Resolving . (.)... failed: No address associated with hostname.
wget: unable to resolve host address ‘.’
FINISHED --2019-03-25 05:54:46--
Total wall clock time: 1m 33s
Downloaded: 1 files, 653M in 1m 32s (7.10 MB/s)

If you want to download Anaconda2 package, you can use the following command:

$ wget https://repo.anaconda.com/archive/Anaconda2-2018.12-Linux-x86_64.sh

Then the Anaconda installation script has been downloaded to your local disk on your CentOS system.

[root@devops ~]# ls -alh Anaconda3-2018.12-Linux-x86_64.sh
-rw-r--r--. 1 root root 653M Dec 21 15:23 Anaconda3-2018.12-Linux-x86_64.sh

Verify the Data Integrity of the Anaconda Bash Script


You need to check the data integrity of installation script of Anaconda downloaded in the above step. you can use MD5 or SHA-256 tool to check it, type the following command:

$ md5sum Anaconda3-2018.12-Linux-x86_64.sh

Or

$ sha256sum Anaconda3-2018.12-Linux-x86_64.sh

Outputs:

[root@devops ~]# md5sum Anaconda3-2018.12-Linux-x86_64.sh
c9af603d89656bc89680889ef1f92623 Anaconda3-2018.12-Linux-x86_64.sh
[root@devops ~]# sha256sum Anaconda3-2018.12-Linux-x86_64.sh
1019d0857e5865f8a6861eaf15bfe535b87e92b72ce4f531000dc672be7fce00 Anaconda3-2018.12-Linux-x86_64.sh

Then you can go the official hash web page of Anaconda to confirm if it matches the hashes or checksums. Refer to the below screenshot about hash.

If the hashes or checksums is correct, you can ready to install Anaconda tool on your system.

Run the Anaconda Installation Script


If you want to install Anaconda Tool on your system, you just need to run the Anaconda installation scripts that you downloaded in the above step to install Anaconda for python 3.7 on your CentOS or RHEL 7 Linux server. Execute the following command with Bash shell, type:

$ bash Anaconda3-2018.12-Linux-x86_64.sh

Outputs:

[root@devops ~]# bash Anaconda3-2018.12-Linux-x86_64.sh

Welcome to Anaconda3 2018.12

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

You need to press Enter key to review the license agreement to continue the installation process of Anaconda on your CentOS system. Then press Space key to get the end of the license terms. Then you will be asked to accept the license terms.

Do you accept the license terms? [yes|no]
[no] >>>

You need to enter yes to accept the license terms to continue the installation process. then you can specify one installation location or press Enter key to accept the default location.

Anaconda3 will now be installed into this location:
/root/anaconda3

- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below

[/root/anaconda3] >>>

After the installation is completed, you should see the following installation output:

installing: widgetsnbextension-3.4.2-py37_0 ...
installing: ipywidgets-7.4.2-py37_0 ...
installing: jupyterlab-0.35.3-py37_0 ...
installing: spyder-3.3.2-py37_0 ...
installing: _ipyw_jlab_nb_ext_conf-0.1.0-py37_0 ...
installing: jupyter-1.0.0-py37_7 ...
installing: anaconda-2018.12-py37_0 ...
installing: conda-4.5.12-py37_0 ...
installing: conda-build-3.17.6-py37_0 ...
installation finished.

You will get the following output to confirm if you want the installer to prepend the Anaconda3 install location to PATH environment variable, type yes.

Do you wish the installer to initialize Anaconda3
in your /root/.bashrc ? [yes|no]
[no] >>> yes

Initializing Anaconda3 in /root/.bashrc
A backup will be made to: /root/.bashrc-anaconda3.bak

For this change to become active, you have to open a new terminal.

Thank you for installing Anaconda3!

Then the installer will ask you if you wish to proceed with the installation of Microsoft VSCode, you can type yes to install it or type no to decline.

Anaconda is partnered with Microsoft! Microsoft VSCode is a streamlined
code editor with support for development operations like debugging, task
running and version control.

To install Visual Studio Code, you will need:
- Administrator Privileges
- Internet connectivity

Visual Studio Code License: https://code.visualstudio.com/license

Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]
>>> no

Activate the Installation of Anaconda


After installed Anaconda3 on your system, you still need to activate the installation of Anaconda3, and it has been added into the /root/.bashrc file , type:

$ source ~/.bashrc

Test the Installation of Anaconda


You can use the following conda command to verify if the installation of Anaconda has been installed successfully, type:

$ conda list

Or

$ conda info

You should get the following outputs:

[root@devops ~]# conda list
# packages in environment at /root/anaconda3:
#
# Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py37_0
alabaster 0.7.12 py37_0
anaconda 2018.12 py37_0
anaconda-client 1.7.2 py37_0
anaconda-navigator 1.9.6 py37_0
anaconda-project 0.8.2 py37_0
asn1crypto 0.24.0 py37_0
astroid 2.1.0 py37_0
astropy 3.1 py37h7b6447c_0
atomicwrites 1.2.1 py37_0
attrs 18.2.0 py37h28b3542_0
babel 2.6.0 py37_0
backcall 0.1.0 py37_0
......

[root@devops ~]# conda info

active environment : base
active env location : /root/anaconda3
shell level : 1
user config file : /root/.condarc
populated config files :
conda version : 4.5.12
conda-build version : 3.17.6
python version : 3.7.1.final.0
base environment : /root/anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/linux-64
https://repo.anaconda.com/pkgs/pro/noarch
package cache : /root/anaconda3/pkgs
/root/.conda/pkgs
envs directories : /root/anaconda3/envs
/root/.conda/envs
platform : linux-64
user-agent : conda/4.5.12 requests/2.21.0 CPython/3.7.1 Linux/3.10.0-957.10.1.el7.x86_64 centos/7 glibc/2.17
UID:GID : 0:0
netrc file : None
offline mode : False

Setup Anaconda Environments


You can create an Anaconda environments with conda command, for example, you want to create a python3 environment called python3test with the following command:

$ conda create --name python3test python=3

Outputs:

(base) [root@devops ~]# conda create --name python3test python=3
Collecting package metadata: done
Solving environment: done

## Package Plan ##

environment location: /root/anaconda3/envs/python3test

added / updated specs:
- python=3

The following packages will be downloaded:

package | build
---------------------------|-----------------
ca-certificates-2019.1.23 | 0 126 KB
certifi-2019.3.9 | py37_0 155 KB
libedit-3.1.20181209 | hc058e9b_0 188 KB
openssl-1.1.1b | h7b6447c_1 4.0 MB
pip-19.0.3 | py37_0 1.8 MB
python-3.7.2 | h0371630_0 36.4 MB
setuptools-40.8.0 | py37_0 643 KB
sqlite-3.27.2 | h7b6447c_0 1.9 MB
wheel-0.33.1 | py37_0 39 KB
------------------------------------------------------------
Total: 45.2 MB

The following NEW packages will be INSTALLED:

ca-certificates pkgs/main/linux-64::ca-certificates-2019.1.23-0
certifi pkgs/main/linux-64::certifi-2019.3.9-py37_0
libedit pkgs/main/linux-64::libedit-3.1.20181209-hc058e9b_0
libffi pkgs/main/linux-64::libffi-3.2.1-hd88cf55_4
libgcc-ng pkgs/main/linux-64::libgcc-ng-8.2.0-hdf63c60_1
libstdcxx-ng pkgs/main/linux-64::libstdcxx-ng-8.2.0-hdf63c60_1
ncurses pkgs/main/linux-64::ncurses-6.1-he6710b0_1
openssl pkgs/main/linux-64::openssl-1.1.1b-h7b6447c_1
pip pkgs/main/linux-64::pip-19.0.3-py37_0
python pkgs/main/linux-64::python-3.7.2-h0371630_0
readline pkgs/main/linux-64::readline-7.0-h7b6447c_5
setuptools pkgs/main/linux-64::setuptools-40.8.0-py37_0
sqlite pkgs/main/linux-64::sqlite-3.27.2-h7b6447c_0
tk pkgs/main/linux-64::tk-8.6.8-hbc83047_0
wheel pkgs/main/linux-64::wheel-0.33.1-py37_0
xz pkgs/main/linux-64::xz-5.2.4-h14c3975_4
zlib pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3

Proceed ([y]/n)? y

Downloading and Extracting Packages
certifi-2019.3.9 | 155 KB | ##################################### | 100%
pip-19.0.3 | 1.8 MB | ##################################### | 100%
sqlite-3.27.2 | 1.9 MB | ##################################### | 100%
setuptools-40.8.0 | 643 KB | ##################################### | 100%
wheel-0.33.1 | 39 KB | ##################################### | 100%
ca-certificates-2019 | 126 KB | ##################################### | 100%
libedit-3.1.20181209 | 188 KB | ##################################### | 100%
python-3.7.2 | 36.4 MB | ##################################### | 100%
openssl-1.1.1b | 4.0 MB | ##################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate python3test
#
# To deactivate an active environment, use
#
# $ conda deactivate

Then you can activate this environment with the following command:

$ conda activate python3test

Outputs:

(base) [root@devops ~]# conda activate python3test
(python3test) [root@devops ~]#

If you want to list all installed packages for the current python3test environment, just type the following command:

$ conda list

Outputs:

(python3test) [root@devops ~]# conda list
# packages in environment at /root/anaconda3/envs/python3test:
#
# Name Version Build Channel
ca-certificates 2019.1.23 0
certifi 2019.3.9 py37_0
libedit 3.1.20181209 hc058e9b_0
libffi 3.2.1 hd88cf55_4
libgcc-ng 8.2.0 hdf63c60_1
libstdcxx-ng 8.2.0 hdf63c60_1
ncurses 6.1 he6710b0_1
openssl 1.1.1b h7b6447c_1
pip 19.0.3 py37_0
python 3.7.2 h0371630_0
readline 7.0 h7b6447c_5
setuptools 40.8.0 py37_0
sqlite 3.27.2 h7b6447c_0
tk 8.6.8 hbc83047_0
wheel 0.33.1 py37_0
xz 5.2.4 h14c3975_4
zlib 1.2.11 h7b6447c_3

Conclusion


You should know that how to install Anaconda for Python3 on CentOS 7 or RHEL 7 from this guide. If you want to see more information about Anaconda, you can go the official web site of Anaconda directly.