Install R and RStudio
To start writing R programs, you need two things on your computer: R itself (the engine that runs your code) and RStudio (the editor where you write and manage your code). Think of R as the car engine and RStudio as the dashboard and steering wheel — you need both to drive.
Understanding the Difference
┌──────────────────────────────────────────────┐ │ RStudio │ │ (Interface: where you type your code) │ │ │ │ ┌──────────────────────────────────┐ │ │ │ R Engine │ │ │ │ (Does the actual computation) │ │ │ └──────────────────────────────────┘ │ └──────────────────────────────────────────────┘
R is the core language. RStudio is the tool that makes working with R comfortable and productive.
Step 1: Install R
For Windows
- Open your web browser and go to cran.r-project.org
- Click "Download R for Windows"
- Click "base"
- Click the download link at the top (for example: Download R 4.x.x for Windows)
- Open the downloaded .exe file
- Follow the installer — click Next on each screen and keep the default settings
- Click Finish when done
For Mac
- Go to cran.r-project.org
- Click "Download R for macOS"
- Download the .pkg file matching your Mac (Apple Silicon or Intel)
- Open the file and follow the installation steps
For Linux (Ubuntu/Debian)
Open your terminal and run these commands one at a time:
sudo apt update sudo apt install r-base
Step 2: Install RStudio
RStudio is made by a company called Posit. The free version is called RStudio Desktop.
- Go to posit.co/download/rstudio-desktop
- Click Download RStudio Desktop (the free version)
- Download the file for your operating system
- Run the installer and follow the steps
Step 3: Verify the Installation
Open RStudio. You will see a large panel on the left side called the Console. Click inside it and type:
print("Hello, R!")
Press Enter. If R is installed correctly, the console will display:
[1] "Hello, R!"
This confirms both R and RStudio are working together properly.
Understanding CRAN and Packages
When you install R, you get the base language. Extra tools called packages extend what R can do. You download packages from CRAN. To install a package, type this in the console:
install.packages("ggplot2")
You only install a package once. Each time you start a new R session and want to use it, you load it with:
library(ggplot2)
What Gets Installed With R
R Installation Contents ───────────────────────────────────────── Base R → Core functions and math Recommended Pkg → datasets, stats, graphics R GUI → Simple built-in editor Help System → Built-in documentation
RStudio sits on top of all this and gives you a much better experience than the basic R GUI.
Keeping R and RStudio Updated
Both R and RStudio release new versions regularly. Updating R requires downloading and installing a new version from CRAN. RStudio checks for updates automatically — go to Help → Check for Updates inside RStudio to see if a newer version is available.
For beginners, staying one or two versions behind the latest release is perfectly fine. Focus on learning the language first.
Common Installation Problems and Fixes
Problem: RStudio says "R not found"
This means RStudio cannot locate R on your computer. Make sure you installed R before installing RStudio. If R is already installed, try restarting your computer and opening RStudio again.
Problem: Package install fails
Some packages need extra software called Rtools (Windows) or Xcode (Mac). RStudio will usually prompt you to install these. Follow the on-screen instructions.
Problem: "Permission denied" on Linux
Use sudo before your install commands, or install packages to your personal library folder using install.packages("name", lib="~/R/library").
A Note on R Online
If you cannot install software on your computer, use RStudio Cloud (now called Posit Cloud) at posit.cloud. This runs R and RStudio directly in your web browser. It is free for basic use and requires no installation at all.
Once installation is complete, you are ready to explore the RStudio interface and write your first R program.
