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
pythonuserand 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.shThe 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.shWhen successful, the following prompt should display:
In order to continue the installation process, please review the license agreement. Please, press ENTER to continuePress Enter to continue and view the License Agreement. To browse through the agreement pager, press the Space button. When complete, enter
yesto accept the product license termsDo 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 asroot, 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
- Press Enter to install Anaconda to the default installation 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
yesand press EnterWhen 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-IPWhen 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_basevalue tofalseas 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 -bWhen 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-poption to the command. For example:$ bash Anaconda3-2023.07-1-Linux-x86_64.sh -b -p /var/anacondaTo initialize Conda for use on the server. Run the activation script
$ source /home/pythonuser/anaconda3/bin/activateInitialize 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 $PATHVerify that the
PATHoutput 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/binView the list of programs installed by Anaconda
$ conda listTo 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 deactivateDelete the Anaconda installation directory
$ rm -rf ~/anaconda3Delete the hidden Conda data directory
$ rm -rf ~/.condaTo delete the Conda environment variables, edit the
.bashrcin your user home directory$ nano /home/pythonuser/.bashrcNavigate 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
$ exitRe-establish an SSH connection to your server
$ ssh pythonuser@SERVER-IPVerify that Anaconda uninstalls from the system, and the
(base)environment prompt does not display in your terminal promptpythonuser@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: