Installing Anaconda Python on Ubuntu: A Step-by-Step Guide (2024)

Anaconda is a popular platform for data processing and machine learning. It supports Python and R programming languages and is used for large-scale data processing, predictive analytics, and scientific computing. You can install it on a local machine or scalable cloud servers from Hostman.

The Python distribution comes with 250 open-source data packages, and you can install over 7,500 additional packages from Anaconda repositories. It also includes the Conda package manager and the graphical user interface, Anaconda Navigator.

In this guide, you'll learn how to install the Anaconda distribution on the latest versions of Ubuntu.

Downloading the Anaconda Distribution

There are three options to download the Anaconda script:

  1. Download via a browser.

  2. Download using wget.

  3. Download using curl.

To download the distribution via a browser, go to the official Anaconda website in the Distribution section. Enter your email, and you’ll receive a download link. Download the 64-bit (x86) Installer for Linux.

To download the distribution using the wget utility, use the following command:

wget https://repo.anaconda.com/archive/Anaconda3-2024.06-1-Linux-x86_64.sh --output anaconda.sh

When downloading, it’s important to specify the correct version. This command requests version 2024.06, which is the latest at the time of writing. If you need another version, specify its number (e.g., 2022.05). You can find the version number and changes on the Release Notes page in the documentation.

Pay attention to the syntax. In the end, we specify --output anaconda.sh, which is an optional argument that renames the file Anaconda3-2024.06-Linux-x86_64.sh to anaconda.sh for convenience, so you don’t have to type a long, complex filename during installation.

To verify the integrity of the data, compare the cryptographic hash using the checksum (optional step). To see the SHA-256 checksum, run:

sha256sum anaconda.sh

The terminal will display a line of numbers and letters. Compare this checksum with the one provided on the Anaconda website for the corresponding version. If the hash doesn’t match, the file may not have been downloaded completely. Download it again and recheck the checksum.

Installing Anaconda

To work with Anaconda, you can use the graphical interface Navigator. For it to work correctly on Ubuntu, you need to install additional packages:

sudo apt install libgl1-mesa-glx libegl1-mesa libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6

If you don’t plan to use the graphical interface, these packages are not necessary.

Now that you have the distribution file, it's time to deploy the package manager with all components. Regardless of how you downloaded the distribution, deployment is done with a single command:

bash anaconda.sh

The installation runs in dialog mode. First, you’ll be prompted to press Enter to continue. Then, press Enter to read the license agreement. If you agree to the terms, type 'yes' and press Enter again.

The next step is choosing the installation location. You can accept the default directory by pressing Enter. If you want to specify a different folder, enter the full path.

Installing Anaconda takes a few minutes. After completion, you'll be prompted to initialize Anaconda. Type 'yes' and press Enter. The installation wizard will automatically make the necessary changes to all required directories.

Activating the Installation

Activation refers to adding a new PATH variable. This allows the system to recognize commands given to Anaconda and its components. To activate, run the following command:

source ~/.bashrc

After activation, the environment variables will be updated. Visually, this change is reflected by the appearance of the word base before the username.

To confirm the installation was successful, run:

conda list

The screen will display a list of all the installed Anaconda components.

Setting Up a Virtual Environment

By default, Anaconda uses the base environment for work. Working in a single environment can be inconvenient if you have multiple projects with different packages and versions. Anaconda Python virtual environments solve this issue. For each environment, you can specify the Python version, as well as the composition and versions of all packages.

For example, if you have a project on a Hostman server that uses Python 3.9, you can create a dedicated virtual environment for it with the following command:

conda create -n new_env python=3.9

The syntax is quite simple:

  • create: the command to create a virtual environment;

  • -n: the argument followed by the name of the new environment, in this case, new_env;

  • python=3.9: specifies the version of Python to be used inside the virtual environment.

After running the command, information about the packages to be installed will be displayed. If you agree with the list, type 'yes' and press Enter.

To switch to the environment, you need to activate it:

conda activate new_env

To exit the environment, deactivate it:

conda deactivate

Inside the environment, you can install the packages needed for your project. There are two ways to do this:

  1. Activate the environment and install packages within it.

  2. Specify the environment's name when installing a package. For example:

conda install --name new_env numpy

This command can be run from the base environment, but the numpy library will be installed inside new_env.

You can create as many virtual environments as needed for your Anaconda projects. To display a full list of environments, use the command:

conda info --envs

The current environment will be marked with an asterisk (*).

Updating Anaconda

Updating Anaconda is a simple task. Open the terminal and run the following command:

conda update --all

If updates are available for Anaconda in Python 3, they will be displayed in a list. To confirm the installation of updates, type 'y' and press Enter.

You can also update package manager components individually. For example, if you know there’s a new version of the conda command-line utility, update it with the command:

conda update conda

To update the entire distribution without checking the list of updates, use this command:

conda update anaconda

Remember to check for updates periodically to ensure you're using the latest versions of tools.

Complete Removal of Anaconda

There are two ways to uninstall the Anaconda package manager. Let’s review both.

Method 1: Manual Removal

Remove the installation directory and all other files created during installation with the following command:

rm -rf ~/anaconda3 ~/.condarc ~/.conda ~/.continuum

Method 2: Using anaconda-clean

This method is a bit more automated. You can use the anaconda-clean module to ensure all components are completely removed from the system. It helps remove configuration files. After that, you just need to delete the anaconda3 directory.

First, install the module:

install anaconda-clean

To confirm the removal, enter 'y' in the prompt and press Enter.

Run the module after installation with the following command:

anaconda-clean

The uninstaller will ask for confirmation before deleting each component. To avoid having to enter 'y' repeatedly, add the flag for automatic confirmation:

anaconda-clean --yes

After the cleanup, a backup folder will appear in the user's home directory. Inside, you’ll find a backup of the last saved state, in case you change your mind and want to restore Anaconda on Ubuntu.

Once the cleaning module has finished, you can finally delete the package manager directory:

rm -rf ~/anaconda3

To completely remove all traces of Anaconda from the system, also delete the PATH entry from the .bashrc file. This entry is added by default during installation.

Open the .bashrc file in any text editor. In this example, we'll use nano:

nano ~/.bashrc

Look for the lines where conda is initialized. If Anaconda was installed recently, these lines will be near the end of the file. To speed up the search, use the Ctrl+W key combination. The lines will look something like this:

# >>> conda initialize >>># !! Contents within this block are managed by 'conda init' !!__conda_setup="$('/home/linux/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"if [ $? -eq 0 ]; then eval "$__conda_setup"else if [ -f "/home/linux/anaconda3/etc/profile.d/conda.sh" ]; then . "/home/linux/anaconda3/etc/profile.d/conda.sh" else export PATH="/home/linux/anaconda3/bin:$PATH" fifiunset __conda_setup# <<< conda initialize <<<

Delete or comment out these lines in the file. To save changes in nano, press Ctrl + X and confirm the overwrite. The removal of Anaconda is now complete.

Conclusion

In this tutorial, we covered the key steps from installing Anaconda to fully removing it. Now you can properly install the package manager in your system, keep it up to date, and, if needed, completely remove the software components from Ubuntu.

Installing Anaconda Python on Ubuntu: A Step-by-Step Guide (2024)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6092

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.