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 | |
Add CRAN repository signing key:
1 | |
Add CRAN repository for your Ubuntu version:
1 | |
Install R:
1 | |
Verify R installation:
1 | |
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 | |
Download RStudio Desktop (Ubuntu/Debian package):
1 | |
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 | |
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 | |
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 | |
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 | |
Make this permanent by adding to your shell configuration:
1 2 | |
For Zsh users, replace ~/.bashrc with ~/.zshrc.
Launching RStudio¶
Start RStudio from terminal:
1 | |
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 | |
This should complete without errors. If successful, all system libraries are correctly configured.
Load Tidyverse to verify:
1 | |
Should load without warnings or errors.
Troubleshooting¶
Package Installation Fails with Missing Library Errors¶
If you see errors like:
1 2 | |
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 | |
Windows 11: WSLg should work automatically. If not, update WSL:
1 | |
"Cannot open display" Error¶
Set the DISPLAY environment variable:
1 | |
Or for Windows 11 with WSLg:
1 | |
Alternative: RStudio Server¶
For a browser-based alternative without GUI requirements, consider RStudio Server:
1 | |
Access via browser at http://localhost:8787
Additional Resources¶
- RStudio Official Documentation
- CRAN Ubuntu Installation Guide
- Tidyverse Documentation
- R for Data Science Book - Free online resource
Next Steps¶
After successful installation:
- Configure RStudio preferences (Tools → Global Options)
- Install additional R packages as needed
- Set up version control integration with Git
- 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.