How to Install Anaconda on Ubuntu 24.04
Introduction
Anaconda is an open-source distribution for Python and R programming languages that simplifies package and dependency management for data science. To install Anaconda on Ubuntu 24.04, you’ll gain access to the Conda package manager along with a variety of pre-built machine-learning libraries and tools.
This article explains how to install Anaconda on Ubuntu 24.04 and managing isolated user environments using Conda.
Prerequisites
Before you begin:
- Deploy an Ubuntu 24.04 instance on Vultr.
- Access the instance using SSH as a non-root user with sudo privileges.
- Update the instance.
Install Anaconda on Ubuntu 24.04
Anaconda is not available in the default Ubuntu package repositories. Follow the steps below to install the package by downloading a script from the Anaconda repository.
Visit the Anaconda archives directory to check and download the latest installation script.
console$ wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh
Run the script using Bash.
console$ bash Anaconda3-2024.06-1-Linux-x86_64.sh
Press Enter when prompted to review the Anaconda license agreement.
Welcome to Anaconda3 2024.06-1 In order to continue the installation process, please review the license agreement. Please, press ENTER to continue >>>
Press Space to browse through the license agreement.
Enter
yes
and press Enter to accept the license agreement.Version 4.0 | Last Modified: March 31, 2024 | ANACONDA TOS Do you accept the license terms? [yes|no] >>> yes
Verify the default installation path, typically
anaconda3
in your user home directory and press Enter to install Anaconda.Anaconda3 will now be installed into this location: /vultr/anaconda3 - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below [/vultr/anaconda3] >>>
Enter
yes
and press Enter to update your shell environment and initialize Conda.Do you wish to update your shell profile to automatically initialize conda? This will activate conda on startup and change the command prompt when activated. If you'd prefer that conda's base environment not be activated on startup, run the following command when conda is activated: conda config --set auto_activate_base false You can undo this by running `conda init --reverse $SHELL`? [yes|no] [no] >>> yes
Reload the
.bashrc
shell configuration to apply the Anaconda changes to your environment.console$ source ~/.bashrc
View the installed Conda version.
console$ conda --version
Output:
conda 24.5.0
List all packages in the default Conda environment.
console$ conda list
Output:
# Name Version Build Channel _anaconda_depends 2024.06 py312_mkl_2 _libgcc_mutex 0.1 main _openmp_mutex 5.1 1_gnu abseil-cpp 20211102.0 hd4dd3e8_0 aiobotocore 2.12.3 py312h06a4308_0 aiohttp 3.9.5 py312h5eee18b_0 aioitertools 0.7.1 pyhd3eb1b0_0 aiosignal 1.2.0 pyhd3eb1b0_0 alabaster 0.7.16 py312h06a4308_0 altair 5.0.1 py312h06a4308_0 anaconda-anon-usage 0.4.4 py312hfc0e8ea_100 anaconda-catalogs 0.2.0 py312h06a4308_1 anaconda-client 1.12.3 py312h06a4308_0 anaconda-cloud-auth 0.5.1 py312h06a4308_0 anaconda-navigator 2.6.0 py312h06a4308_0 anaconda-project 0.11.1 py312h06a4308_0 annotated-types 0.6.0 py312h06a4308_0 ............................. ```
Manage Conda Environments
A Conda environment contains specific dependencies, packages, and Python versions that match your project needs. The isolated environment is different from your global system environment. Follow the steps below to create and manage Conda environments.
Create a new
myenv
Conda environment with a specific Python version, such as3.8
.console$ conda create --name myenv python=3.8
Enter Y when prompted to install all necessary dependency packages in the new environment.
Activate the new Conda environment.
console$ conda activate myenv
Verify that your shell prompt changes to the new environment.
console(myenv) vultr@Server:~$
List all outdated packages in your environment.
console$ conda update --all
Enter Y when prompted to install new packages.
Create a
test
environment by cloning the existingmyenv
environment.console$ conda create --name test --clone myenv
Install a new package, such as
requests
in the environment.console$ conda install requests
To install packages from different sources like conda-forge, run
conda install -c conda-forge package_name
and replacepackage_name
with the name of the package that you want to install.Clear all unused packages and caches from your environment.
console$ conda clean --all
Export the Conda environment to a file like
environment.yml
.console$ conda env export > environment.yml
Import the environment to reinstall all necessary packages and dependencies.
console$ conda env create -f environment.yml
Use
conda run
to execute commands in a specific environment without activating it. For example, run thescript.py
file in themyenv
environment.console$ conda run -n myenv python -c "print('Hello, World')"
Output:
Hello, World
Conclusion
You have installed Anaconda on Ubuntu 24.04 and managed Conda environments on the server. Anaconda provides an advanced platform for managing dependency and packages to match your project's needs. Use Anaconda when running multiple projects that require different packages and dependencies. For more information, please visit the official Anaconda documentation.