Here is a super-easy visual guide to setting up and running RStudio Server for Ubuntu 20 on Windows 10. This is useful if you want to run R for Linux (e.g., due to its faster computation and better parallelization or simply to do cross-platform development) while on a Windows machine. Although there are several such guides already (linked below), this one combines the content of several and, through the use of screenshots and examples, is meant to be especially accessible to those without prior Linux experience.
1. Update Windows 10
We want to use the Windows Subsystem for Linux version 2 (WSL2), but to do so we need to update a recent build of Windows 10.
In the Windows search bar at the bottom-left of the screen, type in Check for updates
and left-click the matching result (or click here). Install all updates (this might take a while), restarting when required.
When done, you should have Windows 10 version 1903, 1909, 2004, or 20H2 (or higher). Do not proceed to further steps until this one is complete. To check this, press the Windows logo key and the R key at the same time (⊞+R), type in winver
, and hit Enter.
2. Open PowerShell
To quickly and easily change some Windows settings (i.e., enable some features that are disabled by default), we can use the Windows PowerShell.
In the Windows search bar at the bottom-left of the screen, type in Windows PowerShell
, and left-click the matching result. This will pull up a big blue console window.
3. Enable WSL1 and the Virtual Machine Platform
Now we need to enable those disabled features: the Windows Subsystem for Linux version 1 (WSL1) and the Virtual Machine Platform.
Enter the following commands into the PowerShell console, hitting Enter after each:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all
Once complete, save and close down all your documents and restart your machine. It's not necessary to do it this way, but you can restart your computer from the PowerShell console by typing Restart-Computer
and hitting Enter.
4. Download and install WSL version 2
Now that we have WSL1 enabled and installed, we can upgrade it to version 2 (WSL2).
Go to this page and follow the instructions to download and install the latest WSL2 Linux kernel. (Note that different installers are needed for x64 and ARM64 machines.)
5. Open PowerShell (again)
Since we restarted the computer during Step 3, the PowerShell console is gone and we have to re-open it using the instructions from Step 2.
In the Windows search bar at the bottom-left of the screen, type in Windows PowerShell
, and left-click the matching result.
6. Change the default WSL version to 2
Now we need to tell Windows to use WSL2 by default instead of WSL1.
Enter the following command into the PowerShell console and hit Enter:
wsl --set-default-version 2
7. Install and Launch Ubuntu from the Microsoft Store
We are finally ready to install Ubuntu on Windows using WSL2.
Go the this page in your web browser, which will open the Microsoft Store. Left-click the “Ubuntu” button to open the Ubuntu download page and left-click the “Install” button to download and install it. When it is finished, left-click the “Launch” button to open it. Alternatively, and in the future, you can open Ubuntu by finding it in your start menu as you would any other Windows program/app. Either way, this will open a black terminal window.
8. Configure your Ubuntu account
When launching for the first time, the Ubuntu terminal will ask you to create a username and password for your Ubuntu account. This can be whatever you'd like it to be. Don't forget these as you will need them later.
Type in your desired Ubuntu username into the Ubuntu terminal and hit Enter, then type your desired Ubuntu password and hit Enter, then type in your desired Ubuntu password again and hit Enter.
9. Check that Ubuntu is using WSL2
Before continuing, let's just double-check that Ubuntu is using WSL version 2.
In Powershell, use the following command to check that Ubuntu appears, has the “Running” state and the “2” version. If this does not appear, you may need to run the previous Powershell steps as Administrator (or not as Administrator).
wsl -l -v
10. Enable copy-pasting into your Ubuntu terminal
Some of the next steps involve entering rather long and complicated commands into the Ubuntu terminal. To make this easier, we can enable copy-paste functionality.
With your Ubuntu terminal window open, left-click the center of the orange Ubuntu icon on the top-left of the window; this will open a contextual menu (see the image below). Select the “Properties” option from the menu. From here, left-click the checkbox next to “Use Ctrl+Shift+C/V as Copy/Paste” to add a check to it. Then click the “OK” button.
Now you can press the Ctrl, Shift, and C keys (Ctrl+Shift+C) at the same time to copy text from Windows (e.g., from this webpage) and then, with the Ubuntu terminal open, press the Ctrl, Shift, and V keys (Ctrl+Shift+V) at the same time to paste that text into the terminal.
11. Update Ubuntu
When you first install Ubuntu, several packages that come with it may be slightly outdated. Quickly update them to the newest version before continuing.
Enter the following commands into the Ubuntu console and hit Enter:
sudo apt update sudo apt upgrade -y
You will need to enter your newly created password and hit Enter to confirm some of these commands.
12. Install the newest version of R and dependencies for RStudio
To install the newest version of R on your virtual Ubuntu machine, you will first need to add a long key phrase and the appropriate repository to download R from.
Copy and paste the following commands into the Ubuntu terminal and hit Enter:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' sudo apt update sudo apt install -y r-base r-base-core r-recommended r-base-dev gdebi-core build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev
Again, you may need to enter your newly created password and/or type Y
and hit Enter to confirm some of these commands.
13. Check the version of R that was installed
If all went well, you should now have R version 4.0.5 (or higher) installed.
Enter the following commands into the Ubuntu console and hit Enter:
R --version
14. Install the newest version of RStudio Server on Ubuntu
Although we could now run R from the Ubuntu terminal by typing R
and hitting enter, it will be much more convenient to install RStudio Server (free version) and use that as an interface to R on our virtual Ubuntu machine.
Copy and paste the following commands into the Ubuntu terminal to download the newest version of RStudio Server for Ubuntu.
wget https://rstudio.org/download/latest/stable/server/bionic/rstudio-server-latest-amd64.deb sudo gdebi rstudio-server-latest-amd64.deb