Skip to main content

Manage environment with Conda

Environment Setup and Management for Data Science and Bioinformatics

Created

October 9, 2022

Modified

November 5, 2026

Pixi

  • Website:https://pixi.prefix.dev/latest/

  • Install pixi on new machine

    • copy the yaml file: ~/.config/pixi/manifest.toml
    • Run the sync command to automatically download and isolate all your global tools
    • pixi global sync
## Auto-activate pixi when entering project directory
eval "$(pixi completion --shell bash)"  # or zsh
## Create a global pixi environment with specific R version and packages
pixi global install -e renv \
    r-base=4.5 \
    r-languageserver \
    r-tidyverse \
    r-irkernel \
    r-httpgd \
    r-downlit \
    r-xml2 \
    r-markdown \
    r-devtools \
    radian

## Print out  global pixi environments
pixi global list

## Add Bioconda Permanently
pixi config append default-channels bioconda --global
pixi config set default-channels '["conda-forge", "bioconda"]' --global

## Remove a environment and all its packages
pixi global uninstall <env_name>

## Restore the exposed R and Rscript binaries in the global environment
pixi global install --environment renv --expose R --expose Rscript r-base

manifest

# Linux/mac
code ~/.pixi/manifests/pixi-global.toml

# Windows
code "C:\Users\guorui\.pixi\manifests\pixi-global.toml"
  • Example of a manifest file
version = 1
[envs.renv]
channels = ["conda-forge", "bioconda"]
platform = "win-64"

[envs.renv.dependencies]
r-base = "4.5.*"
r-languageserver = "*"
r-tidyverse = "*"
r-irkernel = "*"
r-httpgd = "*"
r-downlit = "*"
r-xml2 = "*"
r-markdown = "*"
r-devtools = "*"
r-here = "*"
r-writexl = "*"
bioconductor-biostrings = "*"
r-argparse = "*"
r-ape = "*"
r-ggplot2 = "*"
ipykernel = "*"
matplotlib = "*"
r-seurat = "*"
r-clustree = "*"
r-anndata = "*"
bioconductor-rhdf5 = "*"
bioconductor-anndatar = "*"
bioconductor-deseq2 = "*"
bioconductor-ComplexHeatmap = "*"
bioconductor-zellkonverter = "*"
bioconductor-hdf5array = "*"
bioconductor-singlecellexperiment = "*"
r-pheatmap = "*"
r-qs2 = "*"
r-BPCells = "*"
zlib = "*"
quarto = "*"
r-renv = "*"
r-knitr = "*"
r-rmarkdown = "*"
pandoc = "*"
jupyter = "*"
python = "*"
ipython = "*"

[envs.renv.exposed]
quarto = "quarto"
R = "R"
Rscript = "Rscript"
pandoc = "pandoc"
RSetReg = "RSetReg"
Rcmd = "Rcmd"
Rfe = "Rfe"
Rgui = "Rgui"
Rterm = "Rterm"
open = "open"
jupyter = "jupyter"
python = "python"
pythonw = "pythonw"
idle = "idle"
pydoc = "pydoc"
ipython = "ipython"
ipython3 = "ipython3"

Conda

  • Installation

# Miniforge linux
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh"

# Miniforge Mac
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh"

# Install it
bash Miniforge3-$(uname)-$(uname -m).sh

# Add conda to PATH if found
if [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then
    . $HOME/miniconda3/etc/profile.d/conda.sh
fi
  • Configuration

# Init
conda init --all

# Use mamba for faster solving
conda update -n base conda
conda install -n base conda-libmamba-solver

# Config
conda config --set solver libmamba
conda config --set always_yes true
conda config --set auto_activate_base false

# Setup channels
conda config --add channels bioconda
conda config --add channels conda-forge
#conda config --set channel_priority strict

# Install software from a specific channel
conda install -c conda-forge numpy
  • Create Environment
# Create R environment with specific R version and packages
conda create -n renv r=4.5 r-languageserver r-tidyverse r-irkernel r-httpgd r-downlit r-xml2 r-markdown r-devtools radian

# Install bioconductor packages, all package names are lower case
conda install -n renv bioconductor-deseq2 bioconductor-edger

# Install repository packages
conda install -n renv r-qs r-fs r-tidyverse

# Remove a specific environment
conda remove --name renv --all

# Remove a software in a environment
conda remove --name renv package_name

# Export and save the conda env file with all software information
conda env export -n renv > renv.yml

# Export and save the conda env file with all software information
# without the prefix and bundle information
conda env export -n renv --no-builds > renv.yml
conda env export -n renv --no-builds --file renv.yml

# Create a new environment with a environment file
conda env create --file renv.yml

# Rename an environment
conda create --name new_env_name --clone old_env_name
conda activate new_env_name
conda remove --name old_env_name --all
Back to top