Installing a specific version of R on Linux Ubuntu requires to compile it from source code
Installing R from source is required whenever you need a specific version of R
rather than latest release available as binary on either CRAN or Ubuntu repositories.
Enable the required and optional repositories. You will need them to check R installation dependencies.
Ad the R pubblic key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7'
Add the following lines in /etc/apt/source.list
deb http://cloud.r-project.org/bin/linux/debian bullseye-cran40/
deb-src http://cloud.r-project.org/bin/linux/debian bullseye-cran40/
Next update and, install the build dependencies for R:
sudo apt update
sudo apt-get build-dep r-base
After checking dependencies you’d better comment those lines in source.list
.
export R_VERSION=4.1.2
curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
./configure \
--prefix=/opt/R/${R_VERSION} \
--enable-memory-profiling \
--enable-R-shlib \
--with-blas \
--with-lapack \
--with-tcltk
Tcltk has been added as packages TSclust
and TSdist
wont compile
make
sudo make install
/opt/R/${R_VERSION}/bin/R --version
To ensure that R is available on the default system PATH variable, create symbolic links to the version of R that you installed:
sudo ln -fs /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -fs /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
The f
flag force symlink to recreate and therefore to update from previous R versions
If you see mistakes or want to suggest changes, please create an issue on the source repository.
For attribution, please cite this work as
Spano (2021, Nov. 18). andreaspano blog: Installing R from source. Retrieved from https://andreaspano.github.io/posts/2021-11-18-installing-r-from-source/
BibTeX citation
@misc{spano2021installing, author = {Spano, Andrea}, title = {andreaspano blog: Installing R from source}, url = {https://andreaspano.github.io/posts/2021-11-18-installing-r-from-source/}, year = {2021} }