Install R

Introduction

This page presents a detailed guide about how to install R onto your computer — this is referred to as building a local development environment or LDE. Additional install R help was provided in Chapter 1.1 – A quick look at R and R Commander.

Instructions for RStudio are also provided (optional for BI311 students). A guide to install R Commander is provided in Install R Commander.

Instructions for how to run R via a “cloud computing” (serverless) option — a remote development environment — are also provided, Use R in the Cloud.

For help upgrading installed packages after upgrading new R version, see R packages.

Note: Installation guides quickly become outdated. This page was created first in September 2019 and last updated October 2024 and describes working installation protocols at that time. As of September 2024, R -4.4.1 was current version. Instructions for Win10 and Win11 are the same. Instructions for Intel-based macOS are the same; with Apple’s switch to ARM64 (M1, M2, M3), changes have been made. Going forward, the instructions on this page, but not my videos — version numbers need to be updated in the videos, are likely to be the same for new R versions. And wow! Search Google or Bing for “how to install R,” options in the millions. Ultimately the best source is in the R installation and administration manual.

Per usual caveat about this page of instructions: my advice is offered for instructional purposes and in no way implies warranty against damage or guarantee of success.

Run R on your computer (LDE install)

So why in this day in age should you install and build R on your own computer? The remote options to run R are a wonderful option, convenient: you can access anywhere you have internet, from any device that connects to the internet. It’s easy to share and work together on projects, particularly those based on Jupyter. I think the main benefits to a local installation is it’s a more efficient environment to work in — you have control of everything and, provided your PC has power, a working R install on your computer will always be available to you. Since you can control the update cycle for your computer, you won’t run into times you cannot access the remote server to work on your project. Testing code is faster on a local install, feedback — think error messages — apply to your installed version. And, while remote R servers may come with low initial costs to students, any significant use will quickly require paid accounts. As a reminder, the good folks at the R-project continue to offer R as free software. All you need to do is work through the install process.

  1. Windows PCs, download the base application from https://cran.r-project.org, select Download R for Windows, and install the R software as you would any other software. All of you are likely to have the 64-bit version of Windows 11, so install the 64-bit version of R. Follow the instructions as they are presented. Screenshots of the install process are available at the end of this page (click here or scroll down to Win11 setup, Screenshots).
    • Current versions of Microsoft Windows come in several flavors, the simplest distinction is between home and pro. R runs perfectly well on both.
      • Windows 10 is reaching end of life cycle.
      • Some inexpensive Microsoft Windows PCs are built on ARM64, not Intel or AMD64 CPU. Thus, installing R and or RStudio may prove problematic.
    • You should install R with Administrator privileges. Highlight the install file, right-click the file, and select “Run as administrator” from the popup menu.
    • When you first try to run R you may get a popup screen “Windows protected your PC,” locate and click on the “More info” link and select “Run anyway.”
      • This in no way will harm your computer — provided you have downloaded from official sites. R is a verified program. Microsoft has taken an aggressive line on developers and favors apps that are part of their app store.
      • It is advisable to confirm for yourself: check the md5sum against the fingerprint on the CRAN server
    • When prompted, I recommend that you change the install directory to root folder, e.g., C:\R\R-4.4.2. This will allow for installation of packages to the common library as opposed to a personal library.
      • I recommend this change because of how Windows assigns home folders. During initial setup Windows 10 prompted you to choose a username and whether you wanted your work stored locally or in your OneDrive folder. A worse case scenario? You select a user name with spaces, e.g.,”Mike Dohm,” and you selected OneDrive. Both will cause challenges later for running and or installing packages for R.
        • If you install R anywhere but the default Program files folder on your Win10/11 PC, chances are you will need to add the folder containing the executable, r.exe, to you path.
          • Search: “env”
          • Open “Edit the system environment variables” in the Control Panel
          • Click Advanced tab, then click on Environment Variables… button (lower right of panel)
          • Under System variables, scroll to and select Path.
          • Click Edit… button, then click New button.
          • Type in the path to the folder containing R.exe. That’s likely to be C:\R\R-4.4.2, assuming R-4.4.2 is the latest version of R installed on your computer.
      • I made a video for you. Video is about 26 minutes long; at 22 minute mark, video includes how to install R Commander (instructions provided Install R Commander).
        • Apologies for the production quality — videos are not my thing.


https://youtu.be/upjmBieh3bM

  1. macOS PCs, first you must download and install XQuartz from https://www.xquartz.org. Best to restart your mac after installing XQuartz then proceed to install R.
    After installing XQuartz, then return to https://cran.r-project.org, select Download for Mac(OS) X, and run the installer. Screenshots of the install process are available at the end of this page (click here or scroll down to Macos setup, Screenshots).

    • As of August 2021, be advised that there are two distinct R versions for your MacBook or iMac.
      • For MacBook or iMac with Apple’s M1 or M2 ARM chip sets, download and install R-4.2.2-arm64.pkg.
        • If you recently purchased a new MacBook or iMac (2020 to present), then you probably have the M2 or M3 chipset (check by clicking the Apple icon, then selecting About this Mac or System Information (/Applications/Utilities/System Information.app)).
        • XQuartz version 2.8.5 works on macs with either the M1 or Intel chipsets.
      • For older MacBook or iMacs with Intel processors, download R-4.4.1-x86_64.pkg.
      • Depreciated 8/4/2021: Be advised that these instructions are for Intel-based macs. At the time of writing these instructions (April 2021), the installation of XQuartz and R should work on new M1-based macs. At the time of this writing (April 2021), however, R will not run natively on your M1 mac. It will run using Rosetta 2, an emulator that is included with your M1 mac. The R folks are busy working on a version that will run natively, which may be ready within a few months.
    • At the completion of the install process, don’t forget to drag the R app to your Applications folder.
    • When you first try to run R, you may get a popup screen which provides no option to start the app, and perhaps even a rather ominous option to move the app to Trash. Just close the warning message and right-click on the R app. A new screen pops up, which looks very much like the previous warning, but now you will see and option to open the app. Click on open to start R.
    • Like the message to Windows PC users, bypassing Apple’s Gatekeeper to run R in no way will harm your computer — provided you have downloaded from official sites — R is a verified program. Apple has taken an aggressive line on developers and favors apps that are part of their app store.
  2. LINUX distros. If your PC platform is Linux, then you should be comfortable with installation and updating of software. R base is already included in Debian distributions (e.g., Mint, Ubuntu). See https://cloud.r-project.org/ for additional instructions.
    • For Chromebook users, if you can install a Linux subsystem, then you can also install and run R. For instructions to install R see Levi’s excellent writeup at levente.littvay.hu/chromebook/.

Note: To install up-to-date R and RStudio, your Chromebook needs to have Intel or AMD CPU; my ASUS Chromebook has an ARM64 processor (MediaTek mt8183), and Levi’s instructions don’t apply. As of January 2024 I am pushing the installation process a bit on my little Chromebook and have successfully created the Linux container (Debian 11, Bullseye) and installed base (and development) R version (4.0.4) included with the Linux distribution. Stay tuned — I’ll update progress with installing an R environment on ARM64-based Chromebook.

Test R

For both macOS and Windows PCs, successful installation of R on your computer installs base R programming language and a simple graphical user interface. Test your install by running code in the terminal (one line at a time) or via script:

  1. Rgui.exe (Windows PC)
  2. File → New script

Enter code in script editor, e.g.,

myX <- c(1,2,3,4)
myY <- c(5,10,15,20)
plot(myY,myX)
  1. Run code: Ctrl+R

basic R with script editor on Win 10 PC

Figure 1. Screenshot of RGui.exe (1), script editor (2), and results of plot() (3) on WinPC.

  1. R.app (macOS): run code in the terminal or via script
  2. File → New Document

Enter code in script editor, e.g.,

myX <- c(1,2,3,4)
myY <- c(5,10,15,20)
plot(myY,myX)
  1. Run code: Cmd+Enter

basic R with script editor on macOS

Figure 2. Screenshot of R.app (1), script editor (2), and results of plot() (3) on macOS.

Many of you would like a video. Do a little search and you’ll find plenty, although most are also showing how to install RStudio in addition to base R.

Note: For my Biostatistics class, BI311, we typically will run R and use R Commander for scripting, without RStudio.

For BI311, we also use R Commander package

R Commander is a package that adds function to R; it provides a familiar point-and-click interface to R, which allows the user to access functions via a drop-down menu system (Fox 2017).

Go to Install R Commander guide.

Run R from the terminal

Whether yours is a mac or win11 pc, you have a powerful computing environment lurking beneath the glossy graphic user interface. It’s called the terminal. The terminal is a place where text-based instructions may be written and submitted to command your computer to do something.

On win11 pc, the modern terminal is the Power Shell. Search “PowerShell,” then open Windows PowerShell. Alternatively, shortcut Win + X, then I key. This opens terminal in your home folder.

  • You’ll want to navigate to your working folder, e.g., BI311 on the Desktop. Setting your working folder can be done in R of course, but at the terminal type the command “cd \users\default\desktop\bi311”. Note — not case sensitive.

On macOS, Spotlight (search) “Terminal.app”. Alternatively, right-click on your working folder icon and select New terminal at Folder from the popup menu.

On Ubuntu Linux, shortcut keys window + alt + t.

Run R in the “Cloud”

If you do not wish to install R, or, if you have a Chromebook and, therefore cannot gracefully install R, then there are alternatives; Run R in the Cloud. I’ll list three ways to run R in the cloud for free. Go to Use R in the Cloud guide.


MacOS setup, Screenshots

Download R install package from R-project.org, then select the R install package from your Download folder

First screen, R install for macOS. Select continue

Second screen, R install on macOS. Select continue

Third screen, R install on macOS. Select continue

Fourth screen, R install on macOS. Agree to continue.

Fifth screen, R install on macOS. Select Install

Sixth screen, R install on macOS. Enter your username and password for your computer, then select Install Software.

Seventh screen, R install on macOS. Several screens will popup, reporting progress.

Eighth and final screen, R install on macOS. Select close

Optional — Keep or discard the install file. I keep and then do manual delete after I’ve confirmed the installation.

From Applications folder, start r.app. You should see the R Console.


Wind10/11 setup, screenshots

Download from R-project.org, then right-click the R install package from your Download folder. Run as administrator

First screen, select language. Select OK to continue

Third screen, click Next to continue

Fourth screen. Change the default location (show in the screenshot) to root folder, e.g., C:\R\R-4.1.1 (current version)

Fifth screen. Change startup options. Select Yes (customized startup) to continue.

Sixth screen, select SDI, then Next to continue

Seventh screen, select HTML help, then Next to continue

Eighth screen, leave start menu folder as is (R), then Next to continue

Ninth screen, check all boxes, then Next to continue

Tenth screen, a series of status updates during the installation.

Final scree, successful install.