Knowledgebase

How to Install Anaconda on Ubuntu 22.04 Print

  • 0

Introduction

Conda is an open-source tool that performs package and environment management. As a package manager, its functionality relates to any other package management tool such as the pip Python package manager. As an environment manager, it helps to create and manage different environments. Sometimes different applications have different versions of the same software. Managing the different versions is a difficult task, and environments solve this problem. Each environment can host specific software and dependencies, independent of other environments. Conda is available to install as part of either Anaconda or Miniconda.

Anaconda is pre-packaged with a smaller set of Python packages. This makes it the preferred choice for servers with storage limitations. It's also the preferred option in situations that require only a small set of tools. Where Anaconda pre-installs a few hundred common packages such as PyTorch, Transformers, Numpy, and Scipy, Miniconda only installs a few dozen basic utility packages.

Choose Anaconda if:

  • A project is large or needs many different packages
  • The project is exploratory and while starting, you don't know what tools it requires
  • You don't want to individually install many software packages
  • Your computer has enough storage space

If your use case does not meet the above requirements, it's better to install Miniconda instead.

In this guide, install Anaconda on a Ubuntu 22.04 Rcs server and verify that the tool is available to use on the system.

Prerequisites

Before you begin, you need to:

This guide uses the example values, user pythonuser and the home directory /home/pythonuser/, replace all occurrences with your actual user account.

  • Have some basic Python programming skills

Install Anaconda

Download the latest Anaconda installer script

$ curl -O https://repo.anaconda.com/archive/Anaconda3-2023.07-2-Linux-x86_64.sh

The above command adds the Anaconda version 2023.07-2 file to your working directory. To download the latest version, visit the official installer scripts page. A single installer file may have a total file size of up to 1 Gigabyte.

To install Anaconda, there are two available methods, the normal installation where you interactively use the installer application, and the silent installation which requires no user input. Depending on your preferences, the silent installation is fast and does not require any prompts to install Anaconda as described in the sections below.

Option 1: Normal Installation (Slow)

  1. Run the shell script

     $ bash Anaconda3-2023.07-2-Linux-x86_64.sh

    When successful, the following prompt should display:

     In order to continue the installation process, please review the license agreement.
     Please, press ENTER to continue
  2. Press Enter to continue and view the License Agreement. To browse through the agreement pager, press the Space button. When complete, enter yes to accept the product license terms

     Do you accept the license terms? [yes|no]

    * Press Enter to view the installation summary as below:

         Anaconda3 will now be installed in this location:
         /home/pythonuser/anaconda3
    
         - Press ENTER to confirm the location
         - Press CTRL-C to abort the installation
         - Or specify a different location below

    * As displayed in the above output, Anaconda installs to your user home directory, for this guide, it installs to /home/pythonuser/. When logged in as root, the default installation directory is /root/anaconda3

    • Press Enter to install Anaconda to the default installation directory /home/pythonuser/anaconda3
    • To install Anaconda to a different directory, manually type the directory path and press Enter to use the directory
  3. When you accept all prompts, all Anaconda files download and extract to the target directory. When complete, the following message displays

     installation finished.
     Do you wish the installer to initialize Anaconda3
     by running conda init? [yes|no]
  4. To initialize Conda before using it. Type yes and press Enter

  5. When the initialization is successful, Anaconda is ready to use on your system. To activate the application, end your user SSH session

     $ exit

    * Using SSH, re-establish a connection to your server

         $ ssh pythonuser@SERVER-IP

    When logged in, verify that your terminal prompt includes the Conda (base) environment as below:

     (base) hum@my-server:~$ 

    If you'd like to disable the Conda base environment whenever you establish a connection to the server, set the activate_base value to false as below:

     $ conda config --set auto_activate_base false

Option 2: Silent Installation (Fast)

The default standard Anaconda installation method requires user input to activate the program on your server. Sometimes it's necessary to install Anaconda automatically through a script. In such cases, you don't need to interact with the installer. Run the installer in batch mode to automatically accept the license agreement and install Anaconda as described below.

  1. Run the Anaconda installation script in batch mode -b

     $ bash Anaconda3-2023.07-2-Linux-x86_64.sh -b

    When successful, your output should look like the one below:

     Executing transaction: / 
    
         Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
         More details are available here: https://intel.github.io/scikit-learn-intelex
    
         For example:
    
             $ conda install scikit-learn-intelex
             $ python -m sklearnex my_application.py
    
     done
     installation finished.

    The command installs Anaconda to the default user home directory /home/user/anaconda3. To install Anaconda to a custom directory, add the -p option to the command. For example:

     $ bash Anaconda3-2023.07-1-Linux-x86_64.sh -b -p /var/anaconda
  2. To initialize Conda for use on the server. Run the activation script

     $ source /home/pythonuser/anaconda3/bin/activate
  3. Initialize Conda

     $ conda init

Anaconda is now available on the server. End your SSH session and log back in to verify that you can view the activated Conda base environment terminal prompt.

Verify the Installation

  1. When logged in to the server, verify that your terminal prompt looks like the one below:

     (base) pythonuser@servername:~$ 
  2. View the available user paths

     $ echo $PATH

    Verify that the PATH output contains the path to the ancillary programs installed by Anaconda and the path to the Conda executable as below:

     /home/pythonuser/anaconda3/bin:/home/pythonuser/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  3. View the list of programs installed by Anaconda

     $ conda list
  4. To deactivate the Conda environment, and re-access the main Linux shell, run the following command

     $ conda deactivate

Uninstall

  1. Before you uninstall Anaconda, deactivate the base environment

     $ conda deactivate
  2. Delete the Anaconda installation directory

     $ rm -rf ~/anaconda3
  3. Delete the hidden Conda data directory

     $ rm -rf ~/.conda
  4. To delete the Conda environment variables, edit the .bashrc in your user home directory

     $ nano /home/pythonuser/.bashrc
  5. Navigate to the end of the file, and delete the following configuration lines

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

    Save and close the file.

  6. End your SSH session

     $ exit
  7. Re-establish an SSH connection to your server

     $ ssh pythonuser@SERVER-IP
  8. Verify that Anaconda uninstalls from the system, and the (base) environment prompt does not display in your terminal prompt

     pythonuser@my-server:~$ 

Conclusion

In this guide, you installed Anaconda on a Ubuntu server using two optional installation methods, normal and silent. You also verified the installation and completely removed Anaconda from the system after use. For more information about Anaconda, visit the official documentation.

Next Steps

To apply more solutions on your cloud server, visit the following resources:

Introduction Conda is an open-source tool that performs package and environment management. As a package manager, its functionality relates to any other package management tool such as the pip Python package manager. As an environment manager, it helps to create and manage different environments. Sometimes different applications have different versions of the same software. Managing the different versions is a difficult task, and environments solve this problem. Each environment can host specific software and dependencies, independent of other environments. Conda is available to install as part of either Anaconda or Miniconda. Anaconda is pre-packaged with a smaller set of Python packages. This makes it the preferred choice for servers with storage limitations. It's also the preferred option in situations that require only a small set of tools. Where Anaconda pre-installs a few hundred common packages such as PyTorch, Transformers, Numpy, and Scipy, Miniconda only installs a few dozen basic utility packages. Choose Anaconda if: A project is large or needs many different packages The project is exploratory and while starting, you don't know what tools it requires You don't want to individually install many software packages Your computer has enough storage space If your use case does not meet the above requirements, it's better to install Miniconda instead. In this guide, install Anaconda on a Ubuntu 22.04 Rcs server and verify that the tool is available to use on the system. Prerequisites Before you begin, you need to: Deploy a fresh Ubuntu server on Rcs Using SSH, access the server Create a non-root user with sudo privileges and switch to the account This guide uses the example values, user pythonuser and the home directory /home/pythonuser/, replace all occurrences with your actual user account. Have some basic Python programming skills Install Anaconda Download the latest Anaconda installer script $ curl -O https://repo.anaconda.com/archive/Anaconda3-2023.07-2-Linux-x86_64.sh The above command adds the Anaconda version 2023.07-2 file to your working directory. To download the latest version, visit the official installer scripts page. A single installer file may have a total file size of up to 1 Gigabyte. To install Anaconda, there are two available methods, the normal installation where you interactively use the installer application, and the silent installation which requires no user input. Depending on your preferences, the silent installation is fast and does not require any prompts to install Anaconda as described in the sections below. Option 1: Normal Installation (Slow) Run the shell script $ bash Anaconda3-2023.07-2-Linux-x86_64.sh When successful, the following prompt should display: In order to continue the installation process, please review the license agreement. Please, press ENTER to continue Press ENTER to continue and view the License Agreement. To browse through the agreement pager, press the SPACE button. When complete, enter yes to accept the product license terms Do you accept the license terms? [yes|no] * Press ENTER to view the installation summary as below: Anaconda3 will now be installed in this location: /home/pythonuser/anaconda3 - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below * As displayed in the above output, Anaconda installs to your user home directory, for this guide, it installs to /home/pythonuser/. When logged in as root, the default installation directory is /root/anaconda3 Press ENTER to install Anaconda to the default installation directory /home/pythonuser/anaconda3 To install Anaconda to a different directory, manually type the directory path and press ENTER to use the directory When you accept all prompts, all Anaconda files download and extract to the target directory. When complete, the following message displays installation finished. Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no] To initialize Conda before using it. Type yes and press ENTER When the initialization is successful, Anaconda is ready to use on your system. To activate the application, end your user SSH session $ exit * Using SSH, re-establish a connection to your server $ ssh pythonuser@SERVER-IP When logged in, verify that your terminal prompt includes the Conda (base) environment as below: (base) hum@my-server:~$ If you'd like to disable the Conda base environment whenever you establish a connection to the server, set the activate_base value to false as below: $ conda config --set auto_activate_base false Option 2: Silent Installation (Fast) The default standard Anaconda installation method requires user input to activate the program on your server. Sometimes it's necessary to install Anaconda automatically through a script. In such cases, you don't need to interact with the installer. Run the installer in batch mode to automatically accept the license agreement and install Anaconda as described below. Run the Anaconda installation script in batch mode -b $ bash Anaconda3-2023.07-2-Linux-x86_64.sh -b When successful, your output should look like the one below: Executing transaction: / Installed package of scikit-learn can be accelerated using scikit-learn-intelex. More details are available here: https://intel.github.io/scikit-learn-intelex For example: $ conda install scikit-learn-intelex $ python -m sklearnex my_application.py done installation finished. The command installs Anaconda to the default user home directory /home/user/anaconda3. To install Anaconda to a custom directory, add the -p option to the command. For example: $ bash Anaconda3-2023.07-1-Linux-x86_64.sh -b -p /var/anaconda To initialize Conda for use on the server. Run the activation script $ source /home/pythonuser/anaconda3/bin/activate Initialize Conda $ conda init Anaconda is now available on the server. End your SSH session and log back in to verify that you can view the activated Conda base environment terminal prompt. Verify the Installation When logged in to the server, verify that your terminal prompt looks like the one below: (base) pythonuser@servername:~$ View the available user paths $ echo $PATH Verify that the PATH output contains the path to the ancillary programs installed by Anaconda and the path to the Conda executable as below: /home/pythonuser/anaconda3/bin:/home/pythonuser/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin View the list of programs installed by Anaconda $ conda list To deactivate the Conda environment, and re-access the main Linux shell, run the following command $ conda deactivate Uninstall Before you uninstall Anaconda, deactivate the base environment $ conda deactivate Delete the Anaconda installation directory $ rm -rf ~/anaconda3 Delete the hidden Conda data directory $ rm -rf ~/.conda To delete the Conda environment variables, edit the .bashrc in your user home directory $ nano /home/pythonuser/.bashrc Navigate to the end of the file, and delete the following configuration lines # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/home/pythonuser/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/home/pythonuser/anaconda3/etc/profile.d/conda.sh" ]; then . "/home/pythonuser/anaconda3/etc/profile.d/conda.sh" else export PATH="/home/pythonuser/anaconda3/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<< Save and close the file. End your SSH session $ exit Re-establish an SSH connection to your server $ ssh pythonuser@SERVER-IP Verify that Anaconda uninstalls from the system, and the (base) environment prompt does not display in your terminal prompt pythonuser@my-server:~$ Conclusion In this guide, you installed Anaconda on a Ubuntu server using two optional installation methods, normal and silent. You also verified the installation and completely removed Anaconda from the system after use. For more information about Anaconda, visit the official documentation. Next Steps To apply more solutions on your cloud server, visit the following resources: How to Perform Facial Recognition in Python with a Rcs Cloud GPU Asynchronous Task Queueing in Python using Celery Authenticate a Python Application with Rcs Managed Databases for PostgreSQL and Redis

Was this answer helpful?
Back

Powered by WHMCompleteSolution