Anaconda is a free and open source package manager of the Python and R programming languages.
Anaconda is used for data science analytics and predictive analysis. It works on all popular operating systems including Linux, Windows and Mac OS. Anaconda comes with 720 open-source packages with free community support.
Anaconda contains two components Miniconda and Conda. Conda is the package management system that is used to install multiple versions of packages. Miniconda contain python and its related packages.
In this tutorial, we will see how to install anaconda Python on Ubuntu 16.04.
Requirements
- A server running Ubuntu 16.04.
- A non-root user with sudo privileges for your server.
Install Anaconda
First, you will need to download the latest version of the Anaconda installer bash script from their official website. You can download it by running the following curl command:
curl -O https://repo.continuum.io/archive/Anaconda3-4.3.1-Linux-x86_64.sh
Once the download is completed, you will need to verify the data integrity of the installer with cryptographic hash.
You can do this with the following command:
sha256sum Anaconda3-4.3.1-Linux-x86_64.sh
Once, you are finished. You can proceed to install Anaconda with the following command:
bash Anaconda3-4.3.1-Linux-x86_64.sh
You should see the following output:
Welcome to Anaconda3 4.3.1 (by Continuum Analytics, Inc.)
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
Press ENTER to continue then Review and accept license Agreement.
Here, you will be asked to choose the location of the installation as shown below:
Anaconda3 will now be installed into this location:
/home/hitesh/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/hitesh/anaconda3] >>>
Now, press ENTER to accept the default location. The installation process will start copying files and installing required modules to your specified location.
Once the installation is complete, you should see the following output:
installation finished.
Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /home/hitesh/.bashrc ? [yes|no]
Type yes
so that you can use the conda command line utility.
Next, activate the installation by running the following command:
source ~/.bashrc
Once you are finished, you can verify your installation with the following command:
conda list
You should see the list of all the packages available through the Anaconda.
Configure Anaconda Environments
To keep all your projects organized, the Python helps you by using the anaconda virtual environment.
You can select version of Python is needed for your anaconda python environment.
First, you can check the available version of Pythons for use by running the following command:
conda search "^python$"
You can see the multiple versions of Python including Python 2 and Python 3.
Here, we will use Python 3, so you have access to python 3 packages.
First, create an environment using the Python 3 by assigning version 3 to the Python argument as shown below:
conda create --name my_env python=3
The above command will be prompted to proceed with y or n. Press Y to continue.
Next, activate the newly created environment with the following command:
source activate my_env
Once the environment is set, you should see the following output:
(my-env) hitesh@ubuntu:~$
You can now verify the version of python with the following command:
(my-env) hitesh@ubuntu:~$ python --version
You should see the following output:
Python 3.6.0 :: Continuum Analytics, Inc.
If you want to deactivate your Anaconda environment, just run the following command:
(my-env) hitesh@ubuntu:~$ source deactivate
If you want to use the specific version of Python, like Python 3.5 then run the following command to create a new environment myenv35 with Python 3.5:
conda create -n my_env35 python=3.5
If you want to update your version of Python in your environment, run the following command:
(my-env) hitesh@ubuntu:~$ conda update python
You can check all the environment you have created by running the following command:
conda info --envs
You should see the following output:
# conda environments:
#
my_env /home/hitesh/anaconda3/envs/my_env
my_env35 /home/hitesh/anaconda3/envs/my_env35
root * /home/hitesh/anaconda3
When you create an environment using conda, it will have default packages including openssl, pip, python, readline, sqlite, setuptools, tk, xz, wheel, and zlib.
If you want to add some additional package like nuppy then run the following command:
conda install --name my_env numpy
You can also add the additional package with the following command:
conda create --name my_env python=3 numpy
You can remove an environment by running the following command:
conda remove --name my_env --all
If you want to update the latest version of Anaconda, run the following command:
conda update conda
The prompt will ask of Yes or no, type y to proceed.
If you are not using anaconda and want to remove it, then run the following command:
conda install anaconda-clean
Type y to install the anaconda clean module. Once anaconda clean module is installed, run the following command to uninstall Anaconda.
anaconda-clean
The above command will create a backup folder called .anaconda_backup in your home directory:
Next, remove the entire anaconda directory with the following command:
rm -rf ~/anaconda3
Congratulations! You have successfully installed Anaconda with Python3 on Ubuntu 16.04 server.
Conclusion
I hope, you have now enough knowledge to install Anaconda also learned how to use anaconda commands. You can now easily deploy it on your production environment.
Feel free to e-mail me if you have any doubts.