RStudio Server, Linux(Ubuntu), WSL(Windows Subsystem for Linux), and Docker

Young Joon Oh
Geek Culture
Published in
3 min readAug 16, 2021

If I want to use RStudio Server, I need Linux as OS. Windows users like me need to set up WSL(Windows Subsystem for Linux) for RStudio Server. First of all, make sure if your Windows is the latest version.

  1. Setup WSL

Find Turn Windows features on or off in the Search of Windows.

Check Virtual Machine Platform and Windows Subsystem for Linux. Then Restart your device.

2. Change the WSL version to 2

# In the Windows PowerShell as Administratorwsl --set-default-version 2 # See https://aka.ms/wsl2kernel if you have an issue

3. Install Ubuntu

Find Run Linux on Windows in the Microsoft Store. Click and download Ubuntu

4. Setup Ubuntu account

Run Ubuntu you already installed, and type username and password which you desire. These username and password will be used in the RStudio Server.

5. Update Ubuntu

# In the Ubuntusudo apt update
sudo apt upgrade -y
# You cannot use ctrl+V in the Ubuntu. Instead Use the right click

6. Install the latest R and RStudio Server

# See https://cran.r-project.org/bin/linux/ubuntu/   sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' sudo apt updatesudo apt install -y r-base r-base-core r-recommended r-base-dev gdebi-core build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev 
## Install RStudio Server ##wget https://rstudio.org/download/latest/stable/server/bionic/rstudio-server-latest-amd64.debsudo gdebi rstudio-server-latest-amd64.deb

7. Run RStudio Server

sudo rstudio-server start

In the Web browser, http://localhost:8787, and type username and password you already created for the Ubuntu account.

8. Tip and Close RStudio Server

# Some packages may cause an install issue. You may need an dependency. 
# https://jeroen.cran.dev/V8/
sudo apt-get install -y libv8-dev# Then install R package V8## To Close RStudio Server ##sudo rstudio-server stop

9. Docker

Now you can use RStudio Server. But every time you need to open Ubuntu and type the code. When you close it, you also need to type the code in Ubuntu. Furthermore, when you need to run multiple machines using R, you may want something efficient. Docker can be an answer. Download Docker .

Run Docker. you can find Images tab in the left panel. Docker needs an image to run instead of files. We need Rstudio image.

Go to DockerHub. Then type rocker in the Search. You can find rocker/rstudio. Copy docker pull rocker/rstudio, then paste it in the Powershell.

You can find rocker/rstudio in the image tab of docker.

Click Run for it. In the option, choose Container names. For example, "rstudio-1". Then configure 4-digit Local Host like 1001.

Now you can see rstudio-1 in the Containers/Apps tab. In the web browser, type http://localhost:1001/. Both ID and Password are rstudio which was created by image creators.

10. Update image for your project

After creating your R environment using the rocker’s image, you need to make your own image.

# In the Powershell, check docker containers 
docker ps -a
docker commit {Container ID} {New image name}
#ex# docker commit 40b8d16b7dba rstudio-2

Now you can find rstudio-2 in the image tab. This rstudio-2 has the same environment you already created. Just run this without typing the code in Ubuntu. If you make multiple containers, you can run multiple Rs at the same time.

Originally posted on my website

--

--