86

How do I install "R" on macOS? Ideally using Homebrew?

There seems to be very little information online.

nohillside
  • 100,768
matt burns
  • 3,812
  • 3
  • 21
  • 24
  • 1
    Note people finding this answer who just want to install R the normal way should see the second answer here that mentions how to get the standard installation files. – Jeromy Anglim May 08 '17 at 23:51
  • See also: https://stackoverflow.com/q/20457290/3924118 and https://stackoverflow.com/q/29017001/3924118. –  Feb 26 '18 at 11:36
  • for you guys who stumble upon this, especially who use Mojave++ consider to install it from CRAN instead homebrew, ref: https://github.com/tidyverse/tidyverse/issues/154 and https://stackoverflow.com/questions/50229781/package-installation-in-r-fail-on-macos/50252325 – buncis Jun 11 '19 at 13:48

7 Answers7

117

Install Homebrew (if needed)

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install R

brew tap homebrew/science
brew install r
matt burns
  • 3,812
  • 3
  • 21
  • 24
  • I also ran "brew install gfortran" beforehand, but I don't think it was necessary. If someone could please confirm... – matt burns Feb 18 '14 at 12:18
  • 7
    Indeed, Homebrew should automatically install all required dependencies. – grg Feb 18 '14 at 12:21
  • 1
    With this method are you able to install packages from CRAN? I was unable to get packages from CRAN to install correctly when I installed R using brew. When I switched to a copy of R downloaded directly from CRAN, my problems went away. – Rob Donnelly Feb 18 '14 at 21:41
  • 1
  • I didn't see gfortran in the dependencies it installs with homebrew. It's not technically a required dependency anyway. It's only necessary if you install packages that require it. – neverfox Mar 08 '15 at 23:10
  • Depends on Caskroom/cask/xquartz (not automatic) – OJFord May 17 '15 at 14:44
  • 3
    @PiotrMigdal Currently (April 2017) it works with RStudio again. – xji Apr 25 '17 at 14:43
  • Thanks @Xiang. i have no occasion installing r via brew so far. what do you say about installing packages as of today? – nyxee Jul 26 '17 at 05:32
  • Why is curl wrapped in ruby? – isomorphismes Feb 24 '18 at 19:20
  • 4
    I got Error: homebrew/science was deprecated. This tap is now empty as all its formulae were migrated. while trying out brew tap homebrew/science – Daniel Mar 18 '18 at 12:10
  • for you guys who stumble upon this, especially who use Mojave++ consider to install it from CRAN instead homebrew, ref: https://github.com/tidyverse/tidyverse/issues/154 and https://stackoverflow.com/questions/50229781/package-installation-in-r-fail-on-macos/50252325 – buncis Jun 11 '19 at 13:50
31

Assuming you just want to install “R” on OS X and are not interested in homebrew:

Just download the binary from CRAN https://cloud.r-project.org/

  1. Go to http://www.r-project.org/
  2. Click CRAN
  3. Select a mirror
  4. Click "download R for (Mac) OS X"
  5. Download and install the latest pkg binary

See also the R for Mac OSX FAQ that includes information on installation.

Note also the comments below suggesting that homebrew is often not the best option.

  • 7
    Installing Yosemite (re)moved my old R, and I wanted it back. I initially thought to install R using brew, but after following the instructions on this page I ended up with a trainwreck that didn't work correctly and took a while to remove. Not to mention that it ran for hours overnight installing gcc and lots of other things I didn't need or want. After clearing up and hoping "brew doctor" was right, I when to CRAN and downloaded the installer and within 5 minutes had a fully working R with no fuss at all. All I had to do was re-source my terminal. I should have used CRAN first. – Fran K. Jun 19 '15 at 12:33
  • Was your old R under Yosemite installed using brew as well? – jfoo Jan 13 '16 at 21:25
  • 15
    +25: *Just install via r-project.org package.* I am a brew fan, but it was NOT the right way to install R in my case because of gcc dependency catastrophe; save yourself. – hoc_age Feb 16 '16 at 15:48
  • 2
    +1 for your "+25" -- if you're going to get serious with R and take advantage of all it has to offer, choose this answer. – jbnunn Jun 04 '16 at 15:25
  • 1
    If only there were a brew cask for this! – Dennis Sep 14 '16 at 09:22
  • what's it with gcc.. i think i ran into trouble trying to install Octave some time.. does't homebrew ever try to solve these issues – nyxee Jul 26 '17 at 04:59
  • I just installed r via brew with no occasion. – nyxee Jul 26 '17 at 05:31
  • Where is it after this? I'm trying to run R by typing "R" on the command line and it just tells me -bash: R: command not found – Sam Aug 08 '17 at 19:37
17

After following Matt Burns' answer, you can also install the R.app GUI via brew cask:

$ brew tap caskroom/cask
$ brew cask install r-app
$ open /Applications/R.app
Josh Bode
  • 271
  • 3
    Thanks. One thing, though: You might want to edit the last line in your script so that it reads brew linkapps r-gui instead of merely brew linkapps. – Steve S Aug 27 '15 at 18:45
  • this failed miserably for me. Ended up just following this tutorial on youtube https://www.youtube.com/watch?v=Tnhp65hxtZc – A Person Oct 03 '16 at 15:26
  • 1
    I get the following error, if I try to execute brew install r-gui: Error: No available formula with the name "r-gui". It was migrated from homebrew/science to caskroom/cask/r-app. You can access it again by running: "brew tap caskroom/cask".. –  Feb 26 '18 at 11:28
  • 1
    As of 2019/04/14: Jasons-MacBook-Pro:20190402_Tuesday_PM_captures harrison$ brew cask install r-app Error: Cask 'r-app' is unavailable: No Cask with this name exists. – Jason Harrison Apr 15 '19 at 04:08
6

You can download R for Mac OS X simply from here : http://cran.cnr.berkeley.edu

Hit the button : Download R for (Mac) OS X

Install the PKG file that came in the download.

This website might help to go ahead and download home-brew / install home brew as well.

https://github.com/Homebrew/homebrew/wiki/Installation

GummyArgyle
  • 3,101
2

I'm a fan of RStudio. It's an IDE that wraps R, makes visualization, organization, debugging, and other tasks much easier. Or, you can just use it as if it were a simple install of R. There's a Mac binary available from that website.

1

I stumbled onto this trying to install R in general and I ended up using MacPorts. If your using MacPorts, try

sudo port install R

Taken from http://johnlaudun.org/20140721-install-r-with-macports/

Chris Smith
  • 211
  • 2
  • 6
0

1.- http://cran.r-project.org/bin/macosx/ and download in Mac-GUI-1.62.tar.gz. 2.- INSTALL

You need R built and installed as a framework: see the 'R Installation and Administration Manual'. A CRAN binary install of R suffices.

Building R.app

Only Mac OS X 10.6 and higher are supported, and only 64-bit R. The project is called "R.xcodeproj" and requires Xcode 3.2 or higher.

The project can be built by selecting "R" target and "Build" inside the XCode GUI.

Supported configurations are: SnowLeopard64 (release, current OS X, default) Lion64 (release, OS X 10.7+, Xcode 4.5+) MLion64 (release, OS X 10.8+, Xcode 4.5+) Debug (with debugging output, current OS X)

The configurations differ mainly in the SDK selected (recent versions of Xcode only support the current and immediately previous SDKs, so for example in Mar 2013 the default would build for 10.8, but configuration Lion64 allows building for >= 10.7).

To build the project from the command line in the Mac-GUI directory use something like: xcodebuild -target R -configuration SnowLeopard64

To build the R for Mac OS X FAQ use either xcodebuild -target Docs or manually in docs folder makeinfo -D UseExternalXrefs --html --force --no-split RMacOSX-FAQ.texi

The resulting html FAQ file will be found in Mac-GUI/docs directory.

Note about binary compatibility:

The general rules for R apply, that is binary compatibility is given only if the major and minor version numbers match - only the patch level may differ. When using the X.Y.Z version form it means that X.Y must match. For example R-GUIs linked to 3.0.x and 3.1.x are NOT binary compatible.

The compiled R.app is usually bound to a specific version, such as 3.0.1. If you upgrade R removing the older version, let's say using R.app built for 3.0.0 and updating R to 3.0.1, you may need to fix the absolute path to libR.dylib. The nightly builds use a generic path /Library/Frameworks/R.framework/Resources/lib/libR.dylib which points to the latest version of R, but this is done by an additional call to install_name_tool in the building script. Release versions of the GUI use a fixed-version path as they come with a specific R version (in fact the default behavior doesn't depends on the GUI, but on libR.dylib - changing its own reference entry changes the way R.app is linked).

YoelMacia
  • 177
  • 1
  • 6