RStudio Server on Ubuntu through Windows Subsystem for Linux (WSL2)
A guide to install RStudio Server on Ubuntu
![](/faculty/jwwang/post/rstudio-server-on-ubuntu-through-windows-subsystem-for-linux-wsl2/featured_hua1521fb5f5473dda832ddc25aa7fc8c5_1499929_1200x0_resize_q75_lanczos.jpg)
Why RStudio Server
I am mainly on Windows and have been using RStudio on Windows for many years. I decided to try RStudio Server (currently on Linux only) for the following reasons:
- RStudio on Windows sometimes crashes, especially during live demo teaching and working on larger data
- RStudio Server is much faster as it is based on Linux. This is particularly true when I am doing deep learning and working with larger dataset. For one project, RStudio Server saves half of the running time.
- Microsoft has introduced the Windows Subsystem for Linux (WSL2) which makes running Linux on Windows much easier. I tried dual OS booting and virtual machine before but not very convenient. WSL2 works greatly.
Prerequisites
I am using Windows 10 version 21H2. Before we install the RStudio Server, we need to do the following two things:
Enable the Windows Subsystem for Linux (WSL)
Go to your Windows PowerShell and use the following command to enable the WSL:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
The system needs to be restarted after the enabler.
Install Ubuntu on WSL
The simplest way to install Ubuntu on WSL is through the Microsoft Store. Go to the Microsoft Store and search for Ubuntu. It may return multiple results and I just use the default one.
After downloading the app, Open it to initiate the installation. It will take a few minutes. After installation, I need to assign an UNIX username and password which is the username for the new Ubuntu Linux operating system.
Now, you have the Ubuntu Linux operating system running on your Windows operating system through the Windows Subsystem for Linux. You may launch the Ubuntu system through the Windows Start menu. It is labeled as “Ubuntu on Windows” on my computer. It is so convenient as it is just running an application on Windows. You can also access to all your local hard disks through
/mnt
folder. I’d vote it as the greatest software from Microsoft in the most recent years (WSL was introduced in 2016)
Install RStudio Sever on Ubuntu through WSL
RStudio has provided a very good guide on the installation of RStudio Server on WSL.
Update Ubuntu
- Go to Windows Start to launch the “Ubuntu on Windows”. A command line window will appear. This is the command line interface for the Ubuntu Linux operating system.
- Use the following commands to upgrade Ubuntu packages
sudo apt-get update
sudo apt-get upgrade -y
You will need to input the password for your Linux account and it will take a while as a lot of packages need to be updated. This is similar to the Windows updates patches.
Install R most recent version
- Run the following commands to add credentials to your repository list for Getting the Latest R
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/'
- Install R
The following command is to install the most recent R and some necessary dependencies. It will take a while.
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
If you want to check you R installation, just type “R” in the command line (big R not little r).
Install RStudio Server
- Install RStudio Server using the following commands:
wget https://rstudio.org/download/latest/stable/server/bionic/rstudio-server-latest-amd64.deb
sudo gdebi rstudio-server-latest-amd64.deb
- Launch the RStudio Server
sudo rstudio-server start
If you want to stop and remove/uninstall the server, you may do the following:
# To stop the server
sudo rstudio-server stop
# To remove the server
sudo apt-get remove rstudio-server -y
- Access your server at http://localhost:8787 using your Ubuntu Linux username and password.
Now you have access to the RStudio Server through a browser. The interface is almost the same as the RStudio. The Server can only be accessed locally, ie, not through the internet. I need to figure out how to make it a real server which can be accessed through internet. But I doubt my University network allows me to set up my office computer as a server.
Enjoy the RStudio Server!
Last updated on 13 March, 2022