This post is a part of a series, and you can use the following links to go directly to the other parts of the series:
- Part 1: Introduction
- Part 2: Setting up a VPS
- Part 3: Setting up RStudio Server
- Part 4: Setting up Jupyter Notebook
- Part 5: Setting up Visual Studio Code
Overview
If you've been following the series, you should now have your own VPS up and running. (If you don't, refer to my Part 2 post)
By the end of this post you should have a full RStudio environment running on it too, which you can then access through a web browser no matter what platform you're on (PC, tablet, or even mobile phone).

Once you have this running, you could for example start an analysis on your desktop at home, continue working on it from your tablet while you're on the go, and seamlessly transition back to your desktop once you're back home.
Housekeeping
Before we install R Studio, the first step is to install R. And before that, we need to do some housekeeping.
If you have prior experience with Debian-based Linux distros, you'll know that the best practice for whenever you're installing a new software is to type:
sudo apt update
On my previous post, I've briefly mentioned that you can elevate a non-root
user's privileges to super-user level. The command to do so is su
, but sudo
is more commonly used because the privilege elevation only applies to that single command following sudo
.
Whenever you use su
or sudo
, the system will ask for a password. Note that this is the root password, and not the password of the user you're logged in with.apt
stands for Advanced Package Tool, and is the default package (software) manager used in Debian-based Linux distros. The update
option next to it tells apt
to check its repositories for the latest versions of available packages.
So when you type sudo apt update
, you're your VPS to do the following things:
- Elevate privileges to super-use
- Check for latest versions of available software packages
Another good practice is to keep your Linux system up to date by upgrading installed packages to their latest versions. This can be done by typing:
sudo apt upgrade -y
The -y
argument at the end is telling apt
to consider your response as "yes" whenever it needs to ask for your confirmation. You can omit this and review the upgrade details before manually typing "y" when it asks you Do you want to continue? [Y/n]
.
Installing R
If you just want to quickly install R and don't care if it's a slightly outdated version, you can now simply type:
sudo apt install r-base r-base-dev -y
But unfortunately the R version available in Ubuntu's default repository aren't updated very regularly, so we need to add CRAN
(The Comprehensive R Archive Network) to the list of repositories for apt
to search. This can be done by first typing:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
This command will add the GPG
(GNU Privacy Guard) key for CRAN to apt
.
Next, type:
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
This is the actual command to add the default CRAN
mirror to the apt
repository.
Note: This adds the CRAN repository for Ubuntu 18.04 (codenamed Bionic) and R version 3.5, which are the latest at point of time of writing. If you're on a different Ubuntu version or wish to install a different R version, this will need to be changed.
Now since we have a new repository, we'll need to refresh apt
again using the command:
sudo apt update
You can note that the new repository now shows up as one of the repositories being refreshed from.
And finally, we can install R using:
sudo apt install r-base r-base-dev -y
You can check that R is successfully installed by typing:
R --version
This should show you the version of R installed.
Install RStudio Server
Next let's install RStudio Server.
For this, we'll need to install another package manager called GDebi
, by typing:
sudo apt-get install gdebi-core -y
Next, we'll download RStudio Server package to the VPS's local disk:
wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.3.959-amd64.deb
Note: This is the latest RStudio Server version available at point of time of writing. The latest version can be downloaded from RStudio's download page.
max@ubuntu:~$ wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.3.959-amd64.deb
--2020-01-26 20:59:10-- https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.3.959-amd64.deb
Resolving download2.rstudio.org (download2.rstudio.org)... 52.84.228.15, 52.84.228.69, 52.84.228.98, ...
Connecting to download2.rstudio.org (download2.rstudio.org)|52.84.228.15|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 66392542 (63M) [application/x-deb]
Saving to: ‘rstudio-server-1.3.959-amd64.deb’
rstudio-server-1.3. 100%[===================>] 63.32M 4.43MB/s in 12s
2020-05-26 20:59:22 (5.39 MB/s) - ‘rstudio-server-1.3.959-amd64.deb’ saved [66392542/66392542]
Finally we will install the package using GDebi
:
sudo gdebi rstudio-server-1.3.959-amd64.deb
After a long list of lines showing the installation details, the screen should end with:
Preparing to unpack rstudio-server-1.3.959-amd64.deb ...
Unpacking rstudio-server (1.3.959) ...
Setting up rstudio-server (1.3.959) ...
Created symlink /etc/systemd/system/multi-user.target.wants/rstudio-server.service → /lib/systemd/system/rstudio-server.service.
● rstudio-server.service - RStudio Server
Loaded: loaded (/lib/systemd/system/rstudio-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-01-26 21:00:40 +08; 1s ago
Process: 29249 ExecStart=/usr/lib/rstudio-server/bin/rserver (code=exited, status=0/SUCCESS)
Main PID: 29250 (rserver)
Tasks: 3 (limit: 2311)
CGroup: /system.slice/rstudio-server.service
└─29250 /usr/lib/rstudio-server/bin/rserver
Jan 26 21:00:40 mint systemd[1]: Starting RStudio Server...
Jan 26 21:00:40 mint systemd[1]: Started RStudio Server.
And that's it, your RStudio Server is now installed and ready for use!
Connecting to RStudio Server
By default, RStudio Server listens on port 8787
.
So assuming the IP address of your VPS is 12.34.56.78
, you can open up a web browser and type:
12.34.56.78:8787
Log in with the username and password you use to log in to your VPS (not root
), and... Voilà!

Note: This screenshot is from a local installation, so shows localhost
instead of the server IP.
Conclusion
There are a few more "best practice" steps left to do for security, such as securing the connection with a SSL certificate or changing the default port.
But that's another post for another time. For now, enjoy the full power of R on your brand new Cloud Computing platform!