Oh, wouldn’t it be just wonderful if you could have your own RStudio installation on a server that you could then access from whatever device you currently have, including an iPad? It totally would. Except it’s some times far from straightforward. Here’s how to do it relatively painlessly.
Step 1: Get a server
I use Linode,1 and in general, their 4096 server is pretty good. Linodes can be very easily resized, so this should not be a worry.
Step 2: Set up the server
Once your Linode is up, it will turn up on your dashboard with a random name (
linode1234567, typically). If you click on it, you will see your Linode is ‘Brand New’, which means you need to configure it. I usually keep them in groups depending on purpose: blog servers, various processing servers, hosts, research servers. Each of them then gets a name. Choose whatever nomenclature fits your needs best.
Next, click on the
Rebuild tab, and configure the root password, the operating system (we’ll be using Debian 9), the swap disk size (for R, it’s a good idea to set this as large as you can) and finally, set the deployment disk size. I usually set that for 66%.
Step 3: Install R
SSH into your Linode and log in as root. You will find your Linode’s IP address and other interesting factoids about it under the
Remote access tab. I have obscured some information as I don’t want you scallywags messing around with my server, but the IP address is displayed both in the SSH link (the one that goes
ssh [email protected] or something along these lines) and below under public IPs.
/etc/apt/sources.list and add the following source:
# CRAN server for Debian stretch (R and related stuff) deb http://cran.rstudio.com/bin/linux/debian stretch-cran34/
Save the file, and next install
sudo apt-get install dirmngr). Then, add the requisite GPG key for CRAN, update the repository and install
sudo apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF' sudo apt update sudo apt install r-base
At this point, you can enter R to test if your R installation works, and try to install a package, like ggplot2. It should work, but may ask you to select an installation server. If all is well, this is what you should be getting:
root@localhost:~# R R version 3.4.4 (2018-03-15) -- "Someone to Lean On" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.
In the prompt, enter
install.packages("ggplot2"). Select a server if requested. Otherwise, watch
ggplot2 (and a bazillion other packages) install. Then, quit R by calling
Step 4: Downgrade
For some inscrutable reason, RStudio is currently set up to work with
libssl1.0.0, whereas Debian 9 comes with
libssl1.1.0 out of the box. Clearly that’s not going to work, so we’ll have to roll back our
libssl. We’ll do so by creating a file called
vim. And we’ll fill it with the following:
deb http://httpredir.debian.org/debian jessie main contrib non-free deb-src http://httpredir.debian.org/debian jessie main contrib non-free deb http://security.debian.org/ jessie/updates main contrib non-free deb-src http://security.debian.org/ jessie/updates main contrib non-free
In case you’re curious: this creates a sources list called
jessie, and allows you to draw from Debian Jessie. So let’s have apt get with the program (
sudo apt update), and install
sudo apt install libssl1.0.0). Ift may be prudent to also install the
openssl tool corresponding to the
libssl version (
sudo apt install openssl/jessie).
Step 5: Time to install RStudio Server!
First, install gDebi, a package installer, by typing
sudo apt-get install gdebi. Next, we’ll be grabbing the latest RStudio version using wget, and installing it using gDebi. Make sure you either do this in your home directory or in
/tmp/, ideally. Note that the versions of RStudio tend to change – 1.1.442 was the current version, released 12 March 2018, at the time of writing this post, but may by now have changed. You can check the current version number here.
wget https://download2.rstudio.org/rstudio-server-1.1.442-amd64.deb sudo gdebi rstudio-server-1.1.442-amd64.deb
If all is well and you said yes to the
dress question about whether you actually want to install RStudio Server (no, you’ve been going through this whole pain in the rear for excrement and jocularity, duh) , you should see something like this:
(Reading database ... 55651 files and directories currently installed.) Preparing to unpack rstudio-server-1.1.442-amd64.deb ... Unpacking rstudio-server (1.1.442) ... Setting up rstudio-server (1.1.442) ... groupadd: group 'rstudio-server' already exists rsession: no process found Created symlink /etc/systemd/system/multi-user.target.wants/rstudio-server.service → /etc/systemd/system/rstudio-server.service. ● rstudio-server.service - RStudio Server Loaded: loaded (/etc/systemd/system/rstudio-server.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2018-03-31 21:59:25 UTC; 1s ago Process: 16478 ExecStart=/usr/lib/rstudio-server/bin/rserver (code=exited, status=0/SUCCESS) Main PID: 16479 (rserver) Tasks: 3 (limit: 4915) CGroup: /system.slice/rstudio-server.service └─16479 /usr/lib/rstudio-server/bin/rserver Mar 31 21:59:25 localhost systemd: Starting RStudio Server... Mar 31 21:59:25 localhost systemd: Started RStudio Server.
Now, if all goes well, you can navigate to your server’s IP at port
8787, and you should behold something akin to this:
There are a few more things you wish to install at this point – these are libraries that will help with SSL and other functionality from within R. Head back to the terminal and install the following:
sudo apt-get install libssl-dev libcurl4-openssl-dev libssh2-1-dev
Step 6: Some finishing touches
The login screen will draw on PAM, Unix’s own authentication module, in lieu of a user manager. As such, to create access, you will have to create a new Unix user with
adduser, and assign a password to it. This will grant it a directory of its own, and you the ability to fine-tune what they should, and what they shouldn’t, have access to. Win-win! This will allow you to share a single installation among a range of people.
Step 7: To reverse proxy, or to not reverse proxy?
There are diverging opinions as to whether a reverse proxy such as NGINX carries any benefit. In my understanding, they do not, and there’s a not entirely unpleasant degree of security by obscurity in having a hard to guess port (which, by the way, you can change). It also makes uploads, on which you will probably rely quite a bit, more difficult. On the whole, there are more arguments against than in favour of a reverse proxy, but I may add specific guidance on reverse proxying here if there’s interest.
References [ + ]
|1.||↑||Using this link gives me a referral bonus of $20 as long as you remain a customer for 90 days. If you do not wish to do so, please use this link. It costs the same either way, and I would be using Linode anyway as their service is superbly reliable.|