How To Install Anaconda on Debian 11

In this article, we want to teach you How To Install Anaconda on Debian 11.

Anaconda is a free and open-source distribution of the programming languages Python and R programming. This distro comes from the Python interpreter and various packages related to machine learning and data science.

The idea behind Anaconda is to make it easy for people interested in those fields to install all (or most) of the packages needed with a single installation.

How To Install Anaconda on Debian 11

Before you start to install Anaconda on Debian 11. you need to log in to your server as a non-root user with sudo privileges. To do this, you check our article about the Initial server setup with Debian 11.

When you are done with this, you can start to install Anaconda on Debian 11.

Install Anaconda on Debian 11

To install Anaconda on a Debian 11 server, you should download the latest Anaconda installer bash script, verify it, and then run it.

Go to the Anaconda Distribution Page. Search for the latest version of Anaconda for Python 3. and copy the link address of it.

It’s recommended to change your directory to the /tmp with the following command:

cd /tmp

Then, install the curl tool that you can download the Anaconda bash script:

sudo apt install curl

Now, use curl to download the link that you have copied from the Anaconda website:

curl https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh

After you download the Anaconda installer, you can run the script with the following command:

bash Anaconda3-2021.05-Linux-x86_64.sh

In your output you will see:

Output
Welcome to Anaconda3 2021.05

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

Press enter to continue and press enter to read through the license. then, press yes to approve the license terms.

At this point, you will be asked to choose the location of the installation. you can press Enter to accept the default or specify a different location to modify it.

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] >>>

When your installation is completed, you will see:

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

Type yes that you don’t want to add Anaconda to the PATH manually.

Here you need to activate the installation by sourcing the ~/.bashrc file:

source ~/anaconda3/bin/activate

You will be in Anaconda’s base programming environment which is named base.

Your prompt will change similar to this:

(base) root@deb:~#

Now you can run the conda init command to initialize your environment:

(base) root@deb:~# conda init

Then, you can verify your installation with the following command:

(base) root@deb:~# conda list
# packages in environment at /root/anaconda3:
#
# Name                  Version  Build        Channel
_ipyw_jlab_nb_ext_conf  0.1.0    py38_0
_libgcc_mutex           0.1      main
alabaster               0.7.12   pyhd3eb1b0_0
anaconda                2021.05  py38_0
...

As you can see in your output you will receive all the available packages through the Anaconda installation.

When you have finished installing Anaconda on Debian 11, you can set up Anaconda environments.

Set up Anaconda Environments on Debian 11

Anaconda environments allow you to keep projects organized by Python versions and the packages needed.

First, you need to check which versions of Python are available for you to use with the following command:

(base) root@deb:~# conda search "^python$"

In your output, you will see the different versions of Python. In this article, because you use the Anaconda with Python 3, you will have access only to the Python 3 versions of packages.

Here you can create an Anaconda environment using Python 3 on Debian 11. Here we name the environment “my_env”, you can replace it with your own name.

To do this run the following command:

(base) root@deb:~# conda create --name my_env python=3

Type Y to complete the creation of your environment.

You need to activate your new environment with the following command:

(base) root@deb:~# conda activate my_env

After this, your command prompt will look like this:

(my_env) root@deb:~#

Verify which versions of Python you use with the following command:

(my_env) root@deb:~# python --version
Output
Python 3.10.0

Deactivate your Anaconda environment on Debian 11 with the following command:

(my_env) root@deb: conda deactivate

Also, you can create an Anaconda environment with a specific version of Python. for example we use Python 3.7:

(base) root@deb:~# conda create -n my_env37 python=3.7

Then, activate it with the following command:

(base) root@deb:~# conda activate my_env37

Your command prompt will look like this:

(my_env37) root@deb:~#

Now update your version of Python along the same branch within a respective environment with the following command:

(my_env37) root@deb:~# conda update python

Deactivate your Anaconda environment on Debian 11 with the following command:

(my_env37) root@deb:~# conda deactivate

Here you can list all of the environments that you have set up with the following command:

(base) root@deb:~# conda info --envs
Output
# conda environments:
#
base /root/anaconda3
my_env /root/anaconda3/envs/my_env
my_env37 * /root/anaconda3/envs/my_env37

Every environment you create with conda create will come with several default packages like openssl, Python, wheel, etc.

You can add additional packages like NumPy with the following command:

(base) root@deb:~# conda install --name my_env37 numpy

If you would like a numpy environment upon creation, you can target it in your conda create command:

(base) root@deb:~# conda create --name my_env python=3 numpy

If you are not working on a specific project, you can remove the environment with the following command:

(base) root@deb:~# conda remove --name my_env37 --all

List the available environments with the following command:

(base) root@deb:~# conda info --envs

In your output, you will see that the my_env37 environment does not exist:

Output
# conda environments:
#
base * /root/anaconda3
my_env /root/anaconda3/envs/my_env

Let’s see how to update the Anaconda on Debian 11.

How To Update the Anaconda

At this point, you need to be sure that Anaconda is up to date and working with all the latest package releases.

First, you should update the conda utility with the following command:

(base) root@deb:~# conda update conda

Then, you can update the Anaconda distribution with the following command:

(base) root@deb:~# conda update anaconda

With this command, you will be sure that you are using the latest releases of conda and Anaconda.

Here you can uninstall Anaconda on Debian 11. Let’s see how it works.

How To Uninstall Anaconda

If you don’t want to use Anaconda, you can uninstall it by following these steps.

First, you need to deactivate the base Anaconda environment with the following command:

(base) root@deb:~# conda deactivate

Next, you need to install an Anaconda module on Debian 11 that removes the configuration files. To install it run the following command:

conda install anaconda-clean

You can now remove your entire Anaconda directory on Debian 11 by entering the following command:

rm -rf ~/anaconda3

Finally, you need to remove the PATH line from your .bashrc file. To do this, open the file with your favorite text editor, here we use vi:

vi ~/.bashrc

Then, search for the conda initialize part and comment on all of the lines with # in this section like this:

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

When you are finished, save and close the file.

Anaconda is now removed from your Debian 11 server.

Conclusion

At this point, you learn to install Anaconda on Debian 11. Also, you can use conda, a package, and an environment manager to create environments for isolating our projects that use different versions of Python and/or different versions of packages. and you can also use it to install, uninstall, and update packages in your project environments.

Hope you enjoy this article about How To Install Anaconda on Debian 11.

May this article on the orcacore website about How to install Anaconda on Ubuntu 18.04 be useful for you.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!