Skip to content

conda & mamba

Most command line bioinformatics tools, such as samtools, bcftools, STAR, and salmon, install from the bioconda channel. Each project gets its own environment, so two tools that need different versions of a library do not break each other.

Task Command
Create an environment mamba create -n NAME python=3.12 PKG1 PKG2
Activate conda activate NAME
Deactivate conda deactivate
List environments conda env list
List packages mamba list
Install a package mamba install PKG
Update a package mamba update PKG
Remove a package mamba remove PKG
Search the channels mamba search PKG
Delete an environment mamba env remove -n NAME
Export what you asked for conda env export --from-history > environment.yml
Export an exact lock conda list --explicit --md5 > lock.txt
Rebuild from a file mamba env create -f environment.yml
Run one command in an environment conda run -n NAME CMD
Show the channels conda config --show channels
Clear the package cache mamba clean --all
Name What it is
conda The original package manager for Python, R, C libraries, and command line tools. Since conda 23.10 it uses the libmamba solver by default.
mamba A C++ reimplementation with the same subcommands and parallel downloads
micromamba A single static binary with no Python of its own, for containers and CI
conda-forge The community channel that most packages, and all of bioconda, build on
bioconda The channel for bioinformatics software
Miniforge The installer for conda and mamba, set up with conda-forge as the only channel
Terminal window
base=https://github.com/conda-forge/miniforge/releases/latest/download
installer="Miniforge3-$(uname)-$(uname -m).sh"
curl -L -O "${base}/${installer}"
bash "${installer}"

The installer asks whether to run conda init, which adds the activation hook to your shell startup file. Open a new shell afterwards.

Terminal window
conda config --add channels bioconda
conda config --add channels conda-forge
conda config --set channel_priority strict
conda config --show channels

--add puts a channel at the top of the list, so after these lines conda-forge comes first and bioconda second. That is the order the bioconda project asks for, with strict priority. Leave the defaults channel out: Miniforge does not include it, mixing it with conda-forge causes solver conflicts, and Anaconda’s terms of service require a paid license for its channels in larger organizations.

Terminal window
# Create an environment with a pinned Python and three tools
mamba create -n rnaseq python=3.12 samtools bcftools fastqc
# Activate and deactivate it
conda activate rnaseq
conda deactivate
# List all environments
conda env list
# List the packages in the active environment
mamba list
# Add, update, or remove a package in the active environment
mamba install multiqc
mamba update samtools
mamba remove fastqc
# Delete the environment
mamba env remove -n rnaseq

conda env list prints one line per environment with its path and marks the active one with *. Use conda activate even when mamba builds the environments; it works in every Miniforge install once conda init has set up the shell.

Keep the base environment for conda and mamba themselves. A tool installed into base shares its libraries with the package manager, and a broken base is hard to repair.

Terminal window
# Only the packages you asked for: portable across operating systems
conda env export --from-history > environment.yml
# Every package without build strings
conda env export --no-builds > environment.yml
# Every package with build strings: rebuilds only on the same platform
conda env export > environment.yml
# Rebuild an environment from a file
mamba env create -f environment.yml
# Exact package URLs and checksums for one platform
conda list --explicit --md5 > rnaseq_linux64_lock.txt
conda create -n rnaseq_exact --file rnaseq_linux64_lock.txt

Share the --from-history file with collaborators on other systems. Archive the explicit list next to a paper’s results, because it pins the exact package builds that produced them.

A hand-written environment.yml with pinned versions:

name: rnaseq
channels:
- conda-forge
- bioconda
dependencies:
- python=3.12
- samtools=1.21
- bcftools=1.21
- fastqc=0.12.1
- multiqc=1.25
- star=2.7.11b
- salmon=1.10.3

For a package that exists only on PyPI, add pip to dependencies and a pip: list under it. conda installs the conda packages first and the pip packages last, which keeps pip from replacing files that conda manages.

Package What it does
samtools Reads, filters, sorts, and indexes SAM, BAM, and CRAM
bcftools Filters, merges, and queries VCF and BCF
bwa, bwa-mem2 Short-read alignment to a genome
star Splice-aware RNA-seq alignment
salmon Transcript quantification
fastqc Read quality reports
fastp Adapter trimming and read filtering
multiqc One report from many QC outputs
bedtools Interval arithmetic on BED, GFF, and VCF
seqkit FASTA and FASTQ manipulation
gatk4 Variant calling
snakemake, nextflow Workflow managers

The mambaorg/micromamba image installs an environment.yml into its base environment, and its entrypoint activates base when a container starts. Build it with podman build -t rnaseq-tools .:

The recipe below matches the micromamba-docker 2.0.5 Quick Start examples. Both examples use the same ownership, installation, cleanup, and activation steps. This lesson changes the environment filename, adds the registry prefix, and omits the Python demonstration. The source records copyright 2021-2024 for micromamba-docker contributors under Apache 2.0. The documentation credits micromamba documentation contributors, 2023-2024. The exact source used during code generation remains unknown.

FROM docker.io/mambaorg/micromamba:2.0.5
COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yml /tmp/environment.yml
RUN micromamba install -y -n base -f /tmp/environment.yml && \
micromamba clean --all --yes
# Activate base for any RUN line below this one
ARG MAMBA_DOCKERFILE_ACTIVATE=1

Pin every version in the file. An unpinned image installs whatever is newest on the day you rebuild it.

A batch script runs in a shell that has not read your startup file, so conda activate fails with CommandNotFoundError. Load the hook first, or skip activation:

Terminal window
# Load conda's shell functions, then activate
source "$(conda info --base)/etc/profile.d/conda.sh"
conda activate rnaseq
samtools --version
# Or run one command inside an environment without activating it
conda run -n rnaseq samtools --version

Some bioconda packages still have no osx-arm64 build. Create the environment from the Intel packages, which run under Rosetta, and record that choice in the environment:

Terminal window
CONDA_SUBDIR=osx-64 mamba create -n rnaseq_x86 samtools
conda activate rnaseq_x86
conda config --env --set subdir osx-64
Symptom Fix
The solver reports conflicts between packages Check conda config --show channels; set conda-forge, then bioconda, with strict priority, and remove defaults
CommandNotFoundError from conda activate in a script Source conda.sh first or use conda run
PackagesNotFoundError on an Apple silicon Mac Create the environment with CONDA_SUBDIR=osx-64
A bioconda tool will not install with the newest Python Pin Python, for example python=3.12, in the create command
Tools broke after an install into base Create a separate environment per project
Tool Installs Use it for
conda Python, R, C libraries, command line tools Activation, configuration, and exports
mamba The same packages as conda Creating and updating environments
micromamba The same packages, from a single binary Containers and CI
pip Python packages from PyPI A PyPI-only package inside an environment
uv Python packages from PyPI Python projects with a pyproject.toml

A common setup puts the binary tools such as samtools and STAR in a mamba environment and the Python analysis code in a uv project.

  • Building Images builds a Podman image around an environment like the one above.
  • Why Reproducibility Matters explains how changing software versions break an analysis and what containers fix.
  • Snakemake gives each rule its own conda environment file.
  • SLURM shows the batch scripts where activation needs the conda.sh hook.

The conda environment guide distinguishes history exports from explicit package specifications and explains their platform limits. Use it to decide which environment record can reproduce the packages used by an analysis.

The Bioconda setup guide explains channel order and strict priority. The Miniforge README identifies the installer assets and activation steps for each platform.

The micromamba-docker 2.0.5 Quick Start explains environment installation and activation in the image used by the credited container recipe.