Skip to content

Install RStudio for Ubuntu or WSL

Comprehensive guide for installing RStudio Desktop on Ubuntu Linux or Windows Subsystem for Linux (WSL2).

Overview

RStudio is an integrated development environment (IDE) for R programming. While RStudio installation on Linux is officially supported, getting it to work seamlessly with popular R packages like Tidyverse requires additional system dependencies. This guide provides a complete, tested procedure for Ubuntu 24.04.

WSL2 Complexity

Installing RStudio in WSL2 is not as straightforward as it initially appears. Package installations often fail due to missing system libraries. Following this complete procedure ensures all dependencies are configured correctly the first time.

Prerequisites

  • Ubuntu 24.04 (or compatible Linux distribution)
  • WSL2 if running on Windows
  • Administrator (sudo) access
  • Internet connection for package downloads

Installation Steps

Part 1: Install R Base

R must be installed before RStudio. These instructions follow the official CRAN repository configuration.

Update system and install prerequisites:

1
2
sudo apt update -qq
sudo apt install --no-install-recommends software-properties-common dirmngr

Add CRAN repository signing key:

1
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

Add CRAN repository for your Ubuntu version:

1
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

Install R:

1
sudo apt install --no-install-recommends r-base

Verify R installation:

1
R --version

Should display R version 4.x or later.

Part 2: Install RStudio Desktop

Download and install RStudio from the official RStudio download page.

Install gdebi package installer:

1
sudo apt-get install gdebi-core

Download RStudio Desktop (Ubuntu/Debian package):

1
wget https://download1.rstudio.org/electron/jammy/amd64/rstudio-2024.04.2-764-amd64.deb

Check Latest Version

Visit the RStudio download page to get the latest version URL. Update the wget URL accordingly for newer releases.

Install RStudio:

1
sudo apt install ./rstudio-*.deb

This installs the .deb package and resolves most basic dependencies automatically.

Part 3: Install Supporting System Libraries

This is the critical step often missed in basic installation guides. R packages frequently require system-level libraries for compilation and operation.

Core package dependencies (XML, curl, SSL, Fortran, linear algebra):

1
sudo apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev gfortran liblapack-dev libopenblas-dev cmake

These libraries enable: - libxml2-dev: XML parsing for data import/export - libcurl4-openssl-dev: HTTP requests and API interactions - libssl-dev: Secure connections and cryptography - gfortran, liblapack-dev, libopenblas-dev: Mathematical computations - cmake: Building packages from source

Font and image rendering libraries:

1
sudo apt -y install libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev

These libraries enable: - Graphics rendering in ggplot2 and other visualization packages - Plot export to PNG, JPEG, TIFF formats - Proper font rendering in graphics

Part 4: Configure pkg-config

The pkg-config utility is installed as a dependency but may not be configured properly in PATH.

Add pkg-config to environment:

1
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Make this permanent by adding to your shell configuration:

1
2
echo 'export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig' >> ~/.bashrc
source ~/.bashrc

For Zsh users, replace ~/.bashrc with ~/.zshrc.

Launching RStudio

Start RStudio from terminal:

1
rstudio

RStudio GUI will launch. In WSL2, this requires an X server or uses the built-in WSLg graphics support in Windows 11.

WSLg Graphics

Windows 11 includes WSLg, which provides native GUI support for Linux applications. On Windows 10, you may need to install an X server like VcXsrv or X410.

Testing the Installation

Once RStudio is open, test the complete installation by installing Tidyverse, which exercises most system dependencies:

1
install.packages("tidyverse", dependencies = TRUE)

This should complete without errors. If successful, all system libraries are correctly configured.

Load Tidyverse to verify:

1
library(tidyverse)

Should load without warnings or errors.

Troubleshooting

Package Installation Fails with Missing Library Errors

If you see errors like:

1
2
ERROR: configuration failed for package 'xml2'
ERROR: dependency 'curl' is not available

Ensure you completed Part 3 - system library installation. Re-run the library installation commands.

RStudio Won't Launch in WSL2

Windows 10: Install an X server (VcXsrv or X410) and set the DISPLAY variable:

1
export DISPLAY=:0

Windows 11: WSLg should work automatically. If not, update WSL:

1
wsl --update

"Cannot open display" Error

Set the DISPLAY environment variable:

1
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

Or for Windows 11 with WSLg:

1
export DISPLAY=:0

Alternative: RStudio Server

For a browser-based alternative without GUI requirements, consider RStudio Server:

1
sudo apt-get install rstudio-server

Access via browser at http://localhost:8787

Additional Resources

Next Steps

After successful installation:

  1. Configure RStudio preferences (Tools → Global Options)
  2. Install additional R packages as needed
  3. Set up version control integration with Git
  4. Explore RStudio projects for organizing work

Reference: Installation procedure adapted from Installing RStudio in WSL2 by Adrian Huxley, with style and organization adapted for this documentation.