Anaconda is a free and open-source package manager for Python and R Programming languages. It is specially designed for data science and machine learning platforms on Linux, Windows, and Mac OS. It comes with 1,500+ Python/R data science packages that can be installed individually from its repository. Anaconda is the best choice if you are looking for a platform for developing Python and R applications.
This guide will explain how to install and use Anaconda on CentOS 8.
Prerequisites
- A server running CentOS 8.
- A root password is configured on your server.
Download Anaconda Installation Script
First, you will need to download the latest version of the Anaconda installation script from its official website. At the time of writing this article, the latest version the Anaconda script is Anaconda3-2019.10.
You can also visit the and download the latest version of Anaconda installation script fromĀ Anaconda Download page.
Select your desired distribution version and download it with the following command:
wget https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh
After downloading, check the data integrity of the script by running the following command:
sha256sum Anaconda3-2019.10-Linux-x86_64.sh
You should get the following output:
46d762284d252e51cd58a8ca6c8adc9da2eadc82c342927b2f66ed011d1d8b53 Anaconda3-2019.10-Linux-x86_64.sh
Next, match the above hashes with hash available atĀ Anaconda with Python 3 on 64 bit Linux page
Once you are finished, you can proceed to the next step.
Install Anaconda
Now, start the Anaconda installation with the following command:
bash Anaconda3-2019.10-Linux-x86_64.sh
You should see the Anaconda installation welcome page in the following output:
Welcome to Anaconda3 2019.10 In order to continue the installation process, please review the license agreement. Please, press ENTER to continue >>>
Now, press Enter to continue your installation, you will be asked to accept the license terms as shown below:
Do you accept the license terms? [yes|no] [no] >>> yes
Type yes and press Enter to accept the license, you will be asked to confirm the Anaconda installation location as shown below:
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] >>>
Press Enter to confirm the default location, you will be asked to initialize Anaconda as shown below:
Preparing transaction: done Executing transaction: done installation finished. Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no] [no] >>> yes
Type yes and hit Enter to initialize the Anaconda. Once the installation has been finished, you should get the following output:
==> For changes to take effect, close and re-open your current shell. <== If you'd prefer that conda's base environment not be activated on startup, set the auto_activate_base parameter to false: conda config --set auto_activate_base false Thank you for installing Anaconda3! =========================================================================== Anaconda and JetBrains are working together to bring you Anaconda-powered environments tightly integrated in the PyCharm IDE. PyCharm for Anaconda is available at: https://www.anaconda.com/pycharm
Next, activate the Anaconda environment with the following command:
source ~/.bashrc
You can now check the installed version of the Anaconda with the following command:
conda --version
You should see the following output:
conda 4.7.12
For more information about Anaconda run the following command:
conda info
You should get the following output:
active environment : base active env location : /root/anaconda3 shell level : 1 user config file : /root/.condarc populated config files : conda version : 4.7.12 conda-build version : 3.18.9 python version : 3.7.4.final.0 virtual packages : 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/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /root/anaconda3/pkgs /root/.conda/pkgs envs directories : /root/anaconda3/envs /root/.conda/envs platform : linux-64 user-agent : conda/4.7.12 requests/2.22.0 CPython/3.7.4 Linux/4.18.0-80.7.1.el8_0.x86_64 centos/8.0.1905 glibc/2.28 UID:GID : 0:0 netrc file : None offline mode : False
Update the Anaconda
It is recommended to update the Anaconda regularly. In order to update the Anaconda, you will need to update the conda utility first.
Run the following command to update the conda utility:
conda update conda
Next, update the Anaconda using the following command:
conda update anaconda
Once the Anaconda is updated, you can verify the updated version of the Anaconda using the following command:
conda --version
You should get the following output:
conda 4.8.2
You can also verify the updated Anaconda with the following command:
conda info
You should get the following output:
active environment : base active env location : /root/anaconda3 shell level : 1 user config file : /root/.condarc populated config files : conda version : 4.8.2 conda-build version : 3.18.9 python version : 3.7.4.final.0 virtual packages : __glibc=2.28 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/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /root/anaconda3/pkgs /root/.conda/pkgs envs directories : /root/anaconda3/envs /root/.conda/envs platform : linux-64 user-agent : conda/4.8.2 requests/2.22.0 CPython/3.7.4 Linux/4.18.0-80.7.1.el8_0.x86_64 centos/8.0.1905 glibc/2.28 UID:GID : 0:0 netrc file : None offline mode : False
Setup Anaconda Environments
Before setting up Anaconda environment, it is a good idea to check which versions of Python are available for us to use. You can check it with the following command:
conda search "^python$"
You should see all available versions of the Python in the following screen:
Next, create a new environment named anaconda_env by assigning Python version 3 as shown below:
conda create --name anaconda_env python=3
You will be asked for confirmation as shown below:
Proceed ([y]/n)? y
Type y and press Enter to create a new environment:
# To activate this environment, use # # $ conda activate anaconda_env # # To deactivate an active environment, use # # $ conda deactivate
Now, activate the new environment with the following command:
conda activate anaconda_env
You should get the following shell:
(anaconda_env) [root@centos8 ~]#
You can now very the Python version using the following command:
python --version
You should get the following output:
Python 3.8.1
Next, deactivate from the Anaconda environment with the following command:
conda deactivate
In some cases, you want to create an environment with a specific version of Python.
For example, create a new Anaconda environment with Python version 3.5 using the following command:
conda create -n anaconda_env35 python=3.5
Next, activate the environment with the following command:
conda activate anaconda_env35
You should get the following shell:
(anaconda_env35) [root@centos8 ~]#
Now, check your Python version using the following command:
python --version
You should see the following output:
Python 3.5.6 :: Anaconda, Inc.
If you want to update your Python version to the latest version use the following command:
conda update python
You will be asked for confirmation as shown below:
Proceed ([y]/n)? y
Type y and press Enter to update the Python version.
Now, verify the updated Python version using the following command:
python --version
You should get the following output:
Python 3.8.1
Now, deactivate from the Anaconda environment with the following command:
conda deactivate
You can also check all Anaconda environment with the following command:
conda info --envs
You should get the following output:
conda="" environments:="" base="" root="" anaconda3="" anaconda_env="" envs="" anaconda_env35="" pre="">
If you don't need any environment. You can easily remove them using the conda remove command:
For example, to remove the environment anaconda_env run the following command:
conda remove --name anaconda_env --all
To remove the environment anaconda_env35 run the following command:
conda remove --name anaconda_env35 --all
Uninstall Anaconda
If you don't want to use Anaconda for any project then it is a good idea to remove it from your system.
First, you will need to install the anaconda-clean utility to remove the Anaconda with all configuration files from your system.
You can install this utility using the following command:
conda install anaconda-clean
Once installed, run the following command to remove the Anaconda from your system:
anaconda-clean
You will be asked for confirmation as shown below:
Delete .conda? (y/n): y
Type y and hit Enter to remove the Anaconda from your system.
Next, remove your entire Anaconda directory from the system with the following command:
rm -rf ~/anaconda3
Next, you will also need to remove the Anaconda Path line from the .bashrc file.
Open the .bashrc file as shown below:
nano ~/.bashrc
Remove the following lines:
# >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/root/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/root/anaconda3/etc/profile.d/conda.sh" ]; then . "/root/anaconda3/etc/profile.d/conda.sh" else export PATH="/root/anaconda3/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<<
Save and close the file when you are done.
Conclusion
The above guide taught us how to install Anaconda on CentOS 8. We also learned how to update Anaconda and create an environment with a specific Python version. I hope you have now enough knowledge to start your first Python project using the Anaconda.