Conda (Miniconda) Cheatsheet: Essential Commands You Should Know
Tags: cheatsheet, conda, environmentmanagemen, miniconda
Published: 2024-01-17 17:24:43

---
title: Conda (Miniconda) Cheatsheet: Essential Commands You Should Know
published: true
date: 2024-01-01 23:56:43 UTC
tags: cheatsheet,conda,EnvironmentManagemen,miniconda
canonical_url: https://diegocarrasco.com/conda/
---

![](https://diegocarrasco.com/images/social-images/conda.jpg)

 

- [TLDR:](https://diegocarrasco.com/conda/#tldr)
- [What is Conda?](https://diegocarrasco.com/conda/#what-is-conda)
- [Essential Conda Commands:](https://diegocarrasco.com/conda/#essential-conda-commands)
  - [1. Installing Conda (Miniconda):](https://diegocarrasco.com/conda/#1-installing-conda-miniconda)
  - [2. Managing Environments:](https://diegocarrasco.com/conda/#2-managing-environments)
  - [3. Managing Packages:](https://diegocarrasco.com/conda/#3-managing-packages)
    - [from Conda:](https://diegocarrasco.com/conda/#from-conda)
  - [from conda repositories:](https://diegocarrasco.com/conda/#from-conda-repositories)
  - [from Pip:](https://diegocarrasco.com/conda/#from-pip)
  - [4. Updating Conda:](https://diegocarrasco.com/conda/#4-updating-conda)
  - [5. Exporting and Importing Environments:](https://diegocarrasco.com/conda/#5-exporting-and-importing-environments)
  - [6. Miscellaneous Commands:](https://diegocarrasco.com/conda/#6-miscellaneous-commands)
- [References:](https://diegocarrasco.com/conda/#references)

### TLDR:

This cheatsheet is a summary of the common commands I use. It serves as a quick reference to the most important Conda (Miniconda) commands and as a reminder for myself.

### What is Conda?

Conda is a package and environment management system, widely used in the Python and data science community. It allows you to separate projects into environments and install packages into them, making it easy to manage dependencies and avoid conflicts between packages. It also helps to replicate a specific environment in another computer.

MiniConda is a minimal installer for Conda. It includes only Conda, Python, and a few essential packages, and it's managed thought the terminal.

### Essential Conda Commands:

#### 1. Installing Conda (Miniconda):

- **Download Miniconda** : Visit the [official Miniconda page](https://docs.conda.io/en/latest/miniconda.html) and download the installer for your OS.
- **Install Miniconda** : Follow the installation instructions provided on the download page. In Linux that means running the following:

```
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh # if you don't want to keep the installer

```

You need to initialize conda for your shell for it to work:

```
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh

```

and restart your terminal or run `source ~/.bashrc` or `source ~/.zshrc` for the changes to take effect.

#### 2. Managing Environments:

- **Create** an Environment: `conda create --name myenv`
- **Activate** an Environment: `conda activate myenv`
- **Deactivate** an Environment: `conda deactivate`
- **List** all Environments: `conda env list`
- **Remove** an Environment: `conda env remove --name myenv`
- **Clone** an Environment: `conda create --name myclone --clone myenv`
- **Create an Environment from a File** : `conda env create -f environment.yml`
- **Update an Environment from a File** : `conda env update -f environment.yml`
- **Export an Environment to a File** : `conda env export > environment.yml`

- **Export an Environment to a File (including Conda itself)**: `conda list --explicit > environment.yml`

- **Create an Environment from a File (including Conda itself)**: `conda create --name myenv --file environment.yml`
- **Update an Environment from a File (including Conda itself)**: `conda update --name myenv --file environment.yml`

#### 3. Managing Packages:

##### from Conda:

this is the main and default repository for conda packages.

- **Install a Package** : `conda install numpy`
- **Uninstall a Package** : `conda remove numpy`
- **List Installed Packages** : `conda list`
- **Update a Package** : `conda update numpy`
- **Search for a Package** : `conda search numpy`

#### from conda repositories:

There are alternative repositories to the default one, such as `conda-forge` and `bioconda`. You can install packages from these repositories by specifying the channel.

- Install a Package **from `conda-forge`** : `conda install -c conda-forge numpy`
- Install a Package **from `bioconda`** : `conda install -c bioconda numpy`

#### from Pip:

Some packages are not in conda, so you need to use pip to install them. `pip` is the default package manager for Python.

- **Install Pip** , if its not installed: `conda install pip`
- **Install a Package** : `pip install numpy`

#### 4. Updating Conda:

To update conda itself, you need to update the base environment. This means deactivating the environment you are in and updating the base environment.

- **Update Conda** : `conda update conda`

#### 5. Exporting and Importing Environments:

- **Export Environment** : `conda env export > environment.yml`
- **Create Environment from a File** : `conda env create -f environment.yml`

#### 6. Miscellaneous Commands:

- **List Conda Commands** : `conda --help`
- **Check Conda Version** : `conda --version`

### References:

- [Conda Official Documentation](https://docs.conda.io/projects/conda/en/latest/commands/index.html