How to Manage Conda Environments on Ubuntu: A Step-by-Step Guide

September 2nd, 2024
How to Manage Conda Environments on Ubuntu: A Step-by-Step Guide

Managing software dependencies and environments can be challenging. Conda offers a user-friendly solution for installing, updating, and managing software packages and environments. In this tutorial, we will explore what Conda is and how to manage Conda environments on Ubuntu.

What is Conda

Developed by Anaconda, Conda is particularly popular in the Python community. However, it also supports packages from other programming languages. An essential feature of Conda is its ability to create isolated environments. It allows users to work on multiple projects with different dependencies without any conflicts. Conda is versatile and can be used on Windows, macOS and Linux operating systems. Additionally, it can be configured to work with a Python proxy server, allowing developers to manage packages in restricted network environments or to route their package installations through a proxy.

Conda is mostly used by developers who work with projects using different versions of Python and other programming languages. It is a convenient tool for those involved in data analysis, software development or machine learning.

Prerequisites

  • The latest Ubuntu OS version installed with sudo privileges

Deploy and scale your Python projects effortlessly on Cherry Servers' robust and cost-effective dedicated or virtual servers. Benefit from an open cloud ecosystem with seamless API & integrations and a Python library.

How to manage Conda environments

We will first install the prerequisite packages and then proceed to download and install Anaconda. We will then create and delete a conda environment.

Install Anaconda prerequisites

We install Anaconda prerequisites using the following commands:

apt update
apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6

Download and install Anaconda for Linux

Once the prerequisites are installed, we can download the latest version of Anaconda:

curl -O https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh

You can find all Anaconda versions here, and choose a specific version.

Install Anaconda

We can now proceed with the installation of Anaconda:

bash Anaconda3-2024.02-1-Linux-x86_64.sh

Change the name of the script to match the version you have downloaded.

Let us check if conda has been installed:

$ conda --version
conda 24.1.2

You may need to reload your terminal after the installation to get the conda command.

Create a conda environment

To create a conda environment, use the following command:

conda create --name cherryservers

You should get a similar output asking to confirm the environment creation:

$ conda create --name cherryservers
Channels:
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/didier/anaconda3/envs/cherryservers



Proceed ([y]/n)?

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate cherryservers
#
# To deactivate an active environment, use
#
#     $ conda deactivate

We now activate the environment by entering the following command:

conda activate cherryservers

The environment name will be indicated at the beginning of your prompt, as in the example below:

(cherryservers) didier@lab:~$

You can now install any package you need in the new environment.

You can exit (deactivate) the environment using the following command:

conda deactivate

Also read: How to reverse a list in Python

Delete a conda environment

You can delete a conda environment using the following command:

conda remove --name ENV_NAME --all

In our case, it will be:

conda remove --name cherryservers --all

You will get a similar output:

conda remove --name cherryservers --all

Remove all packages in environment /home/didier/anaconda3/envs/cherryservers:

No packages found in /home/didier/anaconda3/envs/cherryservers. Continuing environment removal
Everything found within the environment (/home/didier/anaconda3/envs/cherryservers), including any conda environment configurations and any non-conda files, will be deleted. Do you wish to continue?
 (y/[n])? y

Enter y in the prompt to confirm the removal of all packages in the environment.

Also read: How to reverse a list in Python

Conclusion

In this tutorial, we have learned what conda is and its importance when working on complex projects requiring multiple programming languages and versions. We have also covered how to install Anaconda, how to delete and create conda environments. Conda's capacity to streamline package management, create isolated environments, and handle dependencies makes it an excellent choice for machine learning, software development, and other fields as it simplifies workflow and project management, enhancing productivity and efficiency. You can learn more about conda in the official Anaconda documentation.

With over 20 years in IT, Didier has been creating technical documentation for companies, catering to both technical and non-technical audiences. Didier is an expert in Linux system administration, DevOps, cloud computing, cybersecurity, IT consulting, management consulting, technical writing, Diataxis framework, Doc-as-Code, UX Writing, Jamstack, MkDocs, Docker, containers, open-source, SDLC, and Python programming. His hands-on technical expertise, coupled with his strong communication skills, enables him to bridge the gap between developers and end-users. Didier creates user guides, API References, end-user documentation, how-tos, and tutorials. He is an expert in authoring using modern technologies such as Markdown, Mermaid, and static-site generators. Didier also utilizes frameworks and methodologies such as Diaxiatis and Doc-as-code, applying structured writing techniques. Currently, Didier works as a freelance technical writer and documentation consultant, assisting organizations in creating comprehensive and easy-to-understand documentation for their software and web applications. In his previous roles, Didier worked as a system and applications engineer and implemented style guides, tone and voice best practices, and documentation processes that streamline their release cycles. Didier resides in Vacoas, Mauritius.

Start Building Now

Deploy your new Cloud VPS server in 3 minutes starting from $5.83 / month.

We use cookies to ensure seamless user experience for our website. Required cookies - technical, functional and analytical - are set automatically. Please accept the use of targeted cookies to ensure the best marketing experience for your user journey. You may revoke your consent at any time through our Cookie Policy.
build: 974cfe9f.722