Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Installing RStudio in WSL2

Installing RStudio within the Windows Subsystem for Linux was not as simple as expected, once I started installing packages in R. Here’s my procedure for getting it all to work seamlessly.

The installation of RStudio is supported on Linux systems and can be installed via the command line within Windows Subsystem for Linux (WSL2). Whilst this is presented as being easy, this was found not to be the case when I attempted to load some of my favourite R packages such as Tidyverse. Sorting out the mess took a lot of effort, so here’s my procedure for getting it right the first time.

I am running Ubuntu 22.04.

Part 1: Install R base

R needs to be installed prior to anything else. I followed the advice from the RStudio CRAN website; in WSL2, enter the following commands:

sudo apt update -qq
sudo apt install --no-install-recommends software-properties-common dirmngr
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
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

This adds a signing key for various repostories. Next, install R:

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

Part 2: Install RStudio

I followed the instructions on the RStudio website. Prior to installation, you will need to install gdebi-core:

$ sudo apt-get install gdebi-core

Next, download the appriate version of RStudio from their website. For me, the correct syntax was:

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

Part 3: Install supporting Linux packages

This was a particularly tricky bit, but I finally got it sorted. In essence, there is a littany of Linux packages that R will require to operate in WSL2.

Package support:

sudo apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev

Font and image support

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

Part 4: Configure pkg-config

Along the way, pkg-config gets installed, but wasn’t added to PATH. Thankfully this is a one-liner in WSL2:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Part 5: Launch RStudio

RStudio can be launched with the simple rstudio command. Installing Tidyverse should then work nicely in R with the following command:

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

   

Comments

No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.