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 set up 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:

Linux, macOS or Git Bash on Windows

Execute the following in a terminal or download the micromamba binary manually from Github releases.

bash -c "$(curl https://micromamba.pfx.dev/install.sh)"

You can also use zsh (preferred on macOS):

zsh -c "$(curl https://micromamba.pfx.dev/install.sh)"

The single binary that is installed is extracted from the conda-forge builds of micromamba. You can find the exact installation script that is used also on Github.

The script installs the micromamba executable to ~/.local/bin/micromamba

During the installation, you will be asked if you want to "initialize" your shell for micromamba. This adds some hooks into your .bashrc file (Windows & macOS: ~/.bash_profile), on zsh the ~/.zshrc file. Micromamba will tell you exactly what hooks are added, and they can be removed by running micromamba shell deinit later on. Without initializing the shell, micromamba activate does not properly function. However, you can still use micromamba run -n myenv <my command> to run commands from myenv.

Windows Powershell

On Windows, you can execute the following script from Powershell to install micromamba.

Invoke-Expression ((Invoke-WebRequest -Uri https://micromamba.pfx.dev/install.ps1).Content)

The script downloads micromamba.exe and places it in $Env:LocalAppData\micromamba\micromamba.exe. This path is also added to the PATH environment variable.

The script also asks to initialize your Powershell for usage with micromamba activate. If you initialize the shell, a code snippet is added to your ~/Documents/WindowsPowerShell/profile.ps1 file.

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 are 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.