Skip to content

Using Conda for Software Installation

This section covers using conda to install scientific software.

What is Conda?

Installing scientific software (including all required dependencies of said software!) is often challenging. Conda is a software manager that helps you find and install software packages.

Set up Miniconda

To get started, we'll install miniconda, which contains everything we need to get started with conda.

Log in to farm and run the following commands to install Miniconda. Follow the prompts on the screen and accept all default options.

Install conda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Again, be sure to answer yes to any yes/no questions, especially the last question about conda init! This will ensure conda is fully installed and you'll be able to use it for the commands below.

Copy .bashrc code to .bash_profile

FARM runs .bash_profile on startup (not .bashrc). Here, we explicitly run the .bashrc from the .bash_profile file

echo source ~/.bashrc >> ~/.bash_profile

Activate conda

Miniconda is now installed, but we need to activate it to be able to use it.

source ~/.bashrc

This command executes our ~/.bashrc command, which should now have

You should now see (base) in front of your prompt, indicating that you are in the base environment.

Optional: Add colors to your terminal output

If you have preferred settings for bash, go ahead and set them up.

Open the .bash_profile file using nano

cd
nano .bash_profile

Now, add the following to the document:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls --color=auto'

And close and save the document (Ctrl-X, Y, <Enter>)

Now source the file:

source .bash_profile

Try an ls! Is your miniconda3 folder a different color than the Miniconda3-latest-Linux-x86_64.sh installer?

Configuring channels

Conda works by searching for software packages in online repositories (Channels). By default, conda searches for software only in Continuum’s (Conda’s developer) channels.

Most of the scientific software we'll be using is not available within the default channel, so we will add additional channels to our conda settings.

Channels in Conda are ordered. The channel with the highest priority is the first one that Conda checks, looking for the package you asked for. You can change this order, and also add channels to it (and set their priority as well).

If multiple channels contain a package, and one channel contains a newer version than the other one, the order of the channels’ determines which one of these two versions are going to be installed, even if the higher priority channel contains the older version.

conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge

Note that these commands stack. In this case, the highest priority channel will be conda-forge, followed by bioconda and then the defaults channel.

So when installing software, conda will start by looking for our desired software packing in the conda-forge channel, then search in the bioconda channel, and finally search in the defaults channel.

Using Conda environments

Different software packages often have different "dependencies": other software packages that are required for installation. In many cases, you'll need software with dependencies that conflict -- e.g. one program requires python version 3, while the other requires python 2. To avoid conflicts, we install software into "environments" that are isolated from one another - so that the software installed in one environment does not impact the software installed in another environment.

Create an environment

Let's start by creating an environment for this project

conda create -y --name nsurp-env

This creates an empty environment named nsurp-env. To activate this environment, run:

conda activate nsurp-env

Your prompt should now start with (nsurp-env).

Install software into the environment

We can now install software into our environment. Let's install sourmash, which we will use in a later lesson.

conda install -y sourmash

Deactivating and Exiting

When you'd like to leave your environment, you can type conda deactivate and you will return to the base environment.

When you log out of farm by typing exit, when you end a tmux or screen session, or when an srun job ends, your environment will automatically be deactivated. To restart the environment, you can run conda activate nsurp-env.

Additional Resources

This tutorial covers the basics of conda including a brief introduction to conda and why it is useful, installation and setup, creating environments, and installing software.

These videos cover the material in the above tutorial:

  • video 1
  • video 2 (there were some technical issues with this recording...sorry!)