Setting up Conda

conda
setup
tutorial
Author

Matt Triano

Published

July 22, 2022

Modified

July 22, 2022

Conda

conda is a language-agnostic package manager and environment management system. conda’s environment management functionality makes it possible for a user to easily switch between environments (where an environment consists of the hardware and software used to execute code) and makes it possible to export a specification of that environment that can be used to reproduce that environment on another system.

In this post, I’ll show my opinionated conda installation and configuration process.

Conda Installation

conda is primarily installable via two distributions; the Anaconda distribution, which includes the conda executable along with over 700 additional conda packages from the Anaconda repository, and the Miniconda distribution, which consists of the conda executable with the minimal number of packages needed for conda to run. Install a miniconda distribution.

Step 1. Download a miniconda installer

Download a miniconda installer, copy the corresponding SHA256 hash, calculate the SHA256 hash of the downloaded file, and compare that value to the one copied from the download link page. If the values match exactly, proceed in installation. * For the miniconda version downloaded below, the SHA256 sum should be aef279d6baea7f67940f16aad17ebe5f6aac97487c7c03466ff01f4819e5a651

!curl -o Miniconda3-py310_23.3.1-0-Linux-x86_64.sh https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Linux-x86_64.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 69.7M  100 69.7M    0     0  75.9M      0 --:--:-- --:--:-- --:--:-- 75.8M
!sha256sum Miniconda3-py310_23.3.1-0-Linux-x86_64.sh
aef279d6baea7f67940f16aad17ebe5f6aac97487c7c03466ff01f4819e5a651  Miniconda3-py310_23.3.1-0-Linux-x86_64.sh

If the calculated hash matches the hash published on the miniconda installer link page, proceed.

Step 2. Execute the installer

Run the installer via

bash Miniconda3-py310_23.3.1-0-Linux-x86_64.sh (or whatever your version is)

and respond to prompts as appropriate (go with defaults). After running conda init, run the command source ~/.bashrc to add the path to conda to your $PATH (or you can just open a new terminal window, ~/.bashrc runs whenever you open a terminal).

Step 3. Install the libmamba solver and set it as the default

The libmamba dependency solver is far faster than the regular conda solver, and in my experience, it has succeeded at nearly instantly resolving envs that the regular conda solver failed to resolve in hours. It’s great.

Install it via

conda install -n base conda-libmamba-solver

and set it as the default solver via

conda config --set solver libmamba

Step 4. Configure conda-forge as the priority channel

Conda-forge is the most complete channel and doesn’t allow package versions to be removed (so an env made purely of packages from the conda-forge channel will be reproducible).

Run these commands to 1) prioritize the conda-forge channel and 2) force conda to only download packages from the highest priority channel.

conda config --add channels conda-forge
conda config --set channel_priority strict

Conclusion

This process should take no more than 5 minutes and it will give you a conda setup that avoids the common complaints (e.g., slow, unreproducible).

To learn more about how conda installs packages, read this.