Installing Anaconda in Ubuntu

In this blog post, I am going to explain the steps required for installing Anaconda. More specifically, I am going to use following environment-

Important

Before we install anaconda, we need to check the default python of the system. Open terminal or press CTRL+ALT+T and use the following command-

python --version

In my system, the default python is 2.7.6. Hence, I am going to install anaconda corresponding to python 2.7. Note that anaconda installation process mentioned below is same irrespective of python version. However, you need to download the correct anaconda version depending on python version.

Anaconda Installer File

Depending on the python version, download the anaconda installer file as listed below-

In this blog post, I am going to assume that the default python version is 2.7 (ROS Indigo works on Python 2.7).

Setup

Below are the installation steps for anaconda [1].

  • Please open terminal or press CTRL+ALT+T and use the following command-
    mkdir ~/tools
    cd ~/tools
    wget https://repo.anaconda.com/archive/Anaconda2-5.2.0-Linux-x86_64.sh
    

    Generally, I keep all the tools inside tools subdirectory under $HOME. However, it is not mandatory. We have downloaded anaconda installer using wget tool. Skip this step if you already have anaconda installer file.

  • Install anaconda using the following command-
    bash Anaconda2-5.2.0-Linux-x86_64.sh -b -p anaconda
    
  • Optionally, you are free to delete or move the installer file as per your preference.
  • Make conda visible by adding conda command to $PATH. Open ~/.bashrc file by using gedit ~/.bashrc and append the following text-
    # Permanently enabling the 'conda' command
    # BUT NOT putting conda's base (root) environment on PATH
    . /home/ravi/tools/anaconda/etc/profile.d/conda.sh
    

    Please DO NOT add conda directly to $PATH. In other words, DO NOT append the following text to ~/.bashrc-

    export PATH="~/tools/anaconda/bin:$PATH"
    

    Close the terminal.

Setup Verification

In order to verify our conda installation, let’s create an environment named testenv for python 3.6. First, open a new terminal or press CTRL+ALT+T then use the following command-

conda create -n testenv python=3.6
  • Now check the conda version by using the following command-
    ravi@lab:~$ conda --version
    conda 4.5.4
    
  • Similarly, check the default python version.
    ravi@lab:~$ python --version
    Python 2.7.6
    
  • Activate testenv environment using the following command-
    conda activate testenv
    
  • Now verify the python version inside this environment. We should expect to see python 3.6. Let see-
    (testenv) ravi@lab:~$ python --version
    Python 3.6.5 :: Anaconda, Inc.
    

Hurray! We have installed anaconda without breaking ROS.

References

  1. https://stackoverflow.com/a/46696734
Written on June 5, 2018