How to Install Anaconda on Ubuntu 22.04: A Complete Guide

September 26th, 2024
How to Install Anaconda on Ubuntu 22.04: A Complete Guide

Are you finding it difficult to manage Python packages or keep track of project dependencies? Anaconda has you covered. This open-source distribution for Python and R makes it simple to manage your environments and packages with ease. It helps you manage dependencies and create reliable, isolated project environments.

This tutorial provides steps for installing Anaconda on your Ubuntu 22.04 server.

Prerequisites

To follow along, ensure you have the following:

  • An Ubuntu server

  • Familiarity with the Linux terminal

How to install Anaconda on Ubuntu 22.04

You can install Anaconda using either the interactive mode or the silent mode. In this section, you'll learn how to install Anaconda using the interactive mode. Then, you'll learn the faster approach, which installs everything automatically without any prompts.

Deploy and scale your Python projects effortlessly on Cherry Servers' robust and cost-effective dedicated or virtual servers. Benefit from an open cloud ecosystem with seamless API & integrations and a Python library.

Step 1: Access the server via SSH

To begin the installation, first log into your server via SSH by running the following command in your local terminal:

ssh user@server-ip

Input your username and the IP address of your server in place of user and server-ip.

Log in to the server

Step 2: Update system packages

Next, as a good practice, you should ensure your server's system packages are up-to-date. This helps prevent potential issues during the installation process. Refresh the package list and update outdated packages using:

apt update && apt upgrade -y

Update server packages

Step 3: Create a non-root user

You should also create and switch to a non-root user to minimize the risk of accidental changes that could affect the entire system (demo-user is used here).

adduser demo-user
usermod -aG sudo demo-user
su - demo-user

You should now be logged in as demo-user and can proceed with the installation steps.

Switch to non-root user

Step 4: Download the Anaconda installer

Next, download the Anaconda installer script using wget. You can obtain the latest version of the script directly from the Anaconda website.

First, navigate to the /tmp directory to keep your working directory clean:

cd /tmp

Change directory

Then, download the installer script and rename it to anaconda.sh:

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

Download Anaconda installer script

Step 5: Verify the download

To make sure the script wasn't corrupted during the download process, confirm its checksum using::

sha256sum anaconda.sh

Verify the integrity of the installer script

Compare the checksum you generated with the one provided on the website. If they match, the file is intact and safe to use. If not, re-download the file and verify again.

Step 6: Install Anaconda

You can continue with the installation if the checksum verification is successful.

Option 1: Interactive installation

Run the script to start the installation process:

bash anaconda.sh

You should see the End User License Agreement displayed. Use the Enter or Down arrow key to read through it. Type YES and hit Enter when asked to accept the agreement.

Accept terms

Next, you'll be asked to provide the installation location. Press Enter to accept the default location (which is your home directory) or indicate a different directory if preferred. After which the installation will start.

Specify installation location

After the installation is complete, you will be prompted to initialize Anaconda. Type YES and press Enter to have Anaconda initialize automatically at startup or type NO if you prefer to activate it manually later.

Initialize Anaconda

Option 2: Silent installation

For a faster, non-interactive installation, you can use silent mode with the -b (batch) option:

bash anaconda.sh -b

This option installs Anaconda with default settings (auto-accept of the license agreement and default installation location) and without user prompts.

Install Anaconda in batch mode

Step 7: Initialize Anaconda

If you had installed using the interactive mode and had entered NO to auto-initialization, to initialize Anaconda, run:

source <Path_to_conda>/bin/activate

You should see Anaconda activated and the prompt would change to indicate this.

After activating, run the following to add the shell functions:

conda init

Activate and initialize Anaconda

If you had entered YES, it will be initialized automatically (this sets up the environment so that Anaconda's conda command is available in the user's PATH. This usually involves modifying the shell profile to include Anaconda's binary directory in the PATH) but you would have to open another terminal or refresh your current terminal to apply changes made to the bash file using the following command:

source ~/.bashrc

Automatically activate Anaconda and apply changes to current terminal

If you installed using the silent mode, activate using:

source <Path_to_conda>/bin/activate

Then add Anaconda's shell functions using:

conda init

Initialize Anaconda

With the installation and activation complete, the base environment will automatically activate each time you open a new terminal. If you prefer not to have the base environment activated by default, you can disable this behavior by running:

conda config --set auto_activate_base False

After doing this, Conda won’t automatically activate the base environment when you open a new terminal. To use Conda, you’ll need to manually activate an environment by running conda activate.

Step 8: Verify installation

Verify the installation by checking its complete information using:

conda info

Verify Anaconda installation

Update Anaconda

If you've already installed Anaconda and want to upgrade to the latest version, you can do that by running:

conda update conda

Update Anaconda

Uninstall Anaconda

If for any reason you want to uninstall Anaconda, execute the following command:

rm -rf ~/anaconda3

Uninstall Anaconda

To apply the changes, exit your terminal session and open a new one.

Conclusion

By now, you should have installed Anaconda successfully on your Ubuntu 22.04 system. You now have a powerful tool to manage Python packages and environments.

With Anaconda up and running, why not go on to explore its features and take your projects to the next level? Read how to manage Conda environments.

Goodness is an expert in technical support, JavaScript programming, and cloud/DevOps engineering. She acquired her skills from studies in computer science and hands-on working experience. Over the years, Goodness has also honed the skills of creating, updating, and improving software documentation, writing instruction guides/manuals and technical articles for the knowledge base, and developing website content. Goodness is an expert in technical writing, DevOps engineering, Linux, Docker, containers, open-source, frontend development, and JavaScript. She also contributes to the documentation of open-source projects like Ansible and ODK-X. Goodness received her B.Sc. in Computer Science from the University of Port Harcourt and resides in Port Harcourt, Nigeria.

Start Building Now

Deploy your new Cloud VPS server in 3 minutes starting from $5.83 / month.

We use cookies to ensure seamless user experience for our website. Required cookies - technical, functional and analytical - are set automatically. Please accept the use of targeted cookies to ensure the best marketing experience for your user journey. You may revoke your consent at any time through our Cookie Policy.
build: 5bc831c3.737