Conda Cheatsheet - Anaconda commandline parameters - most useful conda commands

Forgotten the conda command parameters?

Page content

Here’s a Conda Cheatsheet I’ve compiled some time ago… This Conda Cheatsheet is covering the most essential commands and tips for managing environments, packages, and channels I’ve found useful.

Sleeping conda

Have a look at the uv - New Python Package, Project, and Environment Manager

Installing and Updating Conda

  • Verify Conda Installation and Version:
    conda info
    
  • Update Conda:
    conda update conda
    
  • Update Anaconda Meta Package:
    conda update anaconda
    

Managing Environments

  • Create a New Environment:
    conda create --name my_env
    conda create -n my_env python=3.8  # Specify Python version
    conda create -n bioinfo fastqc trimmomatic bwa  # Create with specific packages
    
  • Activate an Environment:
    conda activate my_env  # On Windows, Linux, macOS
    source activate my_env  # On Linux, OS X (older syntax)
    
  • Deactivate an Environment:
    conda deactivate
    
  • List All Environments:
    conda env list
    conda info --envs
    
  • Clone an Environment:
    conda create --clone old_env --name new_env
    
  • Rename an Environment:
    conda env rename -n old_env -d new_env
    
  • Delete an Environment:
    conda env remove -n my_env
    conda remove --name my_env --all
    
  • List Revisions of an Environment:
    conda list --revisions
    
  • Restore Environment to a Revision:
    conda install --rev 3  # Roll back to revision 3
    

Managing Packages

  • List Installed Packages:
    conda list
    conda list -n my_env  # List packages in a specific environment
    
  • Install a Package:
    conda install package_name
    conda install -c conda-forge package_name  # Install from a specific channel
    conda install package_name=1.2.3  # Install a specific version
    
  • Update All Packages in an Environment:
    conda update --all
    
  • Uninstall a Package:
    conda remove package_name
    conda remove --name my_env package_name  # Uninstall from a specific environment
    
  • Search for Packages:
    conda search package_name
    conda search -c conda-forge package_name  # Search in a specific channel
    

Working with Channels

  • List Channels:
    conda config --show channels
    
  • Add a Channel:
    conda config --add channels conda-forge
    conda config --prepend channels conda-forge  # Add with highest priority
    conda config --append channels bioconda  # Add with lowest priority
    
  • Set Channel Priority:
    conda config --set channel_priority strict
    

Exporting and Importing Environments

  • Export Environment to YAML:
    conda env export > environment.yml
    conda env export --from-history > environment.yml  # Export only explicitly asked packages
    
  • Import Environment from YAML:
    conda env create --name my_env --file environment.yml
    
  • Export Environment to TEXT File:
    conda list --export > requirements.txt
    
  • Import Environment from TEXT File:
    conda create --name my_env --file requirements.txt
    

Additional Commands

  • Get Help for a Command:
    conda -h
    conda install -h
    
  • Clean Up Unused Files:
    conda clean --all
    
  • Examine Conda Configuration:
    conda config --get
    conda config --get channels
    

Mamba (Optional)

Mamba is a faster alternative to Conda, but it has some limitations, especially regarding environment revisions.

  • Install Mamba:
    conda install -c conda-forge mamba
    
  • Use Mamba Interchangeably with Conda: Most commands are the same, but Mamba does not support rolling back environment revisions[2][4].

Tips

  • Create Descriptive Environment Names: Helps in managing multiple environments.
  • Activate Environment Before Installing Packages: Ensures packages are installed in the correct environment.
  • Use Specific Channels for Packages: Ensures you get the packages from the desired sources.
  • Avoid Dependency Conflicts: Install all programs in the environment at the same time[5].