Setup RStudio Server on Windows with a Virtual machine
Introduction
You may be asking yourself: why would I want to setup RStudio Server on Windows? I already have RStudio, what would be the benefit of running RStudio Server in a Linux Virtual Machine (VM) on my Windows machine be? Here are a few reasons:
- Multiple RStudio sessions running simultaneously
- Development for deployment on a Shiny Server
- Test package development independently of OS
For the purposes of this tutorial, we're going to use VirtualBox, however any virtualization product will work, and we'll be installing Ubuntu Server 18.04 LTS, although your preferred Linux distro is also acceptable.
Steps
Figure 1. Fresh VirtualBox Manager GUI. The red arrow indicates where to click to setup a new VM. |
- Go ahead and start downloading your distro as it may take a few minutes.
- Download and install VirtualBox. Hopefully your Linux distro has finished downloading, as installation of VirtualBox may interrupt network connectivity. Go ahead and start VirtualBox after installation.
- Go ahead and click the new button to begin installation (Figure 1).
- Go ahead and switch to Expert Mode (Figure 2).
- Type in Ubuntu RStudio Server or some other meaningful name. VirtualBox should autocomplete the other fields based on the name, but double-check that the "Type" is "Linux" and the "Version" is the distro of Linux you wish to install. Also assign some memory (4 GB, if you can spare it, but not less than 1 GB) (Figure 3).
Figure 2. Switch to Expert Mode after selecting "New" from the VirtualBox Manager. |
Figure 3. Expert Install Settings. |
- Go ahead and click "Create". The defaults here are fine, but you may want to change where the Virtual Hard Disk is created as well as the size of the Virtual Image, you may here.
- After creation, you can power it up and VirtualBox will want to see from where you are installing the VM. Navigate to the ISO file you downloaded and select it (Figure 4).
Figure 4. Choosing the ISO to Boot. |
- Before booting up the VM, click on Settings, and make sure that your Internet connection is configured for the VM. Go ahead and select start and the The VM will boot the selected ISO.
- Follow the on-screen install process and setup a Username and Password (this is how you will connect to RStudio Server). Advanced users can change their configuration here.
- Install should not take long, and you will be asked to reboot, go ahead and do so.
- Login with the username and password setup earlier, and run `sudo apt-get update && sudo apt-get upgrade` to bring your system up-to-date. Then run `sudo apt-get install r-base r-base-dev gdebi-core`.
- Go to RStudio's Server website, and use the commands to install the necessary. Follow the instructions on this website to setup RStudio Server. (You can enable copy/paste between VirtualBox's VM and your host OS to expedite).
- Now, run `ifconfig` to get your ip address, and in the browser of your choice, append ":8787" to it to connect to the RStudio server (Figure 5).
Figure 5. RStudio Server Running on a VM from a Guest OS. - If using Chrome, create an application shortcut to quickly launch RStudio Server on your VM, just as if it was RStudio on your desktop (Figure 6). You can also setup your VM to share files with your guest OS.
Figure 6. Three RStudio Server instances running in VMs. |
Congratulations! You have now setup RStudio Server running on a VM!