Installing R and RStudio
A Step-by-Step Guide for Windows, Linux, and macOS
1 Introduction
R is a free, open-source programming language specifically designed for statistical computing, data analysis, and data visualization. It is used worldwide to analyze data, build predictive models, and create compelling visualizations that inform decisions in business, government, and beyond.
RStudio is a free, beginner-friendly application that makes working with R much easier. It provides a clean, organized interface with panels for writing code, viewing results, managing files, and exploring plots all in one place.
You must install R first, then RStudio. RStudio is not R itself, it is a tool that uses R. Without R installed, RStudio will not work.
Why use R?
- Purpose-built for statistics and data analysis
- Thousands of free add on packages (via CRAN) for any analytical task
- Produces publication quality charts and graphics
- Free and open source no licence fees
- Huge community with extensive free learning resources
2 System Requirements
Before installing, make sure your system meets the minimum requirements:
| Requirement | Minimum |
|---|---|
| Operating System | Windows 10+, macOS 11+, Linux (Ubuntu 20.04+ / Fedora 36+) |
| Architecture | 64-bit (x86_64 or ARM64) |
| Disk Space | ~500 MB for R + ~600 MB for RStudio |
| RAM | 2 GB (4 GB+ recommended) |
3 Downloading R and RStudio
3.1 Where to Download R
R is hosted by CRAN (the Comprehensive R Archive Network):
3.2 Where to Download RStudio
RStudio Desktop is available from Posit (the company behind RStudio):
Both R and RStudio are completely free. Always download from the official websites above to ensure you get safe, latest versions.
4 Installation on Windows
4.1 Part 1. Installing R
4.1.1 Download R
- Go to https://cran.r-project.org
- Click “Download R for Windows”
- Click “base”
- Click the download link at the top (e.g.,
Download R-4.x.x for Windows)
4.1.2 Run the Installer
- Locate the downloaded
.exefile (e.g.,R-4.x.x-win.exe) - Double-click to launch the Setup Wizard
- If prompted by Windows security, click Yes to allow the installer to run
4.1.3 Choose Language and Accept License
- Select your preferred language and click OK
- Click Next to accept the GNU General Public License
4.1.4 Choose Install Location
- The default path is usually
C:\Program Files\R\R-4.x.x - It is recommended to keep the default path
- Click Next
4.1.5 Select Components
- Leave all default components checked
- Click Next
4.1.6 Startup Options and Registry Entries
- Leave the default startup options as they are
- Click Next through the remaining screens
- Click Install
4.1.7 Finish R Installation
- Click Finish when the installation completes
4.2 Part 2. Installing RStudio
4.2.1 Download RStudio
- Go to https://posit.co/download/rstudio-desktop/
- Click “Download RStudio Desktop for Windows”
- The correct installer for your system will be detected automatically
4.2.2 Run the Installer
- Open the downloaded
.exefile (e.g.,RStudio-2024.x.x-xxx.exe) - Click Next to begin
- Choose the install location (default is recommended) and click Next
- Click Install
- Click Finish when done
4.2.3 Launch RStudio
- Open RStudio from the Start Menu or the Desktop shortcut
- RStudio will automatically detect your R installation
4.2.4 Verify the Installation
In the Console panel (bottom left), type the following and press Enter:
R.version.stringYou should see something like:
[1] "R version 4.x.x (YYYY-MM-DD)"
5 Installation on macOS
5.1 Part 1. Installing R
5.1.1 Download R
- Go to https://cran.r-project.org
- Click “Download R for macOS”
- Choose the correct installer for your Mac:
- Apple Silicon (M1/M2/M3/M4) → download the
arm64.pkgfile - Intel Mac → download the
x86_64.pkgfile
- Apple Silicon (M1/M2/M3/M4) → download the
Click the Apple menu→ About This Mac. If you see “Apple M1” (or M2, M3, etc.) under Chip, choose the Apple Silicon version. If you see “Intel Core”, choose the Intel version.
5.1.2 Install R
- Open the downloaded
.pkgfile - Follow the on-screen instructions — click Continue, Agree, and Install
- Enter your macOS password if prompted
- Click Close when complete
5.2 Part 2. Installing RStudio
5.2.1 Download RStudio
- Go to https://posit.co/download/rstudio-desktop/
- Click “Download RStudio Desktop for macOS”
5.2.2 Install RStudio
- Open the downloaded
.dmgfile - Drag the RStudio icon into your Applications folder
- Eject the disk image
5.2.3 Launch RStudio
- Open Finder → Applications → RStudio
- On first launch, macOS may warn you that the app was downloaded from the internet — click Open to proceed
5.2.4 Verify the Installation
In the RStudio Console panel, run:
R.version.stringOutput:
[1] "R version 4.x.x (YYYY-MM-DD)"
5.2.5 Optional: Install Xcode Command Line Tools
Some R packages require compiling from source on macOS. Install the Xcode tools to avoid errors later:
xcode-select --installRun this in the macOS Terminal app (not in RStudio).
6 Installation on Linux
Linux users typically install R through their distribution’s package manager. The steps below cover Ubuntu/Debian and Fedora/RHEL — the two most common distributions.
6.1 Part 1. Installing R
6.1.1 Ubuntu / Debian
# Step 1 — Update your package list
sudo apt update
# Step 2 — Install R base
sudo apt install -y r-base
# Step 3 — Verify the installation
R --versionFor the latest version of R on Ubuntu (recommended), add the official CRAN repository:
# Install prerequisites
sudo apt install -y software-properties-common dirmngr
# Add the CRAN signing key
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc \
| sudo tee /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# Add the CRAN repository (adjust 'jammy' to your Ubuntu version)
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
# Update and install
sudo apt update
sudo apt install -y r-base r-base-dev6.1.2 Fedora / RHEL / CentOS
# Install R
sudo dnf install -y R
# Verify
R --version6.2 Part 2. Installing RStudio on Linux
6.2.1 Download RStudio
- Go to https://posit.co/download/rstudio-desktop/
- Scroll down to find the Linux installer
- Choose the correct version for your distribution:
.debfor Ubuntu / Debian.rpmfor Fedora / RHEL
6.2.2 Install the Package
Ubuntu / Debian:
# Navigate to your Downloads folder
cd ~/Downloads
# Install the .deb package (replace filename with actual version)
sudo dpkg -i rstudio-2024.xx.x-xxx-amd64.deb
# Fix any missing dependencies
sudo apt --fix-broken installFedora / RHEL:
# Navigate to your Downloads folder
cd ~/Downloads
# Install the .rpm package
sudo rpm -i rstudio-2024.xx.x-xxx.x86_64.rpm6.2.3 Launch RStudio
rstudioOr find RStudio in your application launcher / activities menu.
6.2.4 Verify the Installation
In the RStudio Console, run:
R.version.string7 Touring the RStudio Interface
When you first open RStudio, you will see four panels. Understanding them will make your work much more efficient.
| Panel | Location | Purpose |
|---|---|---|
| Main menu | 1 | complete set of options available in the RStudio IDE. |
| Toolbar | 2 | contains buttons for commonly used commands in RStudio. |
| Source Editor | Top left (3) | Write and save R scripts (.R files) |
| Environment / History / Connections | Top right (4) | View stored variables and command history
|
| Console | Bottom left (5) | Run code interactively and see immediate output |
| Files, Plots, Packages, Help, Viewer | Bottom right (6) | Browse files, view charts, read package documentation
|
Click in the Console panel, type 2 + 2, and press Enter. You should see [1] 4. If you do, everything is working perfectly.
8 Post-Installation Setup
8.1 Update R Packages
After installation, update all default packages to their latest versions:
update.packages(ask = FALSE)8.2 Install Your First Package
R packages are installed from CRAN using install.packages(). Let’s install the tidyverse, a popular collection of data science packages:
install.packages("tidyverse")The first time you install a package, R may ask you to choose a CRAN mirror, simply select one close to your location for faster downloads.
After installation, load a package with library():
library(tidyverse)8.3 Set a Default CRAN Mirror (Optional)
To avoid being asked to choose a mirror every time, set a default in your .Rprofile:
# Run this once in the Console
options(repos = c(CRAN = "https://cloud.r-project.org"))8.4 Create Your First R Script
- In RStudio, go to File → New File → R Script
- Type the following in the editor:
# My first R script
name <- "Mugisha"
age <- 23
cat("Hello, my name is", name, "and I am", age, "years old.\n")- Click Run (or press
Ctrl + Enter/Cmd + Enteron Mac) to run the selected line
8.5 Useful RStudio Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + Enter (Win/Linux) / Cmd + Enter (Mac) |
Run selected line or selection |
Ctrl + Shift + Enter |
Run the entire script |
Alt + - |
Insert the assignment operator <- |
Ctrl + Shift + C |
Comment / uncomment selected lines |
Tab |
Autocomplete code |
Ctrl + S |
Save the current script |
9 Troubleshooting
9.1 RStudio Cannot Find R
If RStudio opens but says it cannot find R:
- Go to Tools → Global Options → General → Basic
- Under R version, click Change and manually point to your R installation
- Windows:
C:\Program Files\R\R-4.x.x\bin\R.exe - macOS:
/Library/Frameworks/R.framework/Resources - Linux:
/usr/bin/R
- Windows:
9.2 Package Installation Fails on Linux
Install system-level build tools first:
# Ubuntu / Debian
sudo apt install -y build-essential libcurl4-openssl-dev libssl-dev libxml2-dev
# Fedora
sudo dnf install -y gcc gcc-c++ libcurl-devel openssl-devel libxml2-develThen retry the package installation in R.
9.3 “There is a binary version available” Warning
When installing packages, R may ask:
Do you want to install from sources the package which needs compilation? (Yes/no/cancel)
Type no (or n) to install the pre-built binary version, it is faster and does not require a compiler.
9.4 Updating R on Windows
Use the installr package to update R from within RStudio:
install.packages("installr")
installr::updateR()9.5 Updating R on macOS
Download and install the new .pkg from https://cran.r-project.org it will replace the old version automatically.
10 Uninstalling R and RStudio
10.1 Windows
- Open Control Panel → Programs → Uninstall a Program
- Uninstall RStudio first, then R for Windows
To also remove all installed packages, delete the personal library folder:
C:\Users\<YourName>\AppData\Local\R\win-library\
10.2 macOS
# Remove RStudio
rm -rf /Applications/RStudio.app
# Remove R framework
sudo rm -rf /Library/Frameworks/R.framework
# Remove R-related files
sudo rm -rf /usr/local/bin/R /usr/local/bin/Rscript
rm -rf ~/Library/R10.3 Linux
# Ubuntu / Debian
sudo apt remove r-base r-base-dev rstudio
# Fedora
sudo dnf remove R rstudio11 Next Steps
Summary
| OS | R Installer | RStudio Installer | Key Tip |
|---|---|---|---|
| Windows | .exe wizard |
.exe wizard |
Install R before RStudio |
| macOS | .pkg wizard |
.dmg drag-to-Applications |
Match chip type (Apple Silicon vs Intel) |
| Linux | Package manager (apt / dnf) |
.deb or .rpm package |
Install r-base-dev for compiling packages |
You now have R and RStudio installed and ready to use!
Open RStudio, type 2 + 2 in the Console, and begin your data science journey.
Recommended Next Steps
| Resource | Link |
|---|---|
| Getting Started with R | Your First Steps in R |
| Posit Community Forum | Posit Community |
| More from Prosper | Prosper |
Happy coding!