Install R and RStudio — Windows, Mac and Linux, the ME1 packages and your first script in 15 minutes (and the day RStudio could not find R)
For the Statistical Methods I labs you need two programs that are not the same thing: R, which does the maths, and RStudio, which is where you write and look at the results.
I installed them the wrong way round. I saw «RStudio» in the first lab handout, downloaded it, opened it… and got a window saying it could not find R. I thought the download was broken and repeated it twice before understanding that RStudio does not bring R inside: it is only the workshop, and the engine has to be installed separately. In the right order it takes a quarter of an hour.
In this guide we install both on Windows, Mac or Linux, set up the R packages used in ME1, check that everything works with a test script and go over the typical problems. All the RStudio screenshots are from my laptop, on Windows and with the interface in English.
Table of Contents
R and RStudio: the engine and the workshop
Before downloading anything it is worth being clear about the difference, because it explains almost every installation problem:
- R is the language and the program that does the calculations: the means, the distributions, the plots. It can be used on its own, from its own console, but it is rather uncomfortable.
- RStudio is a working environment (an IDE) that sits in front of R: an editor for your scripts, the console, the variables pane, the plots, the help… When you run something in RStudio, R is the one computing it.
That is why RStudio without R does not work (my case), and why you install R first and RStudio second. If you already have both and only need the ME1 packages, jump to step 4.
If you cannot install anything today (you are on a library computer, or on your phone), the site’s R playground runs R in the browser. It is fine for learning and trying code, but to hand in labs you will need RStudio on your computer.
Before you start: what you need
- A computer with Windows, macOS or Linux. R and RStudio are free and open source.
- About 1.5 GB free on the disk (between R, RStudio and the packages).
- Administrator rights to install programs (on your own laptop, you have them).
- An internet connection, also for the packages in step 4.
Step 1 — Install R
R is downloaded from CRAN, R’s official website: cran.r-project.org. On the front page you have three links, one per system.
On Windows
- Go to cran.r-project.org and click Download R for Windows and then base (or directly install R for the first time).
- Click the big link Download R-4.6.2 for Windows. The number changes with every version: when you read this it may be another one, and it works just the same.

- Open the downloaded
.exeand accept all the defaults: language, folder (C:\Program Files\R\R-4.6.2) and components. There is nothing to change.
In my RStudio screenshots you will see R 4.5.1, the version I had installed. If you install now, you will have a 4.6.x. For ME1 it makes no difference, except for one detail: when you move to a new «major» version (from 4.5 to 4.6), packages are installed again.
On macOS
- On CRAN, click Download R for macOS.
- Choose the
.pkginstaller for your processor: arm64 if your Mac is one of the new ones (M1, M2, M3… chip) and x86_64 if it is an Intel Mac. If you do not know, check the Apple menu > About This Mac. - Open the
.pkgand follow the wizard with the default options.
On Linux
On Ubuntu and Debian, the quickest way is the package manager:
sudo apt update sudo apt install r-base
On Fedora, sudo dnf install R. Your distribution’s version may lag a little behind the latest; for ME1 it does not matter, but if you want the newest one, CRAN’s Linux page (Download R for Linux) has the instructions to add its repository.
Step 2 — Install RStudio
RStudio is made by the company Posit. The free download is at posit.co/download/rstudio-desktop, which takes you to the downloads page of its documentation:

- The page detects your system and recommends an installer. On Windows, click Download installer (the
.exefile). On a Mac it is a.dmg, and on Linux, a.deb(Ubuntu and Debian) or an.rpm(Fedora and Red Hat). - Install it with the default options. On a Mac, drag RStudio into the Applications folder. On Ubuntu,
sudo apt install ./RStudio-*.debfrom the downloads folder. - Open it. If R is installed, RStudio finds it on its own.
Installing RStudio before R (what I did). RStudio starts, cannot find R and warns you. Install R and open RStudio again. If it still cannot see it, Tools > Global Options > General shows the R version it uses, with a Change… button to choose it by hand.
Step 3 — The first start
The first time, RStudio opens like this: the console on the left, with R’s welcome message and its version, and on the right the Environment pane (empty, there are no variables yet) and Files.

Type this in the console and press Enter:
R.version.string 1 + 1
Output:
[1] "R version 4.6.0 (2026-04-24)" [1] 2
If R answers with its version and with [1] 2, R and RStudio are talking to each other. The version you see will be the one you installed (here it is the one in the site’s R playground, which is 4.6.0).
The fourth pane is missing, the script editor, which appears as soon as you open or create a file: File > New File > R Script (or Ctrl + Shift + N). The guide How to use RStudio covers the four panes in detail.
Step 4 — The ME1 packages
R comes with all the basic statistics built in. What it does not bring comes in packages, downloaded from CRAN. They work in two steps, and it is worth understanding them before installing anything:
install.packages("name")downloads the package and stores it on your computer. You do it once (and again if you move to a new version of R).library(name)loads it into the session so you can use its functions. You do it in every script that needs it, usually at the top.
These are the packages used in ME1 to work with distributions and fit models to data. MASS already comes with R; the rest are installed in one go with this line in the console:
install.packages(c("fitdistrplus", "TeachingDemos", "UsingR", "extraDistr", "rootSolve"))
The first time, RStudio may ask you which server to download from (CRAN mirror): any will do, the first on the list is fine. You will see red messages scroll by while it downloads; as long as they do not say Error, they are just information.
You can also do it with the mouse, in Tools > Install Packages…: type the names separated by commas and click Install. Leave the Install dependencies box ticked, so that it also installs the packages they depend on.

If on Windows it asks Do you want to install from sources the packages which need compilation?, answer No. That way it installs the already compiled version, which works the same and needs no extra tools.
If in class you are asked to read Excel files with the xlsx package, bear in mind it needs Java installed on the computer. The readxl package reads the same files without Java (with read_excel()), and it is what I recommend if your lecturer does not require the other one.
Check what you are missing
To find out whether everything is there, this script goes through the list of ME1 packages and tells you which ones you have. Create it with Ctrl + Shift + N, paste it, save it as check-packages.R and run it all (select everything with Ctrl + A and press Ctrl + Enter):
# Is the laptop ready for the ME1 exam? (SergioLearns)
R.version.string
packages <- c("MASS", "fitdistrplus", "TeachingDemos", "UsingR", "extraDistr", "rootSolve")
installed <- packages %in% rownames(installed.packages())
data.frame(package = packages, installed = installed)
getwd()
This is how it looked on my laptop the first time I ran it (my script is the Spanish version, so the names are in Spanish: paquetes are the packages and instalados the installed ones):

installed.packages() is the list of what you have installed, and %in% checks, for each name on the list, whether it is in there (if vectors and %in% are all Greek to you, they are explained in R from scratch). Wherever you see FALSE, install that package and run the script again. The last line, getwd(), tells you the folder R is working in, which is where it will look for your data files.
Step 5 — Your first script
To finish, a real script with what you will do in the labs: some data, a summary and a plot. Create a new script, paste this and save it as marks-ME1.R:
# RStudio inside out: a test script (SergioLearns)
marks <- c(4.5, 7, 8.25, 5, 6.5, 9, 3.75, 7.5)
group <- c("A", "A", "B", "A", "B", "B", "A", "B")
dat <- data.frame(mark = marks, group = group)
average <- mean(marks)
std_dev <- sd(marks)
summary(marks)
tapply(dat$mark, dat$group, mean)
hist(marks, breaks = 0:10, col = "#A99EF5", border = "white",
main = "Exam marks", xlab = "Mark", ylab = "Students")
abline(v = average, col = "#FF6B4A", lwd = 3)
Output:
Min. 1st Qu. Median Mean 3rd Qu. Max.
3.750 4.875 6.750 6.438 7.688 9.000
A B
5.0625 7.8125
Select everything and press Ctrl + Enter. This is what should happen, and what you see in the screenshot (again, my Spanish version of the script):
- In the console the executed lines and the results appear: the summary of the marks and the mean of each group (5.0625 for A and 7.8125 for B).
- In Environment the variables you have created appear (in my screenshot, with their Spanish names:
datos,desv,grupo,mediaandnotas). - In Plots the histogram appears, with a coral line at the mean.

If your screen looks like this one, the installation is done.
Final check: is everything ready?
- Does the RStudio console show the R version when it starts?
- Does
1 + 1return[1] 2? - Does the
check-packages.Rscript giveTRUEfor every package? - When you run
marks-ME1.R, does the histogram appear in Plots? - Do you know which folder R is working in (
getwd())?
If all five answers are yes, you can start the first lab.
Typical problems and how to fix them
| Symptom | Likely cause | Fix |
|---|---|---|
| RStudio warns that it cannot find R | R is not installed, or was installed after opening RStudio | Install R and restart RStudio; if nothing changes, Tools > Global Options > General > Change… |
there is no package called 'fitdistrplus' | The package is not installed (or you changed R version) | install.packages("fitdistrplus") and run the library() again |
could not find function "fitdistr" | The package is installed but not loaded | Add library(MASS) at the top of the script |
| It asks whether to install from sources | There is a newer, uncompiled version of the package | Answer No |
| When installing a package: ‘lib’ is not writable | R cannot write to its packages folder | Accept when it offers to use a personal library |
cannot open file 'data.csv': No such file or directory | The file is not in the working folder | Check getwd() and use Session > Set Working Directory, or open a project (explained in How to use RStudio) |
| Plots come out cut off or with the error figure margins too large | The Plots pane is too small | Make the pane bigger or click Zoom in Plots |
What next?
With R and RStudio working, the next step is to move around RStudio with ease: run line by line, see your data as a table, ask for help on a function and avoid the workspace mistake that drags variables from one lab to the next. All of that is in How to use RStudio.
And if R is new to you, start with R from scratch: the console as a calculator, vectors and matrices, and in the second part data frames and reading .csv files. All the examples can be tried in the site’s R playground, with nothing to install.
Did this article help you? Here is how you can support SergioLearns →



