DEV Community

Cover image for Installing Anaconda on Debian 12
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya Originally published at docs.vultr.com

Installing Anaconda on Debian 12

Anaconda is an open-source distribution of Python and R built for data science, machine learning, and scientific computing. It bundles Conda, a package and environment manager, along with a large set of scientific libraries for processing large-scale data and running advanced computations, making it a solid platform for building machine learning models and running complex workloads on a server. This guide walks through installing Anaconda on Debian 12, setting it up for multiple users, managing Conda environments, and running Jupyter Notebook inside one. By the end, you'll have a working Anaconda installation with isolated Conda environments ready for your data science projects.


Install Anaconda on Debian 12

Anaconda isn't available in Debian 12's default package repositories, so you'll download the installer script directly.

1. Install the required dependency packages for Anaconda:

$ sudo apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 -y
Enter fullscreen mode Exit fullscreen mode

2. Download the latest Anaconda installer script: Visit the Anaconda repository and find the latest Linux installer, for example Anaconda3-2024.10-1-Linux-x86_64.sh.

$ wget -O anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh
Enter fullscreen mode Exit fullscreen mode

3. Test the integrity of the downloaded installer script:

$ shasum -a 256 anaconda.sh
Enter fullscreen mode Exit fullscreen mode

Verify that the generated hash matches the installer's SHA256 value listed in the Anaconda repository, similar to:

3ba0a298155c32fbfd80cbc238298560bf69a2df511783054adfc151b76d80d8
Enter fullscreen mode Exit fullscreen mode

4. Run the script with Bash to install Anaconda:

$ bash anaconda.sh
Enter fullscreen mode Exit fullscreen mode
  • Press Enter when prompted to start the installation and review the license agreement:

    Welcome to Anaconda3 2024.10-1
    In order to continue the installation process, please review the license
    agreement.
    Please, press ENTER to continue
    >>>
    
  • Press Space to page through the terms of service, then press q to close the pager.

  • Enter yes when prompted to accept the license terms, then press Enter to install Anaconda to the default location in your home directory:

    Do you accept the license terms? [yes|no]
    >>> yes
    
    Anaconda3 will now be installed into this location:
    /home/linuxuser/anaconda3
    - Press ENTER to confirm the location
    - Press CTRL-C to abort the installation
    - Or specify a different location below
    
    [/home/linuxuser/anaconda3] >>>
    
  • Enter yes and press Enter when prompted to update your shell profile and initialize Conda on every session:

    Do you wish to update your shell profile to automatically initialize conda?
    This will activate conda on startup and change the command prompt when activated.
    If you'd prefer that conda's base environment not be activated on startup,
    run the following command when conda is activated:
    
    conda config --set auto_activate_base false
    
    You can undo this by running `conda init --reverse $SHELL`? [yes|no]
    [no] >>> yes
    

    Your output should look similar to the following once the installation completes:

    .....................
    modified      /home/linuxuser/.bashrc
    
    ==> For changes to take effect, close and re-open your current shell. <==
    
    Thank you for installing Anaconda3!
    

5. Reload your shell configuration to apply the changes:

$ source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Verify that your shell prompt changes to the default base Conda environment:

(base) linuxuser@debian~$
Enter fullscreen mode Exit fullscreen mode

6. View the installed Conda version:

$ conda --version
Enter fullscreen mode Exit fullscreen mode

Output:

conda 24.9.2
Enter fullscreen mode Exit fullscreen mode

7. View information about the active Conda environment, Python version, and channels:

$ conda info
Enter fullscreen mode Exit fullscreen mode

Your output should be similar to the one below:

active environment : base
active env location : /home/linuxuser/anaconda3
        shell level : 1
   user config file : /home/linuxuser/.condarc
populated config files : /home/linuxuser/anaconda3/.condarc
      conda version : 24.9.2
conda-build version : 24.9.0
     python version : 3.12.7.final.0
   base environment : /home/linuxuser/anaconda3  (writable)
  conda av data dir : /home/linuxuser/anaconda3/etc/conda
       channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                      https://repo.anaconda.com/pkgs/main/noarch
                      https://repo.anaconda.com/pkgs/r/linux-64
                      https://repo.anaconda.com/pkgs/r/noarch
      package cache : /home/linuxuser/anaconda3/pkgs
                      /home/linuxuser/.conda/pkgs
   envs directories : /home/linuxuser/anaconda3/envs
                      /home/linuxuser/.conda/envs
           platform : linux-64
Enter fullscreen mode Exit fullscreen mode

Install Anaconda for Multiple Users

Anaconda is installed in your active user's home directory with a default base environment. To let multiple users use Anaconda and manage Conda environments, create a dedicated anaconda group and grant it ownership of the Anaconda installation directory.

1. Switch to your home directory:

$ cd
Enter fullscreen mode Exit fullscreen mode

2. Create a new anaconda group:

$ sudo groupadd anaconda
Enter fullscreen mode Exit fullscreen mode

3. Grant the anaconda group ownership privileges to the Anaconda installation directory:

$ sudo chgrp -R anaconda /home/linuxuser/anaconda3/
Enter fullscreen mode Exit fullscreen mode

4. Grant the owner and the anaconda group full privileges to the Anaconda installation directory:

$ sudo chmod 770 -R /home/linuxuser/anaconda3/
Enter fullscreen mode Exit fullscreen mode

5. Add your active user to the anaconda group (replace linuxuser with your actual user):

$ sudo usermod -a -G anaconda linuxuser
Enter fullscreen mode Exit fullscreen mode

6. Create a new user, for example exampleuser:

$ sudo adduser exampleuser
Enter fullscreen mode Exit fullscreen mode

7. Add the new user to the anaconda group:

$ sudo usermod -a -G anaconda exampleuser
Enter fullscreen mode Exit fullscreen mode

8. Switch to the new user, and enter the user's password when prompted to log in:

$ su - exampleuser
Enter fullscreen mode Exit fullscreen mode

9. Activate the base Conda environment in the user's session:

$ source /home/linuxuser/anaconda3/bin/activate
Enter fullscreen mode Exit fullscreen mode

10. Initialize Conda in the user's environment:

$ conda init
Enter fullscreen mode Exit fullscreen mode

Your output should be similar to the one below:

no change     /home/linuxuser/anaconda3/shell/condabin/Conda.psm1
no change     /home/linuxuser/anaconda3/shell/condabin/conda-hook.ps1
no change     /home/linuxuser/anaconda3/lib/python3.12/site-packages/xontrib/conda.xsh
no change     /home/linuxuser/anaconda3/etc/profile.d/conda.csh
modified      /home/exampleuser/.bashrc
Enter fullscreen mode Exit fullscreen mode

11. Reload the user's shell configuration to apply the changes:

$ source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Verify that your shell prompt changes to the default base Conda environment:

(base) exampleuser@debian~$
Enter fullscreen mode Exit fullscreen mode

12. View the installed Conda version to ensure the user can manage Conda environments:

$ conda --version
Enter fullscreen mode Exit fullscreen mode

Output:

conda 24.9.2
Enter fullscreen mode Exit fullscreen mode

13. Press Ctrl+D to switch back to your previous user's session.


Manage Conda Environments

Conda environments isolate specific resources including packages, versions, and dependencies for projects on your server. A single Conda environment is active at a time, and activating another environment automatically deactivates the active one.

1. Create a new myenv Conda environment:

$ conda create -n myenv 
Enter fullscreen mode Exit fullscreen mode

Enter y and press Enter when prompted to create the myenv environment:

Proceed ([y]/n)? y
Enter fullscreen mode Exit fullscreen mode

Output:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate myenv
#
# To deactivate an active environment, use
#
#     $ conda deactivate
Enter fullscreen mode Exit fullscreen mode

2. Activate the myenv environment:

$ conda activate myenv
Enter fullscreen mode Exit fullscreen mode

3. Verify that your shell prompt changes from base to the myenv environment:

(myenv) $
Enter fullscreen mode Exit fullscreen mode

4. Install new packages such as numpy and pandas in the myenv environment:

$ conda install numpy pandas=2.0 scipy
Enter fullscreen mode Exit fullscreen mode

5. Update packages in the Conda environment. For example, update the pandas package to the latest version:

$ conda update pandas
Enter fullscreen mode Exit fullscreen mode

6. Remove a Conda package from the active environment. For example, remove the scipy package:

$ conda remove scipy
Enter fullscreen mode Exit fullscreen mode

Enter y and press Enter when prompted to remove the scipy package:

Proceed ([y]/n)? y
Enter fullscreen mode Exit fullscreen mode

7. Remove all unused packages including cached tarballs, index cache, logfiles, and temporary files:

$ conda clean --all
Enter fullscreen mode Exit fullscreen mode

Enter y and press Enter to confirm and remove the packages when prompted:

Will remove 525 (1.09 GB) tarball(s).
Proceed ([y]/n)? y

Will remove 1 index cache(s).
Proceed ([y]/n)? y

Will remove 16 (165.9 MB) package(s).
Proceed ([y]/n)? y

There are no tempfile(s) to remove.
There are no logfile(s) to remove.
Enter fullscreen mode Exit fullscreen mode

If you receive a file permissions error, ensure that your active user has full privileges to the pkgs subdirectory in the Anaconda installation directory.

8. Export the active Conda environment to a file such as environment.yml:

$ conda env export > environment.yml
Enter fullscreen mode Exit fullscreen mode

9. Create a new Conda environment such as myenv-2 using the exported environment file:

$ conda env create -f environment.yml -n myenv-2
Enter fullscreen mode Exit fullscreen mode

10. List all available Conda environments:

$ conda env list
Enter fullscreen mode Exit fullscreen mode

Your output should be similar to the one below. The active environment is marked with an asterisk (*):

base                     /home/linuxuser/anaconda3
myenv                 *  /home/linuxuser/anaconda3/envs/myenv
myenv-2                  /home/linuxuser/anaconda3/envs/myenv-2
Enter fullscreen mode Exit fullscreen mode

Run Applications in a Conda Environment

Jupyter Notebook is an open-source application for interactive computing that uses computational notebooks and supports multiple programming languages. Follow the steps below to install and run Jupyter Notebook as a sample application in the active myenv environment.

1. Install the latest jupyter package:

$ conda install jupyter
Enter fullscreen mode Exit fullscreen mode

2. List all installed packages in your environment and verify that the jupyter package is available:

$ conda list -n myenv
Enter fullscreen mode Exit fullscreen mode

Output:

jupyter                   1.0.0           py312h06a4308_9
jupyter-lsp               2.2.0           py312h06a4308_0
jupyter_client            8.6.0           py312h06a4308_0
jupyter_console           6.6.3           py312h06a4308_1
jupyter_core              5.7.2           py312h06a4308_0
jupyter_events            0.10.0          py312h06a4308_0
jupyter_server            2.14.1          py312h06a4308_0
Enter fullscreen mode Exit fullscreen mode

3. Create a sample hello.ipynb Jupyter notebook that outputs a greeting message:

$ echo '{
 "cells":[
  {
     "cell_type":"code",
     "execution_count":2,
     "id":"5acd64e3-b2bc-41b0-8fc1-1666cb479f30",
     "metadata":{

     },
     "outputs":[
        {
           "name":"stdout",
           "output_type":"stream",
           "text":[
           ]
        }
     ],
     "source":[
        "msg=\"Hello from Jupyter!\"\n",
        "print(msg)"
     ]
  },
  {
     "cell_type":"raw",
     "id":"7ed9e62d-6bc3-4116-b0e9-1b06814cc5f2",
     "metadata":{

     },
     "source":[

     ]
  }
 ],
 "metadata":{
  "kernelspec":{
     "display_name":"Python 3 (system-wide)",
     "language":"python",
     "name":"python3"
  },
  "language_info":{
     "codemirror_mode":{
        "name":"ipython",
        "version":3
     },
     "file_extension":".py",
     "mimetype":"text/x-python",
     "name":"python",
     "nbconvert_exporter":"python",
     "pygments_lexer":"ipython3",
     "version":"3.10.12"
  }
 },
 "nbformat":4,
 "nbformat_minor":5
}' > hello.ipynb
Enter fullscreen mode Exit fullscreen mode

4. Run the hello.ipynb notebook and write the output to a new hello.nbconvert.ipynb file:

$ jupyter nbconvert --to notebook --execute hello.ipynb
Enter fullscreen mode Exit fullscreen mode

Output:

[NbConvertApp] Converting notebook hello.ipynb to notebook
[NbConvertApp] Writing 1175 bytes to hello.nbconvert.ipynb
Enter fullscreen mode Exit fullscreen mode

5. Print the hello.nbconvert.ipynb file and verify that the greeting message displays in the outputs cell:

$ cat hello.nbconvert.ipynb
Enter fullscreen mode Exit fullscreen mode

Output:

{
 "cells":[
  {
     ...
     "outputs":[
        {
           "name":"stdout",
           "output_type":"stream",
           "text":[
              "Hello from Jupyter!\n"
           ]
        }
     ],
     "source":[
        "msg=\"Hello from Jupyter!\"\n",
        "print(msg)"
     ]
  }
  ...
}  
Enter fullscreen mode Exit fullscreen mode

6. Deactivate the myenv environment to switch back to the default base environment:

(myenv) $ conda deactivate
Enter fullscreen mode Exit fullscreen mode

Output:

(base) $
Enter fullscreen mode Exit fullscreen mode

Next Steps

  • Create separate Conda environments per project to keep dependencies isolated.
  • Explore conda-forge as an additional package channel for less common libraries.
  • Set up JupyterLab or a remote Jupyter kernel for interactive development on your server.
  • Automate environment creation with an environment.yml file across your project repos.

For the full guide with additional tips, visit the original article on Vultr Docs.

Top comments (0)