(Mini) Conda on Linux
Conda is an open-source package manager and environment management system that runs on Windows, macOS, and Linux. Miniconda is a minimal version of Conda that includes only Conda and its dependencies. This tool allows you to create isolated environments to manage different versions of packages and software dependencies without conflicts.
Installing Conda on Linux
To install Conda on Linux, follow these steps:
- Download the Miniconda installer from the official website:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh - Run the installer:
bash Miniconda3-latest-Linux-x86_64.sh - Follow the on-screen instructions and accept the license agreement. After the installation is complete, close and reopen the terminal or run:
source ~/.bashrc
Managing Environments
Conda environments allow you to create and manage different development environments. Here are some essential commands:
- Create a new environment:
conda create --name my_environment - Activate an environment:
conda activate my_environment - Deactivate an environment:
conda deactivate - List all environments:
conda env list - Remove an environment:
conda remove --name my_environment --all
Managing Packages
Conda contains a package manager that simplifies package installation and management. **N.B.** Conda is compatible with pip, so you can use both package managers depending on your needs.
pip is out of the scope of this guide. If you want to know more about it, check the official documentation.
The following are some common Conda package management commands:
- Install a package:
conda install package_name - Update a package:
conda update package_name - Remove a package:
conda remove package_name - List installed packages:
conda list - Search for a package:
conda search package_name
Complete Example: Creating and Managing an Environment with pip
Below is an example of how to create a Conda environment, activate it, and install packages using pip:
- Create a new environment called
example_environmentwith Python 3.10:conda create --name example_environment python=3.10 - Activate the newly created environment:
conda activate example_environmentThe terminal prompt should change to:
(example_environment) user@hostname:~$ - Install packages using pip (e.g., numpy and pandas):
pip install numpy pandas - Verify that the packages were installed correctly:
python -c "import numpy; import pandas; print('Numpy and Pandas installed correctly')" - Deactivate the environment when you are done working:
conda deactivate
Useful Commands
Here are some useful Conda commands for various operations:
- Show information about the active environment:
conda info - Save the list of packages to a file:
conda list --export > package_list.txt - Create an environment from a file:
conda create --name my_environment --file package_list.txt