9

When I was in school the system administrator had multiple versions of R installed. I'm running into a bug with R-3.1.0 and need to install reinstall some past versions of R for development while this bug is investigated, but I don't see any documentation about how to have multiple concurrent versions of R on the same system ti should look something like

$ ls -l /usr/lib | grep R-
lrwxrwxrwx  1 root  root         8 Jun  3 09:41 R -> R-3.1.0/
drwxr-xr-x  9 root  root      4096 May 15 11:56 R-3.1.0
drwxr-xr-x  9 root  root      4096 May 15 11:56 R-3.0.3


$ ls -l /usr/bin | grep R-
lrwxr-xr-x  1 root  root         8 Jun  3 09:41 R -> R-3.1.0
-rwxr-xr-x  9 root  root      4096 May 15 11:56 R-3.1.0
-rwxr-xr-x  9 root  root      4096 May 15 11:56 R-3.0.3

I see no documentation about how to achieve this either in the R Installation and Administration guide or in the configure --help. I'm running a Gentoo system and the ebuild removes or overwrites the previous version of R on install, so I'll likely be installing from source.

Andrew Redd
  • 4,632
  • 8
  • 40
  • 64
  • 2
    [Use `configure --prefix`, or `make prefix=...`](http://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installation) – Joshua Ulrich Jun 03 '14 at 16:00
  • Someone recently shared a tool with me that is specifically for this, https://github.com/viking/Renv, but I'd just tend towards Dirk's approach. – russellpierce Apr 01 '18 at 01:52
  • This more recent (Feb 2020) RStudio support blog post might be helpful as well [Installing multiple versions of R on Linux](https://support.rstudio.com/hc/en-us/articles/215488098-Installing-multiple-versions-of-R-on-Linux) – Valentin_Ștefan Dec 26 '20 at 16:14

2 Answers2

8

Yes, this is pretty easy as Josh Ulrich's comment already says.

People usually have this question regarding r-devel installation alongside the basic R you will get from your distro. I use a simple shell script to build / update R-devel, and two matching ones to run R-devel and Rscript-devel. I can't recall if I blogged about it, but folks seem to point to an this older post on the r-sig-debian list which contains it. Here is a nice post by Michael detailing the same process.

And by creating new subdirectories, you can add as many R version as you want. You should keep the local builds in /usr/local, though, and could create softlinks for the binaries in /usr/local/bin. The script R itself will have R_HOME_DIR hard-coded and "just work".

Fancier approaches involve virtualization, and on Linux your best bet is docker which I am playing with now, and which I hope to detail at some point for this very purpose of testing R packages against multiple compilers etc.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks Dirk. I don't need anything that complicated. It's just that the parser data for R-3.1.0 is messed up and giving bad results. I need to install 3.0.3 until Duncan has a chance to look at and fix it. So do I just use --prefix=/usr/local/R-3.0.3 and then there's some linking that I have to do. – Andrew Redd Jun 03 '14 at 18:52
  • 1
    To anyone reading I would recommend also the guide from [Rstudio](https://support.rstudio.com/hc/en-us/articles/215488098-Installing-multiple-versions-of-R) – llrs Aug 30 '17 at 08:48
  • did you ever write anything up about the docker usage dirk? – baxx Sep 01 '20 at 23:40
  • Not a formal tutorial as far as I can remember -- but if you look _e.g._ at the [`.travis.yml` for Rcpp](https://github.com/RcppCore/Rcpp/blob/master/.travis.yml) it constructs a matrix using multiple R versions via multiple Docker containers. – Dirk Eddelbuettel Sep 01 '20 at 23:45
  • This is no longer accessible ' Here is a nice post by Michael ' – Jia Gao Aug 04 '23 at 03:27
  • Well I wrote that nine years ago. Sometimes the internet does not provide time-stable links. – Dirk Eddelbuettel Aug 04 '23 at 03:28
  • Thanks for the prompt reply. I understand that. Could you please share links to other similar content that I could use? – Jia Gao Aug 04 '23 at 03:30
0

I'm not an expert on R but on Linux you can always use schroot and debootstrap to create a new isolated environement with different versions of R, libraries, ... Actually I use it to compile different versions of code for RedHat, Ubuntu or Debian.

See for example: https://wiki.ubuntu.com/DebootstrapChroot

(Once you get use to it, it will take no more than 20 minutes to create a new chrooted system)

earizon
  • 2,099
  • 19
  • 29