1 Easy installation

1.1 Windows

NOTE: See Windows installation instructions for more detail.

It may be necessary to do the following steps with an “Administrator” account.

To install R, visit the Windows base distribution page. Click on the Download R-3.3.2 for Windows link. Click on the installer and make the default selection for each option.

To install RStudio, visit the RStudio download page. Click on the RStudio 1.0.136 - Windows Vista/7/8/10 link. Click on the installer and follow default instructions.

Be sure to switch back to your regular account before starting to use the software that you have just installed.

1.2 Mac

NOTE: See R for Mac OS X for more detail.

To install R, visit the R for Mac OS X. Click on the the R-3.3.2.pkg link. Click on the installer and follow default instructions.

To install RStudio, visit the RStudio download page. Click on the RStudio 1.0.136 - Mac OS X 10.6+ (64-bit) link. Click on the installer and follow default instructions.

1.3 Linux

NOTE: See distribution-specific instructions for additional detail.

On debian-based systems, the easiest way to install R is through a package manager manager, run under an administrator account. On Linux one usually needs to install R packages from source, and R package source often contains C, C++, or Fortran code requiring a compiler and -dev versions of various system libraries. It is therefore convenient to install the -dev version of R.

sudo apt-get install r-base r-base-dev

When installing source packages, it may be necessary to have access to the -dev version of various system libraries. Many of these are installed as dependencies of r-base-dev; other common examples include the xml and curl libraries

sudo apt-get install libxml2-dev
sudo apt-get install libcurl-dev

Note in particular the use specification of libraries (the lib prefix) and the use of the -dev version.

To install RStudio, visit the RStudio download page. Download the appropriate archive by clicking on the RStudio 1.0.136 - link for your OS. On Ubuntu, install the .deb installer with

sudo dpkg -i rstudio-1.0.136-amd64.deb

2 Advanced Installation (NOT required for this course)

Advanced installation is required to (a) install custom packages that (b) have their own C, C++, or Fortran code. In all other cases, the easy installation is sufficient.

2.1 Windows (NOT required for this course)

Advanced installation requires Rtools34.exe, available the Rtools web site. Download and click on the installer. Answer all installer questions with default values. The two most tricky parts are:

  1. Be sure to install the Rtools softare in a directory path that does not include spaces.
  2. Be sure that the system enironment variable PATH contains the path to the Rtools bin directory.

2.2 Mac (NOT required for this course)

2.2.1 Install Xcode and Xcode command line tools

Make sure you have Xcode and Xcode command line tools installed on your mac. If not, you can run the following command on your terminal application to install Code

xcode-select --install

For command line tools, go to and sign in with your Apple ID (the same one you use for iTunes and app purchases). Look for ‘Command line tools’ through the search box, download the required file and install via the .dmg file on your machine.

For more detailed instructions on this, please visit this link.

2.2.2 Install of R and RStudio using homebrew (easy!)

Open your terminal application on your mac. Follow the steps below:

  • Install homebrew on your machine, copy and paste this in your terminal.
/usr/bin/ruby -e "$(curl -fsSL"
  • Update the “taps” on your machine and check if everything is fine.
brew update && brew doctor
  • Get brew cask and the homebrew science taps
# Brew taps and requirements
brew tap caskroom/cask
brew tap homebrew/science
brew install caskroom/cask/brew-cask
  • Install Xquartz and Java
# Dependencies
brew cask install xquartz
brew cask install java
  • Finally install R and Rstudio
# Install R with X11
brew install --with-x11 r

# Install RStudio
brew cask install --appdir=/Applications rstudio

Note: the inclusion of the --appdir option. By default, Cask formula’s will create aliases in ~/Applications, but this option tells Homebrew to use /Applications instead

  • For more functionality with making documents with code embedded within it (literate programming),you have to install LaTeX on your machine as well.
# For latex:
brew cask install mactex

brew install libsvg curl libxml2 gdal geos boost

R CMD javareconf JAVA_CPPFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers

2.2.3 Advanced R installation i.e compile from source

This step is not recommended for new users and it would be much easier installing R using homebrew.

We assume that the users have the following software installed,

  1. XCode and Xcode command line tools.
  2. gfortran, pcre, and liblzma
  3. XQuartz (
  4. Java JRE (jre-8u111-macosx-x64)
  • If gfortran, pcre or liblzma is not installed on your machine, you can follow the steps below. These steps help you install binaries of these programs without having to compile them from scratch.

One thing to keep in mind is the version of OSX being run, i.e take note of the binaries you download from Most people should be having OS-X Snow leopard or higher.

darwin_id Mac OS version
darwin8 for Mac OS X 10.4 (Tiger) or higher
darwin89 32-bit for Mac OS X 10.4 or higher, 64-bit for Mac OS X 10.5 or higher
darwin9 for Mac OS X 10.5 (Leopard) or higher
darwin10 for Mac OS X 10.6 (Snow Leopard) or higher
darwin13 for Mac OS X 10.9 (Mavericks) or higher
#  This is for mac OS sierra

##  Gfortran
curl -O ''
sudo tar fxvz gfortran-4.8.2-darwin13.tar.bz2 -C /

## XZ library or liblzma
curl -O ''
sudo tar fvxz xz-5.2.1-darwin.13-x86_64.tar.gz -C /

## pcre

curl -O ''
sudo tar fvxz pcre-8.36-darwin.13-x86_64.tar.gz -C /
  • The next step is to download R from its source, by checkout from its svn repository.
# I'm making a new directory in my home called "R-stuff"
mkdir ~/R-stuff

# SVN checkouto R-devel or a specific version of R. The rest of this document
# will show the workflow for devel version of R. But the steps are the same for
# the release version as well.

svn checkout ~/R-stuff/devel

# or both. (if you want to have devel and release versions of R on your machine)

svn checkout ~/R-stuff/release-3-3
  • Download recommended packages for R, this is available after you change into your devel or release-3-3 directory.
# Download recommmended packages
  • Be sure to configure R in a different directory as to where it was downloaded. All the libraries being installed will go into that directory.
# make a new directory to configure R

mkdir -p ~/R-stuff/bin/R-devel

cd ~/R-stuff/bin/R-devel

~/R-stuff/devel/configure --enable-R-shlib --enable-R-profiling --enable-memory-profiling --with-internal-tzcode=no
  • Once the configuration goes through without any errors, run make
# run make

# Then check the built system works correctly by
make check
  • Install R-studio from this link.

Once R-studio is installed, and you have manually compiled R, you have to create an alias for your R-studio in your .bashrc or whatever shell you are using on your machine.

The alias will look like,

# R release version; i.e latest release branch, use absolute paths
# when making aliases. This makes it accessible by just using R in the
# terminal.
alias R="/Users/hansolo/R-stuff/bin/R-devel/bin/R"

# This tells Rstudio which R to use as default
export RSTUDIO_WHICH_R=/Users/hansolo/R-stuff/bin/R-devel/bin/R;
  • If you have multiple versions of R installed on your machine via source compilation, one way to refer to multiple version of R and Rstudio via aliases is given below.

In your .bashrc you can have something like:

# R release/patched version; i.e latest release branch
alias R-release="/Users/hansolo/R-stuff/bin/R-3-3-branch/bin/R"
alias RStudio-release="export RSTUDIO_WHICH_R=/Users/hansolo/R-stuff/bin/R-3-3-branch/bin/R; open -a RStudio"

# R devel setup
alias R-dev="/Users/hansolo/R-stuff/bin/R-devel/bin/R"
alias RStudio-dev="export RSTUDIO_WHICH_R=/Users/hansolo/R-Stuff/bin/R-devel/bin/R; open -a RStudio"

Now you can call your R-release version using the command R-release and if you use the command RStudio-release , Rstudio will use the release version of R. Same goes with the commands R-dev and RStudio-dev.

All done!!

Try out the installation in a new terminal or after sourcing your .bashrc by

source ~/.bashrc

You should be all set and ready to use R!

2.3 Linux (NOT required for this course)

NOTE: see distribution-specific instructions and the R Installation and Administration manual for definitive directions.

For advanced Linux installation, a typical approach is ‘checkout’ the R source code from its SVN version control repository and retrieve recommended packages.

mkdir ~/src
cd ~/src
svn checkout

The next step is to configure the software, typically in an indepenent ‘bin’ directory

mkdir ~/bin
cd ~/bin/R-3-3-branch

There are a number of configure options, see ~/src/R-3-3-branch/configure. Typical problems during configuration involve missing system libraries; the -dev versions of these libraries need to be installed by a system administrator.

The final step is to build the software

cd ~/bin/R-3-3-branch
make -j

The executable is at ~/bin/R-3-3-branch/bin/R; it is convenient to add ~/bin/R-3-3-branch/bin to the system PATH variable or to create a shell alias pointing to the executable. A system-wide installation can be made available with

sudo make install