IntroductionGetting started with mamba

mamba and micromamba are general software package managers for any kind of software and all operating systems (currently supported are Windows, macOS and many Linux distributions). A software package manager lets developers install the libraries and applications they need to work efficiently. Mamba is a great choice because it's mature, fast and robust.

With mamba it's easy to setup software environments. A software environment is simply a set of different libraries, applications and their dependencies. The power of environments is that they can co-exist: you can easily have an environment called py27 for Python 2.7 and one called py310 for Python 3.10, so that multiple of your projects with different requirements have their dedicated environments. This is similar to "containers" and images. However, mamba makes it easy to add, update or remove software from the environments.

Installation

Historically we have been working on mamba, and later started micromamba. If you are starting fresh, we recommend micromamba these days. The installation of micromamba is straight forward:

  • curl micro.mamba.pm/install.sh | bash (on Linux, OS X or Git Bash on Windows)

The install script also automatically asks to run "shell initialization". The shell initialization process adds a snippet to your shell configuration file (e.g. the ~/.bashrc file for bash) that adds some specific functions to your shell that make working with mamba simpler.

Usage

The first step when using micromamba is to create an environment. In order to create an environment, one needs to also specify a "channel". Channels are the software repositories from which the packages are downloaded. We recommend the conda-forge channel and are going to use it in this example.

The following line will create a new environment with the name myenv, using the conda-forge channel to get the packages, and install jupyterlab.

micromamba create --name myenv --channel conda-forge jupyterlab

# the equivalent short form is
micromamba create -n myenv -c conda-forge jupyterlab

The environment creation will do four things:

  • first, it downloads the channel index that contains all packages
  • then it solves for jupyterlab and selects specific versions of all the required dependencies (such as Python, jupyter-server, and ipykernel)
  • it then asks the user for confirmation and starts downloading & extracting the packages to the package cache
  • once the download and extraction is finished, mamba "links" the packages into the target environment. The environment is a specific folder on your disk that contains the files of all packages

To use the environment, one can run

micromamba activate myenv

After the activation is executed, one can see a $ (myenv) ... in the shell which indicates the current activated environment. The activation makes all software available from the command line. Since we installed jupyterlab, we can now execute jupyterlab on the shell which would start the jupyterlab server.

Another way to use the installed software is via micromamba run. The following code also executes the jupyterlab version that was installed in the myenv environment.

micromamba run -n myenv jupyterlab

Modifying the environment

The active environment can also be modified using micromamba install xeus-sqlite to install the xeus-sqlite jupyter kernel or micromamba update jupyterlab to update to a newer version of jupyterlab if one is available.