How to use `ln -s` to change between R Versions on Mac?

Viewed 1341

An RStudio support article says that you can alternate between different R Versions on your mac if you "update the R.framework/Versions/Current directory alias directly using ln -s"

How exactly do you use ln -s to change between R Versions?

When I type into my terminal ls -l /Library/Frameworks/R.framework/Versions/ I see:

total 0
drwxrwxr-x  6 root  admin  192 Jan 15 09:04 3.3
drwxrwxr-x  6 root  admin  192 Jun  5 16:36 3.5
drwxrwxr-x  3 root  admin   96 Jun  5 16:36 3.6
lrwxr-xr-x  1 root  admin    3 Jun  5 16:36 Current -> 3.5

But I am unsure of how ln -s can be used to alternate between these R versions. I have currently "switched" from 3.6 to 3.5 by redownloading 3.5. A practice I would like to avoid.

Into my terminal I typed rm /Library/Frameworks/R.framework/Versions/Current which did remove the existing Current. And then on separate attempts I have typed ln -s 3.6 /Library/Frameworks/R.framework/Versions/Current

This changed the symlink

ls -l /Library/Frameworks/R.framework/Versions/ 
total 0 
drwxrwxr-x 6 root admin 192 Jan 15 09:04 3.3 
drwxrwxr-x 6 root admin 192 Jun 5 16:36 3.5 
drwxrwxr-x 4 root admin 128 Jun 6 09:09 3.6 
lrwxr-xr-x 1 joepowers admin 3 Jun 6 09:15 Current -> 3.6

But when I type R.version in the console I get back 3.4.3

Next I tried

ln -s /Library/Frameworks/R.framework/Versions/3.6 /Library/Frameworks/R.framework/Versions/Current
ls -l /Library/Frameworks/R.framework/Versions/
total 0
drwxrwxr-x  6 root       admin  192 Jan 15 09:04 3.3
drwxrwxr-x  3 root       admin   96 Jun  6 09:21 3.5
drwxrwxr-x  7 root       admin  224 Jun  6 09:21 3.6
lrwxr-xr-x  1 joepowers  admin   44 Jun  6 09:23 Current -> /Library/Frameworks/R.framework/Versions/3.6

But typing R.version in the console still returns 3.4.3 even after restarting RStudio.

1 Answers

ln -s creates a symlink, also known as an alias (on Mac) or shortcut (in Windows).

When it starts R, RStudio loads the version of R in /Library/Frameworks/R.framework/Versions/Current.

From that view you posted above, we can see that you have 3 versions of R installed (3.3, 3.5, and 3.6). /Current is actually a symlink to 3.5 (that's what the Current -> 3.5 means).

If you want to change this, you need to:

  1. Go to the appropriate directory with: cd /Library/Frameworks/R.framework/Versions/
  2. Delete the existing Current symlink with: rm Current
    • rm will delete symlinks to directories but will not delete directories themselves
  3. Create a new symlink to version 3.6 with: ln -s 3.6 Current
Related