20.04 – How to install specific R version in ubuntu

Binary packages approach

Before proceeding I need to repeat my points – you can install R 3.6.3 using packages from official repository. Or install R 4.0 from CRAN. And then install here R-package with specified version using commands like shown below:

install_version("ggplot2", version = "0.9.1", repos = "http://cran.r-project.org")

Note: for package names and version consult with R package index.

Manual compilation approach

If you really want to compile older version of R by yourself, then read the next text carefully. Be ready for 900 Mb download and 2200 Mb disk space usage (numbers are shown for fresh system).

To compile older version of R you need to enable source code repositories (deb-src) in Software & Updates (software-properties-gtk), then download the source code, compile it and install compiled binaries and other components. Use commands below:

sudo apt-get update
sudo apt-get build-dep r-base-dev

cd ~/Downloads
wget -c https://cran.r-project.org/src/base/R-3/R-3.5.0.tar.gz
tar -xf R-3.5.0.tar.gz
cd R-3.5.0
make -j9
sudo make install