To use R, you must first install it on your computer. This recipe gives detailed instructions on how to download and install R.
Downloading and installing R
Getting ready
If you are new to the R language, you can find a detailed introduction, language history, and functionality on the official website (http://www.r-project.org/). When you are ready to download and install R, please access the following link: http://cran.r-project.org/.
How to do it...
Please perform the following steps to download and install R for Windows and macOS:
- Go to the R CRAN website, http://www.r-project.org/, and click on the download R link, that is, http://cran.r-project.org/mirrors.html):
- You may select the mirror location closest to you:
- Select the correct download link based on your operating system:
As the installation of R differs for Windows and macOS, the steps required to install R for each OS are provided here.
For Windows:
- Click on Download R for Windows, as shown in the following screenshot, and then click on base:
- Click on Download R 3.x.x for Windows:
- The installation file should be downloaded. Once the download is finished, you can double-click on the installation file and begin installing R, It will ask for you selecting setup language:
- The next screen will be an installation screen; click on Next on all screens to complete the installation. Once installed, you can see the shortcut icon on the desktop:
- Double-click on the icon and it will open the R Console:
For macOS X:
- Go to Download R for (Mac) OS X, as shown in the following screenshot.
- Click on the latest version (R-3.4.1.pkg file extension) according to your macOS version:
- Double-click on the downloaded installation file (.pkg extension) and begin to install R. Leave all the installation options as the default settings if you do not want to make any changes:
- Follow the onscreen instructions through Introduction, Read Me, License, Destination Select, Installation Type, Installation, and Summary, and click on Continue to complete the installation.
- After the file is installed, you can use spotlight search or go to the Applications folder to find R:
- Click on R to open R Console:
As an alternative to downloading a Mac .pkg file to install R, Mac users can also install R using Homebrew:
- Download XQuartz-2.X.X.dmg from https://xquartz.macosforge.org/landing/.
- Double-click on the .dmg file to mount it.
- Update brew with the following command line:
$ brew update
- Clone the repository and symlink all its formulae to homebrew/science:
$ brew tap homebrew/science
- Install gfortran:
$ brew install gfortran
- Install R:
$ brew install R
For Linux users, there are precompiled binaries for Debian, RedHat, SUSE, and Ubuntu. Alternatively, you can install R from a source code. Besides downloading precompiled binaries, you can install R for Linux through a package manager. Here are the installation steps for CentOS and Ubuntu.
Downloading and installing R on Ubuntu:
- Add the entry to the /etc/apt/sources.list file replace <> with appropriate value:
$ sudo sh -c "echo 'deb http:// <cran mirros site
url>/bin/linux/ubuntu <ubuntu version>/' >> /etc/apt/sources.list"
- Then, update the repository:
$ sudo apt-get update
- Install R with the following command:
$ sudo apt-get install r-base
- Start R in the command line:
$ R
Downloading and installing R on CentOS 5:
- Get the rpm CentOS 5 RHEL EPEL repository of CentOS 5:
$ wget
http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-
4.noarch.rpm
- Install the CentOS 5 RHEL EPEL repository:
$ sudo rpm -Uvh epel-release-5-4.noarch.rpm
- Update the installed packages:
$ sudo yum update
- Install R through the repository:
$ sudo yum install R
- Start R in the command line:
$ R
Downloading and installing R on CentOS 6:
- Get the rpm CentOS 5 RHEL EPEL repository of CentOS 6:
$ wget
http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-
8.noarch.rpm
- Install the CentOS 5 RHEL EPEL repository:
$ sudo rpm -Uvh epel-release-6-8.noarch.rpm
- Update the installed packages:
$ sudo yum update
- Install R through the repository:
$ sudo yum install R
- Start R in the command line:
$ R
Downloading and installing R on Fedora [Latest Version]:
$ dnf install R
This will install R and all its dependencies.
How it works...
CRAN provides precompiled binaries for Linux, macOS X, and Windows. For macOS and Windows users, the installation procedures are straightforward. You can generally follow onscreen instructions to complete the installation. For Linux users, you can use the package manager provided for each platform to install R or build R from the source code.
See also
- For those planning to build R from the source code, refer to R Installation and Administration (http://cran.r-project.org/doc/manuals/R-admin.html), which illustrates how to install R on a variety of platforms