Running different versions of R in the RStudio IDE is, on occasion, required to load older packages.

[This article was first published on, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is a re-post by the author from:

I got fed up with the manual process, so I started to automate the entire process Ubuntu in a bash script. This script should work for most Debian based distros.

TLDR -> Get to the Code on Github!

<em>(Through out this process stackoverflow was my friend.)</em>

Generally the process for 3.4.4 (for example) is to:

1. Download R from CRAN

<a href=""><span class="pl-smi">3</span>/R-<span class="pl-smi">3.4.4</span>.<span class="pl-smi">tar.gz</span></a>

2. Un-archive files

tar -xzvf R-<span class="pl-smi">3.4.4</span>.<span class="pl-smi">tar.gz</span>

3. Make from source

<em>(from inside the un-archived directory)</em>
sudo ./configure --prefix=/opt/R/$r_ver --enable-R-shlib && \
sudo make && \
sudo make install

4. Update environment variable  for R-Studio

<span>export RSTUDIO_WHICH_R=</span><span class="pl-s"><span class="pl-pds">"/opt/R/<span class="pl-smi">3.4.4</span>/bin/R</span><span class="pl-smi">"</span></span>

5. Launch R-Studio (in the context of this environment variable)


I started down the road of manually downloading all the .tar.gz files of the versions that I might want to install, so then I grabbed a method for un-archiving all these files at one time.

find . -name '*.tar.gz' -execdir tar -xzvf '{}' \;

Here is where I started to Build and install R from source in an automating script at once I use this


From here i added a menu system i found on stack overflow. This script prompts to install whatever version of R you are attempting to launch if not yet installed.

This file can be downloaded, inspected and run from the github RAW link, of course to run a .sh file it needs to be updated to be executable with


I have found that by just directing the gist’s contents directly into bash i can skip that step!


Executing this script also places a copy of it’s self in the current users local profile, and a link to a new .desktop for the local Unity Launcher on first run. This allows me to run this custom launcher from the application launcher. I then pin it as a favorite to the Dock manually.

The completed can be found on Github HERE or view RAW script from Github

Jeremy D. Gerdes
[email protected]
April 2019
<img class="wp-image-36" src="" alt="Creative Commons by-sa 4.0" /> 
(CC BY-SA 3.0) 

To leave a comment for the author, please follow the link and comment on their blog: offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)