Install R On OSX

By Rémi GATTAZ OS X Polytech RICM4

For this tutorial, you will need to have previously installed brew.

Step 1 : Install dependencies :

R needs gcc-5 to be the default gcc version. If you are not sure which version you are currently using, just type the following in a terminal.

$ gcc --version

If the version is higher that 5, you can skip to the next step. If it wasn't you will need to install it.

$ brew install gcc

This installed the latest version of gcc (5.2.0 as I am writing this). However, this newly installed version is not prioritary to the others yet. If you were to run the first command again, the result would most likely be the same it was.

To force the fact that it is this version that must be run when you use the command gcc, execute this command :

$ brew link --overwrite gcc

Step 2 : Install R

R exists in brew. Not in the default formulas though. You will first need to tap the science formulas to use its formula.

$ brew tap homebrew/science
$ brew update

R can then be installed with brew

$ brew install r

Step 3 : Try R

To try R, we will do a simple "Hello World". Open a terminal and do the following.

$ R
> print('Hello World!');
[1] "Hello World!"

If R returned you the line starting with '[1]', the installation of R was successful.

Step 4 : Install RStudio

brew mainly manages command line apps. There however exists a tool inside of brew called cask that was created to install desktop apps.

Cask is installed with the following :

$ brew install caskroom/cask/brew-cask

You can then use cask to install RStudio

$ brew cask install rstudio
Comments powered by Disqus