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.
Quick reference
Section titled “Quick reference”| 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 |
The tools
Section titled “The tools”| 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 |
Install Miniforge
Section titled “Install Miniforge”base=https://github.com/conda-forge/miniforge/releases/latest/downloadinstaller="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.
Set the channels
Section titled “Set the channels”conda config --add channels biocondaconda config --add channels conda-forgeconda config --set channel_priority strictconda 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.
Environments
Section titled “Environments”# Create an environment with a pinned Python and three toolsmamba create -n rnaseq python=3.12 samtools bcftools fastqc
# Activate and deactivate itconda activate rnaseqconda deactivate
# List all environmentsconda env list
# List the packages in the active environmentmamba list
# Add, update, or remove a package in the active environmentmamba install multiqcmamba update samtoolsmamba remove fastqc
# Delete the environmentmamba env remove -n rnaseqconda 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.
Reproducible environments
Section titled “Reproducible environments”# Only the packages you asked for: portable across operating systemsconda env export --from-history > environment.yml
# Every package without build stringsconda env export --no-builds > environment.yml
# Every package with build strings: rebuilds only on the same platformconda env export > environment.yml
# Rebuild an environment from a filemamba env create -f environment.yml
# Exact package URLs and checksums for one platformconda list --explicit --md5 > rnaseq_linux64_lock.txtconda create -n rnaseq_exact --file rnaseq_linux64_lock.txtShare 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: rnaseqchannels: - conda-forge - biocondadependencies: - python=3.12 - samtools=1.21 - bcftools=1.21 - fastqc=0.12.1 - multiqc=1.25 - star=2.7.11b - salmon=1.10.3For 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.
Common bioconda packages
Section titled “Common bioconda packages”| 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 |
Environments inside a container
Section titled “Environments inside a container”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.5COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yml /tmp/environment.ymlRUN micromamba install -y -n base -f /tmp/environment.yml && \ micromamba clean --all --yes# Activate base for any RUN line below this oneARG MAMBA_DOCKERFILE_ACTIVATE=1Pin every version in the file. An unpinned image installs whatever is newest on the day you rebuild it.
Activate in a script
Section titled “Activate in a script”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:
# Load conda's shell functions, then activatesource "$(conda info --base)/etc/profile.d/conda.sh"conda activate rnaseqsamtools --version
# Or run one command inside an environment without activating itconda run -n rnaseq samtools --versionApple silicon
Section titled “Apple silicon”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:
CONDA_SUBDIR=osx-64 mamba create -n rnaseq_x86 samtoolsconda activate rnaseq_x86conda config --env --set subdir osx-64Common problems
Section titled “Common problems”| 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 |
conda, mamba, pip, or uv
Section titled “conda, mamba, pip, or uv”| 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.
See also
Section titled “See also”- 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.shhook.
Further reading
Section titled “Further reading”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.