Complete Guide to Install Anaconda in Linux Ubuntu

5 Main Steps to Install Anaconda in Linux Ubuntu

Anaconda is an open-source distribution for Python and R programming languages, which includes a wide range of popular scientific computing packages, data analysis tools, and machine learning libraries. Anaconda is the pre-packaged and optimized distribution of Python and R. Anaconda is a comprehensive and integrated Python/R data science platform that is available in both free and paid enterprise versions for the scientific community, data scientists, and novice users. Anaconda is suitable for data science, machine learning, large-scale processing, artificial intelligence (AI), and predictive analytics applications on common operating systems such as Windows, Linux, and more.

Installing Anaconda on your operating system makes managing libraries, packages, and dependencies easy and optimized. Due to these valuable features of Anaconda and the needs of scientific communities, we have decided to provide a step-by-step guide on how to install Anaconda in Linux Ubuntu in this article. If you work in the domains of data science, machine learning, scientific computing, and artificial intelligence, read this guide to the end to benefit from Anaconda features on Linux.

Why install Anaconda in Ubuntu?

Installing Anaconda in Ubuntu Linux is useful for various reasons. In this section of the article, you will learn about the key features and advantages of installing Anaconda on Ubuntu Linux:

  • Anaconda is a simple and efficient way to install and manage a comprehensive set of tools, libraries, and data science packages.
  • Provides the ability to update, install, and remove packages and dependencies through Conda package management.
  • Offers an integrated development environment (IDE) and interactive development environment for visualization, experimentation, and data analysis, supporting tools such as Jupyter Notebook, JupyterLab, and Spyder.
  • Includes a vast collection (over 1,000) of pre-configured packages and libraries used in data science and scientific computing (libraries such as NumPy, pandas, Matplotlib, scikit-learn, TensorFlow, PyTorch, and more).
  • Enables the creation of isolated Python environments to prevent compatibility issues and conflicts between different projects with specific library versions and configurations.
  • Ensures stability across different platforms in Ubuntu Linux and plays an effective role in facilitating collaboration and project sharing with team members using various operating systems.
  • Has a large and active community that provides resources, tutorials, and support.
  • Optimizes the performance of various libraries, which is helpful for data-intensive and computationally demanding tasks.
  • Guarantees security updates, bug fixes, and access to the latest features for tools and libraries by keeping the installed packages up to date.

Prerequisites Anaconda installation in Ubuntu

Before installing Anaconda in Ubuntu, consider the following prerequisites:

  • Access to an Ubuntu system or Ubuntu VPS.
  • Check and allocate sufficient resources (CPU, memory, storage) for managing the installation and using Anaconda, especially when working with large datasets or running resource-intensive computations.
  • Have sudo (superuser) privileges to install software.
  • Update the package lists for upgrades and new package installations (by executing the command sudo apt update).
  • Have a stable and reliable internet connection for downloading and installing Anaconda.
  • Install Python in Ubuntu VPS.
  • Install R in Ubuntu.

Quick Guide to Install Anaconda on Linux Ubuntu

Installing Anaconda on Ubuntu is a straightforward process. Here are 5 steps to install Anaconda on Ubuntu:

1. Download and Install Anaconda

The simplest and most common method to install Anaconda is to download the latest Anaconda installer bash script.

After connecting to your Ubuntu VPS, updating and synchronizing repositories, and installing packages, the first step to install Anaconda is to download Anaconda for Ubuntu system from the Anaconda download page.

Review the Anaconda download page to find the latest and most suitable version of Anaconda (usually the 64-bit version) for your Ubuntu system. Then, move to the /tmp directory. Usually, the Downloads directory contains recently downloaded items, but it’s better to move the Anaconda installer script to the /tmp directory. This is because the /tmp directory is suitable for items you won’t need after installing and running the software.

So open the Ubuntu terminal by pressing Ctrl + Alt + T or searching for “Terminal” in the programs menu and navigate to the directory where you want to download the Anaconda installer script using the cd (change directory) command:

cd /tmp

The curl command helps download the link from the official Anaconda site, so run the following command to download the latest version of Anaconda in your Ubuntu system:

curl https://repo.anaconda.com/archive/ Anaconda3-2023.09-0-Linux-x86_64.sh --output anaconda.sh

To save time and effort, we saved the command’s output to a file called anaconda.sh using the --output anaconda.sh option.

Note: In the previous command, 2023.09-0 is the version number of the Anaconda installer you want to download, at the time of typing this article, the latest version of Anaconda is 2023.09-0. You can replace it with a different or newer version in the future.

2. Verify the data integrity of the installer

After completing the download, use the SHA-256 checksum to verify the data integrity of the installer with cryptographic hash verification:

sha256sum anaconda.sh

The cryptographic hash verification relevant to the installed Anaconda version is displayed in the output. It should match the SHA256 for the Anaconda version available on the official Anaconda website.

After making sure that the hash displayed in the sha256 row on the official Anaconda site and the output of the previous command match, continue the installation process by running the Anaconda bash shell script:

bash anaconda.sh

Output:

Welcome to Anaconda3 2023.09-0
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

Receiving a welcome message in the output of the Anaconda script execution command indicates a successful installation of Anaconda in Ubuntu Linux. As the output informs you, to proceed, press the Enter key. Then, follow a series of prompts on the screen to review the license agreement, choose the installation location, and continue with the installation.

3. Follow the Installation Wizard

To proceed, read the license and press Enter to accept. You will be asked to agree to the terms and conditions, type “yes” in response to the prompt with the content “Do you approve the license terms? [yes|no]“. Finally, you must specify the location of the installation. (Press Enter to select the default location instead of setting a specific location.)

Output:

Anaconda3 will now be installed into this location:
/root/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/anaconda3] >>>

The next prompt indicates the completion of the installation process, which will be completed after a few minutes of waiting. After the installation process is complete, you will receive the following output:

Output:

...
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>>

Finally, to initialize Anaconda3, type Yes and press Enter.

4. Activate Anaconda

When the installation is finished, execute this command to activate Anaconda:

source ~/.bashrc

Alternatively, you can close and reopen the terminal to activate Anaconda.

By activating Anaconda, you enter the base Anaconda programming environment.

5. Verify Installation

Verify the installation by running the following command and observing information about the Anaconda installation:

conda info

Alternatively, you can also run the following command and confirm the installation by checking the Conda version:

conda --version

Congratulations, you have successfully installed Anaconda on your Ubuntu system and are now ready to create and manage Python environments using Conda.

Anaconda Update Guide

Regularly updating Anaconda is essential to optimize its performance. Updating Conda to the latest version is a good practice to create and manage environments. Run the following command for this purpose:

conda update -n base -c defaults conda

Or

conda update conda

After updating Conda, then update the Anaconda distribution by running the following command:

conda update anaconda

After running the previous commands, type y and press Enter.

Instructions for Configuring Anaconda Environments in Ubuntu

Setting up Anaconda environments on Ubuntu will create isolated Python environments to manage different versions of libraries and packages for various projects, aiding in preserving project-specific configurations and coherence. Reading this section of the article for creating and managing Anaconda environments is beneficial.

Create a New Environment:

To create a new Anaconda environment, you’ll need to specify a name for the desired environment and the desired Python version. Therefore, examining the available Python versions is a crucial step. To find out which Python versions are available, use the following command:

conda search "^python$"

Corresponding to the Anaconda version, you will have access to a set of Python package versions. Since Anaconda is used with Python 3 in this article, Python 3 package versions will be available. Then, to create a new Anaconda environment using the desired Python version, run the following command:

conda create --name myenv python=python_version

Replace “myenv” with your desired environment name and “python_version” with the Python version you want, and type y to confirm the output and the information given about the packages that will be installed.

Activate the Environment:

To use the Anaconda environment you created in ubuntu, you need to activate the new environment by running the following command:

conda activate myenv

Upon activating the new environment, your command prompt prefix will indicate your entry into the new environment.

Verify Python Version of the Environment:

To ensure whether the newly created environment is using your desired Python version or not, the following command is useful:

python --version

The previous command’s output displays the Python version used in the Anaconda environment.

Install Packages to Environment:

Every environment you create in Anaconda includes default packages such as openssl, ncurses, libedit, ca-certificates, sqlite, zlib, python, wheel, pip, and so on. After activating the new Anaconda environment, you can install specific packages in the new environment using the command conda install. For example:

conda install numpy pandas matplotlib

Deactivate the Environment:

To return to the base environment and deactivate the current environment, use the following command:

conda deactivate

List Environments:

To check all the environments you have created, you can type the following command:

conda env list

This command outputs a list of created environments. Alternatively, you can use the following command to inspect all of the environments:

conda info --envs

In the output, the environment with an asterisk is the currently active environment.

Remove an Environment:

When you don’t need a specific environment to use in the project, you can remove it by running the following command:

conda env remove --name myenv

replace myenv with the environment name you want to remove.

Then, to confirm the removal of the specific environment, you can run the conda info --envs command.

Note: To use an Anaconda environment, you need to activate it. For organizing and efficiently setting up Anaconda, especially when managing and working on multiple projects with different package requirements, it is recommended to deactivate the environment after finishing work with it.

Uninstalling Anaconda in Ubuntu

If you’ve concluded that you no longer need Anaconda, you can uninstall it from your Ubuntu system by executing a few commands. To remove Anaconda configuration files from your Ubuntu system, you must first install the anaconda-clean module to remove.

install anaconda-clean

After installing the anaconda-clean module, run the following command to delete all Anaconda-related files and directories:

anaconda-clean

The previous command for removing each Anaconda configuration file will prompt you for confirmation, requiring you to type “y” each time to confirm. If you don’t want this to happen, type the “– yes” option at the end of the previous command so that all relevant files are deleted without being prompted.

To remove all the relevant directories for Anaconda, run the following command:

rm -rf ~/anaconda3

To ensure the complete removal of Anaconda from your Ubuntu system, you can delete the PATH line that Anaconda added to your .bashrc file. First, access the content of the file using your preferred text editor:

nano ~/.bashrc

In the file’s content, look for Anaconda; after finding it, delete or comment out the Anaconda block. After editing the content, type “CTRL + X” to exit the file and save your changes by typing “y.”

As a result, you have now completely cleaned your Ubuntu system from the Anaconda program.

Conclusion

In general, Anaconda provides an easy and efficient way to set up a powerful data science environment in Linux Ubuntu, enhancing productivity and facilitating the development of data-driven applications and research. In this article, you learned how to install Anaconda in Linux Ubuntu and interact with the Conda command line. This article provides a comprehensive guide for using Anaconda in managing workloads for data science, analysis, large-scale data processing, and other purposes. It covered updating Anaconda, creating and setting up environments, and even removing Anaconda.

We hope this article has helped install and use Anaconda on your Ubuntu system. If you have any questions, feel free to share them with us in the comments section.

Leave a Reply

Your email address will not be published. Required fields are marked.