Skip to main content
How To

How to Install Conda on Ubuntu

Conda is the open source package manager that is hugely popular among folks in data science and AI. Learn how to install Conda on Ubuntu Linux.

Pratham Patel

Conda is an open source package manager, like apt on Debian derivatives, pip for Python. It is mostly used in the fields of data science, machine learning, artificial intelligence, scientific computing, etc.

In this tutorial, I'll show you the ways to install Conda on Ubuntu.

Conda? Which one?

There are three items that are referred to as "conda". They are as follows:

  • Conda
  • Anaconda
  • Miniconda

So what is the difference?

Conda is the actual package manager, whereas Anaconda and Miniconda are the software distributions that include helpful software.

So, you use the conda command to install packages that are provided by Anaconda or Miniconda.

As the name implies, Miniconda has less software included compared to Anaconda.

The only system requirement (at the time of writing this) is that you have 400 MB of free disk space and 3 GB of free disk space for Miniconda and Anaconda respectively.

🙌
To get the Conda package manager, you can install either Anaconda or Miniconda packages. Conda is installed with these packages.

Unfortunately, Ubuntu doesn't provide either Anaconda or Miniconda from its repositories. That means you'll have to use the official ways of installing these packages on your system. No simple apt-get install conda here.

You'll need to be familiar with Linux command lines a bit to install the packages.

Installing Miniconda on Ubuntu

Miniconda is available for three versions of Python. At the moment of writing this article, it is offered for Python versions 3.7, 3.8 and 3.9.

Miniconda is offered for four CPU architectures. They are as follows:

  • Intel x86 64-bit
  • ARM 64-bit
  • PowerPC 64-bit
  • IBM System/390 64-bit (IBM Z)

Step 1: Download the installer script

To download the Miniconda installer script, visit this downloads page.

Select the installer script that contains the version of Python you need along with the correct CPU architecture.

The installer is a shell script, so make sure that it can be executed. Do so with the following command:

chmod -v +x Miniconda*.sh

Running this command will make the installer script executable.

I want the Miniconda installer for Intel x86 with Python 3.9, so the file I download is named Miniconda3-py39_4.12.0-Linux-x86_64.sh. I will use the wget command to do so.

$ wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh

$ chmod -v +x Miniconda*.sh
mode of 'Miniconda3-py39_4.12.0-Linux-x86_64.sh' changed from 0664 (rw-rw-r--) to 0775 (rwxrwxr-x)

And with that, proceed to the next step.

DigitalOcean – The developer cloud
Helping millions of developers easily build, test, manage, and scale applications of any size – faster than ever before.
Get started on DigitalOcean with a $100, 60-day credit for new users.

Step 2: Verify hash

Hash verification is the process to determine that the file you downloaded was in fact the correct one, and not incomplete nor compromised.

The hash for each file is right next to the download button on the above-mentioned website. It is under the "SHA256 hash" column.

To verify that the installer you downloaded, make note of the hash that is available on the above-linked webpage.

Now, run the following command with appropriate changes:

echo "HASH_OF_INSTALLER *INSTALLER_SCRIPT_NAME" | shasum --check

The hash for my file (as mentioned above) is 78f39f9bae971ec1ae7969f0516017f2413f17796670f7040725dd83fcff5689. For my case, I will modify the above command in the following manner:

echo "78f39f9bae971ec1ae7969f0516017f2413f17796670f7040725dd83fcff5689 *Miniconda3-py39_4.12.0-Linux-x86_64.sh" | shasum --check

Once you run this command, you will get either output.

The one provided right below is when the hash matched and it is considered safe to use the downloaded installer.

$ echo "78f39f9bae971ec1ae7969f0516017f2413f17796670f7040725dd83fcff5689 *Miniconda3-py39_4.12.0-Linux-x86_64.sh" | shasum --check
Miniconda3-py39_4.12.0-Linux-x86_64.sh: OK

The output provided below is when the hash did not match. In this case, download the file again and verify the hash again. Proceed only if the hash matches.

$ echo "78f39f9bae971ec1ae7969f0516017f2413f17796670f7040725dd83fcff5689 *Miniconda3-py39_4.12.0-Linux-x86_64.sh" | shasum --check
Miniconda3-py39_4.12.0-Linux-x86_64.sh: FAILED
shasum: WARNING: 1 computed checksum did NOT match

Step 3: Execute the Installer

The installer is a Shell script, so the easiest way to install Miniconda is to use the following command:

./Miniconda3-py39_4.12.0-Linux-x86_64.sh

Do note that your installer will have a different name.

Upon executing the script, it will ask you to agree to the EULA (End User License Agreement). What choice do we have than agree to it if we want to use it? So agree to the agreement.

You will be asked a "yes" or a "no" to convey your agreement.

After that, you will be asked about the installation location for Miniconda. Usually, it will create a folder called miniconda3 and that will be created in your home directory (~/miniconda).

You can press Enter to use this location or specify one of your own. I recommend using the default location.

Next, the installer will ask if you wish to run the conda init command. This command will modify your .bashrc file so that the PATH variable contains the path to the software installed by Miniconda. At the moment of writing this, it is an experimental feature, so I advise you say "no".

You can assume this to be experimental as long as the default option remains "no".

Step 4: Update PATH variable

For now, we have to change our PATH variable manually. To do so, add the following lines to your ~/.bashrc file:

if ! [[ $PATH =~ "$HOME/miniconda3/bin" ]]; then
  PATH="$HOME/miniconda3/bin:$PATH"
fi

The above code snippet checks if the ~/miniconda3/bin directory is in the PATH variable or not. If it isn't present, it is added. If it already is present, nothing extra is done.

Once that is done, to bring this change into effect do either one of the following:

  • Close and re-open the terminal
  • Run the source ~/.bashrc command in the terminal

That will update the PATH variable so you can invoke conda directly, without having to type the full/relative path.

Step 5: Verify installation

Finally, the last step is to verify that the installation of Miniconda was successful.

The easiest way to verify the installation, run the following command:

conda list

Running this command should list packages (roughly 40). That means that Miniconda was installed successfully. You may remove the installer script that was downloaded.

Rest easy soldier, because now you have Miniconda installed on your computer :)

Customer Referral Landing Page - $100
Cut Your Cloud Bills in Half Deploy more with Linux virtual machines, global infrastructure, and simple pricing. No surprise bills, no lock-in, and the
Get started on Linode with a $100, 60-day credit for new users.

Installing Anaconda

Anaconda, unlike Miniconda, is only offered for the latest version of Python. It supports the following CPU architectures:

  • Intel x86 64-bit
  • PowerPC 64-bit
  • ARM 64-bit
  • IBM System/390 64-bit (IBM Z)

Step 1: Download the installer script

The Anaconda installer is offered as a shell script on this webpage. Download the script that is written for your CPU architecture.

The installer script is ~700 MB in size, so downloading it will take a while. Do try to be patient ;)

Once done, make the script executable with the chmod command like so :

chmod -v +x Anaconda*.sh

Since Ubuntu is a Linux distribution and my CPU architecture is x86, I will download the Anaconda3-2022.05-Linux-x86_64.sh script. I will download it using the wget command.

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

$ chmod -v +x Anaconda3-2022.05-Linux-x86_64.sh
mode of 'Anaconda3-2022.05-Linux-x86_64.sh' changed from 0664 (rw-rw-r--) to 0775 (rwxrwxr-x)

After downloading the appropriate installer and making it executable, continue with the next step.

Step 2: Verify hash

Verifying the hash of any file allows you to determine if the file is an incomplete download or if you have a compromised file.

You can find the hash for your file at this webpage.

To verify the checksum, use the following command with appropriate substitutions:

echo "HASH_OF_INSTALLER *INSTALLER_SCRIPT_NAME" | shasum --check

The hash for my installer (Anaconda3-2022.05-Linux-x86_64.sh) is a7c0afe862f6ea19a596801fc138bde0463abcbce1b753e8d5c474b506a2db2d. Therefore, I will run the following command:

$ echo "a7c0afe862f6ea19a596801fc138bde0463abcbce1b753e8d5c474b506a2db2d *Anaconda3-2022.05-Linux-x86_64.sh" | shasum --check
Anaconda3-2022.05-Linux-x86_64.sh: OK

As you can see, I got an OK in the output. This means that the hash matched and it is safe to use this file.

If you see FAILED in the output, it means that something is wrong with the file. In that case, re-download the file and verify the hash again, until the hash matches.

Step 3: Execute the Installer

The installer for Anaconda is a shell script and can be easily executed in following fashion:

./Anaconda3-2022.05-Linux-x86_64.sh

Please note that your installer script might have a different name. Do not copy paste everything :)

The Anaconda installer has an EULA, which you do need to agree to if you want to use it. So yeah, you have to agree to it.

Once agreed, it will assume that the default installation location is ~/anaconda3, but that can be changed here. I advice you not to change this and simply press 'Enter' at this stage of installation.

With that, the installation will copy necessary files at the ideal places.

At the end, you will be asked a question "Should the installer run conda init on your behalf". To this, answer "no". You have to do this manually in the next step.

You can assume this to be experimental as long as the default option remains "no".

Step 4: Update the PATH variable

In the previous step I told to answer 'no' for conda init, that is because that is considered experimental. At least at the time of writing this article.

So, let us do that manually.

In your ~/.bashrc, add the following 3 lines and save it.

if ! [[ $PATH =~ "$HOME/anaconda3/bin" ]]; then
    PATH="$HOME/anaconda3/bin:$PATH"
fi

This checks if the ~/anaconda/bin directory is present in the PATH variable.

If the directory is not present, it is added to the PATH variable. Otherwise nothing is done.

There are two ways to make this change come into effect:

  • Close the terminal and re-open it
  • Run the source ~/.bashrc command in the terminal

This will re-read the ~/.bashrc file and make sure that ~/anaconda3/bin is present in the PATH variable.

Step 5: Verify Installation

At last! Anaconda is installed, but, like Schrödinger's cat, we need to open the box to see the results.

So let us run a conda command and see what the output is. The command given below will list all the software that is installed:

conda list

If you get a list of packages that are installed, congratulations!

Anaconda is successfully installed.

Learn Linux Quickly - Linux Commands for Beginners
Learn Linux Quickly doesn’t assume any prior Linux knowledge, which makes it a perfect fit for beginners. Nevertheless, intermediate and advanced Linux users will still find this book very useful as it goes through a wide range of topics. Learn Linux Quickly will teach you the following topics:Insta…

Conclusion

As you can see, there is no easy 'apt install conda' here. You have to put quite some effort to get Conda on your Ubuntu system.

In my opinion, you should start with Miniconda as it takes less space and doesn't need the latest Python version. If you go for Anaconda, you need to upgrade the Python version on your Ubuntu system first.

I know it's somewhat a complicated tutorial and you may very well have some doubts. Feel free to ask your questions in the comment sections.

Pratham Patel