In this guide, we will learn how to install R and RStudio on Windows, macOS, Linux, and UNIX [FreeBSD] and get our machine ready for some statistical research and data science.
The whole R and RStudio installation on all the above-mentioned operating system do not take more than 5-10 minutes of your time.
R is a free programming language and software environment for statistical computing and graphics created and maintained by the R Foundation for Statistical Computing. R is also a very popular programming choice among data scientists and statisticians for statistical computing, data mining, and design.
To use R to its maximum potential, you need to install two components on your machine: the R language and the RStudio Desktop IDE. This article covers both installations. In this tutorial, we will do just that.
Ready? Let’s get to work!
Install R and RStudio on Windows.
- Select a CRAN mirror
Open a browser and navigate to CRAN R-project website. CRAN is a set of worldwide distributed mirror servers to provide global coverage and fast download speeds for R setup and R packages. Select a mirror server that is nearest to your location.
2. On the Download and install R section, click on Download R for Windows.
3. On the Download for Windows section, click on the base sub-directory.
4. Click on the latest R release for Windows 32/64 bit. At the time of writing this guide, the latest version is R 4.0.4 but by the time you read this guide, a new R version might be available.
5. Once the download is completed, click on Open File to launch the installer. Alternatively, you can find and launch the R installer from your Download folder.
6. Select Yes when prompted to allow this app to make changes to your computer.
7. On the Select Setup Language dialogue box, select your language and click OK.
8. On the Information window, review the GNU General Public License agreement and click Next.
On the Select Destination Location, click Next
9. Leave the default settings on the Select Components window to avoid 32/64 bit package compatibility issues later. Click Next.
10. On the Startup Options window, you can customize the installation further. For most cases, the default settings are sufficient. Leave the default No option selected and click Next.
11. On the Select Start Menu Folder window, leave the defaults and click Next.
12. You can choose to create a Desktop or Quick Launch shortcut or proceed with the Select Additional Tasks window’s default settings. Click Install.
13. Windows will proceed to install R on your system. Once completed, click Finish to close the installation window.
At this time, the R language is installed on our Windows machine. However, if you launch R now, you will be greeted by a console and a prompt. To make things much easier for us, we can install a front-end IDE for the R language called RStudio.
The RStudio IDE is a series of interconnected tools designed to enable you to code in R and Python more efficiently. It provides a console, syntax-highlighting editor that facilitates direct code execution, and a range of comprehensive resources for plotting, scanning, debugging, and handling the workspace.
14. To download RStudio Desktop IDE on your Windows computer, head over to the RStudio Desktop website, scroll down to the Download section and select the RStudio Desktop Free option. Click the Download button.
15. In the All Installers section, download the Windows 10/8/7 .exe installer.
16. Once the download is completed, click Open File to launch the RStudio Desktop Installer. The RStudio installer can be also found in your Download folder.
17. Select Yes when prompted to allow this app to make changes to your computer.
18. On the Welcome to RStudio Setup window, select Next.
19. On the Choose Install Location window, select Next.
20. On the Choose Start Menu Folder window, select Install.
21. The RStudio Setup will proceed with the installation on your Windows machine. Once completed, click Finish.
22. To launch RStudio, click the Search icon on the Windows bar, search for RStudio and launch the RStudio IDE on your machine.
23. When prompted to Enable Automated Crash Reporting, click Yes.
Awesome! You just installed R and RStudio on Windows. Now go ahead and learn how to do some data analysis and statistics in R. Let’s learn next how to install packages in R using RStudio.
Install R and RStudio on macOS
- Open a browser and head over to CRAN R-project website. CRAN is a set of worldwide distributed mirror servers to provide global coverage and fast download speeds for R installers and R packages. Select a mirror server that is nearest to your country.
- On the Download and Install R page, click on Download R for (Mac) OS X
- On the R for Mac OS X page, download the latest .pkg release.
- Launch the installer. You should find the R .pkg installer in your Download folder. On the R Welcome window, click Continue.
- Read the Important Information and click Continue.
- Read the Software Licence Agreement and click Continue.
- When prompted to Agree with the Terms Of Software License Agreement, click Agree.
- Click the Install button to start the installation.
- When prompted, type your user password.
- Click the Close button. R is now installed on your macOS computer.
The RStudio IDE is a collection of tools created to enable coding in R and Python more efficiently. Let’s install RStudio on our Mac next.
- To download RStudio Desktop IDE on your macOS machine, navigate to the RStudio Desktop website, scroll down to the All Installers section, and download the macOS 10.13+ installer by clicking the .dmg file.
- Once the download is completed, launch the installer, usually located in your Download folder, and drag and drop the RStudio icon on your application folder.
- To launch the RStudio, head over to the Applications folder and double-click on the RStudio icon. When prompted if you want to open an application downloaded from the Internet, click Open.
- When prompted to Enable Automated Crash Reporting, click Yes.
That’s it. We just installed R and RStudio on macOS. You are now ready to write some cool code in R.
Install R and RStudio on Linux
In Linux, we have quite a number of distributions, but all of these distros are basically based on three main Linux branches: Debian (e.g., Ubuntu, Linux Mint, PopOS, etc.), RedHat (e.g., Fedora, CentOS, Suse Linux), and Arch (e.g., Manjaro, Endeavors OS).
Install R and RStudio on Debian-based distributions
R installation on Debian and Debian-based distributions is a straightforward process. In this guide, I will install R on Ubuntu 21.10. The installation method should be the same for newer Ubuntu versions.
- To install R on Ubuntu, open a terminal and type:
sudo apt -y install r-base
- To install RStudio on Ubuntu, open a browser and head over to the RStudio Desktop website, scroll down to the All Installers section and select Ubuntu 18/Debian 10 .deb package.
- When prompted, select Save to download the file on your computer.
- Navigate to your Download folder, right-click and select the Open in Terminal option. Alternatively, you can navigate to the Download folder using cd ~/download in the terminal.
- To install the RStudio .deb package, type in the terminal the following command and use the Tab key on your keyboard to autocomplete the name of the file.
sudo dpkg -i rstudio<Hit Tab Key>
- If the installer complains about any missing dependencies, type in the terminal the following command:
sudo apt --fix-broken install
Alternatively, you can use the following command to fix any broken dependencies:
sudo apt -f install
- To launch RStudio, find the application in your App Launcher or type in the terminal: RStudio When prompted to Enable Automated Crash Reporting, click Yes.
That all. You just installed R and RStudio on Ubuntu.
Install R and RStudio on RPM-based distributions
Follow this guide if you are using an RPM-based Linux distribution such as RHEL, Fedora, CentOS, etc. In this guide, I am going to use Fedora 36.
- To install R on Fedora, open a terminal and type:
sudo yum install R
- To install RStudio on Fedora, open a browser and head over to the RStudio Desktop website, scroll down to the All Installers section and select Fedora 28/Red Hat 8 .rpm package.
- When prompted, select Save to download the file on your computer. Navigate to your Download folder and double-click on the .rpm file you just downloaded. The Software Manager window will open. Click Install.
5. Once the RStudio package is installed, click the Launch button.
When prompted to Enable Automated Crash Reporting, click Yes.
You are now ready to write code in R on your RPM-based operating system.
Install R and RStudio on Arch-based distributions
Follow this guide if you are using Arch or any other Arch-based Linux distribution. In this guide, I am going to use Manjaro 21.
- To Install R language on Arch-based systems, open a terminal and type:
sudo pacman -S r
Type Y when prompted to proceed with the installation.
- Install RStudio IDE. To install RStudio, in the terminal type:
pamac build rstudio-desktop-bin
- Launch RStudio from the application launcher or by typing in the terminal:
When prompted to Enable Automated Crash Reporting, click Yes.
And just like that, we managed to install R and RStudio on an Arch-based distribution. You gotta love Linux for its simplicity!
Install R and RStudio on UNIX [FreeBSD]
For UNIX, I chose the most popular UNIX distribution out there: FreeBSD. In this guide, I am using FreeBSD 13 with GNOME Desktop Environment but the same installation procedure applies to other Desktop Environments or Windows Managers out there.
1. Install R language by opening a terminal, switching to the root user (su -), and typing:
pkg install r
Bam! The R language is installed on FreeBSD!
2. Install RStudio IDE on FreeBSD To install RStudio, in the terminal type as root:
pkg install RStudio
Alternatively, you can build the RStudio package from freshports by running the following command as root:
cd /usr/ports/devel/RStudio/ && make install clean
[Optional] RStudio requires /proc to be mounted in /etc/fstab. To edit /etc/fstab, use the ee text editor or install nano using the following command as root:
pkg install nano
3. Next, edit the /etc/fstab:
- Add the following line into the /etc/fstab file:
proc /proc procfs rw 0 0
Your /etc/fstab file should look like this after adding the above line:
Save and quit the fstab file (press Ctrl+X then type Y to save).
- Mount /proc by running the following command:
- You can launch RStudio by launching the app or typing in the terminal:
You are now ready to write code in R on FreeBSD operating system.
In this article, we learned how to install R and RStudio on Windows, macOS, Linux, and UNIX [FreeBSD] operating systems.
As you see, installing R and RStudio on any OS is quite straightforward. Now go ahead and learn some statistics for R with me!