Tutorial:Installing/switching between versions of R/Rstudio/Bioconductor on personal machine (Linux | Ubuntu)
Entering edit mode
BioinfGuru ▴ 30
Last seen 2 days ago

Hi all,

I noticed there are many questions and no dedicated tutorials here for installing multiple versions of R and bioconductor so I thought I''d share how I install and switch between versions of R and bioconductor on Ubuntu. This is for both beginners on first installation of R/Rstudio/Bioconductor, and intermediates looking to use multiple versions. I find it useful to have everything in one place. I've also included the most useful links for each step that helped me piece this together for whenever I do a complete re-install.

Hope it helps someone out!



  1. 19/4/24 - The scope of this tutorial is for those installing on personal machines (sudo privilage is required). Next time I install, I'll be trying to install as guest, without sudo to see what fixes are required. For those who want to use this on a cluster, that is beyond the scope of this tutorial.


Source: Posit - Install R

Remember: All versions of R are always installed in /opt/R, while a symlink is placed in /usr/local/bin/R. So the command "which R" always returns the symlink, not the installation location or version

First Installation: View the list of R versions and choose the latest (currently 4.3.3)

sudo snap install curl # step 1
sudo apt-get update # step 2
sudo apt-get install gdebi-core # step 3
export R_VERSION=4.3.3 # step 4 - notice version number is latest version always for first installation
curl -O https://cdn.rstudio.com/r/ubuntu-2204/pkgs/r-${R_VERSION}_1_amd64.deb # step 5
sudo gdebi r-${R_VERSION}_1_amd64.deb # step 6
/opt/R/${R_VERSION}/bin/R --version # step 7 - verify installation
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R # step 8 - create R symlink (first installation only)
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript # step 9 - create Rscript symlink (first installation only)
R --version # step 10 - verify R symlink
Rscript --version # step 11 - verify Rscript symlink

Now to install additional versions of R (older or newer) is simple:

  1. Edit step 4 (e.g. export R_VERSION=4.2.3)
  2. Repeat steps 4-7 only (the default version is always the last one you install)

And to change the default R version (always used by Rstudio) is also simple (just edit the symlinks):

export R_VERSION=X.X.X # select the version you wish to be the default
sudo ln -sf /opt/R/${R_VERSION}/bin/R /usr/local/bin/R # edits R symlink
sudo ln -sf /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript # edits Rscript symlink
readlink -f /usr/local/bin/R && readlink -f /usr/local/bin/Rscript # verify symlinks
R --version # verify R version
Rscript --version # verify Rscript version                                                                                  

And to temporarily use a different R version is simple:

/opt/R/4.2.3/bin/R    # runs version 4.2.3



  1. Posit - code signing
  2. Posit - Rstudio download
  3. Posit - Using different versions of R

This may be specific to my machine, or operating system (Ubuntu 22.04), but it works without error for me so I'm posting this as some people also have trouble installing Rstudio and get stuck in a tree of errors due to not having some of the dev packages listed below installed on there machine.

gpg --keyserver keys.openpgp.org --search-keys 51C0B5BB19F92D60         # enter number 1 when prompted
sudo apt-get install libxml2-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libcurl4-openssl-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev

Finally, I can download the ubuntu 22 .deb file and install with 'software install'

And now, to change the version of R that RStudio uses is simple:

Opening Rstudio with the app icon always uses the default version of R. So to have Rstudio run a different R version you have 2 options:

  1. Change the default version of R (above) or ...
  2. Open Rstudio from the terminal after explicitly telling it which R version to use. This switching of versions is temporary and ends as soon as the terminal is closed. Don't worry, you will still be looking at the Rstudio GUI with full functionality, all that has changed is how you open it, and the R version.

Here is how to do the second option:

export RSTUDIO_WHICH_R=/opt/R/4.2.3/bin/R   # tell Rstudio which version to use from terminal
rstudio # now starting RStudio from the terminal runs R version 4.2.3 (clicking on the desktop icon will still use the default R version



  1. CRAN - Biocmanager
  2. Match R version and Bioconductor version


  • Each Bioconductor release is designed to work with a specific version of R
  • R releases have 2 digits (e.g. 4.3), R updates have 3 digits (4.3.2)
  • R has 1 release per year, but Bioconductor has 2 releases
  • So for every R release (4.3), there are 2 bioconductor releases (3.17, 3.18)

So remember: If you require a specific bioconductor release, you must first install and switch to the R version it matches to!

Open Rstudio and Install the latest release of bioconductor for the R version running:

install.packages("BiocManager", repos = "https://cloud.r-project.org") # IF R-4.3.3, installs bioconductor version 3.18
BiocManager::version() # Verify version
BiocManager::install("DESeq2") # install a bioconductor package

Switch to the other of the 2 releases for the R version currently running:

BiocManager::install(version="3.17") # Updates all packages to the specified Bioconductor version
BiocManager::version() # view bioconductor version
BiocManager::valid() # identify packages that are out-of-date or from unexpected version
bioconductor Install • 408 views

Login before adding your answer.

Traffic: 424 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6