Skip to content

Installing a specific version of R on a Linux server using Conda

Conda is a package management tool that allows regular users (i.e. users who are not system adminstrators with special privileges) to install software. Regular users can even install Conda if it is not already available on a compute server.

For this example, we will install a minimal version of Conda called Miniconda.

First step is to download the miniconda installation script from https://docs.conda.io/en/latest/miniconda.html#latest-miniconda-installer-links

For most IEU compute servers, the Linux 64-bit script should work. If installation fails, older versions can be found further down that page https://docs.conda.io/en/latest/miniconda.html#linux-installers. Really old versions can be found here: https://repo.anaconda.com/miniconda/

To download the script, copy the download link and run the following two commands on the compute server.

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

Now use the script to install Conda.

bash Miniconda3-latest-Linux-x86_64.sh

Add the following lines to the end of your .bash_profile file in your home directory:

PATH=$HOME/miniconda2/bin:$PATH
export PATH

Log out and then log back in for these changes to take effect.

Before using Conda, it must be told how to search for software:

conda config --add channels conda-forge

For some reason Conda runs faster when using strict channel priority.

conda config --set channel_priority strict

Using Conda, it is possible to create different environments, each with different installed software. For example, multiple different versions of R could be installed, each in a different environment.

By default, if Conda is installed, the 'base' environment will be active.

I've decided that I want the 'base' environment to retain access to the default installation of R on the compute server. Therefore, I'll create a new environment called 'r42' for installing R v4.2.

conda create --name r42

Switch to 'r42' by activating it.

conda activate r42

Install R v4.2 as follows:

conda install r-base=4.2.0

As long as this environment is active, typing 'R' at the command line should start R v4.2.

Alternatively, activing the 'base' environment and typing 'R' will start the default installation of 'R' on the compute server.

conda activate base
R

Additional software packages available for installation can be found here: https://anaconda.org/

For example, it is possible to install many R packages using Conda, e.g.

# install a set of essential R packages
conda install -c r r-essentials

# add 'magick' package to R
conda install -c conda-forge imagemagick
conda install -c conda-forge r-magick

Although it is possible to install most packages with the install.packages() command in R, some packages require installation of libraries outside R. These can be handled automatically by installing the R package using Conda.