Installing RStudio server

These are the minimal instructions on how to setup an RStudio server in an EC2 instance in AWS cloud server under Ubuntu. This requires more than just installing RStudio server. You need to also install R, TeX, and Git. Please see the RStudio website for further details on server installation, and administration.

The instructions below can be used to create a user called rstudio a directory, set a password and then change the permissions for this user’s home directory.

# Create a user, home directory and set password
sudo useradd rstudio
sudo mkdir /home/rstudio
sudo passwd rstudio
sudo chmod -R 0777 /home/rstudio

Even if you just created a new instance for an AMI in AWS, it is always good to make sure that there are no pending upgrades. The first command updates the database of versions current at the moment in the repositories. The second line actually does the upgrades.

# Update all files from the default state
sudo apt-get update
sudo apt-get upgrade

There is a copy of the R repository in the Ubuntu distribution repo, but it is not kept up-to-date in-between Ubuntu releases, so if we want to install the latest version, and later be able to get the latest upgrades we need to add to the repositories used CRAN itself. This is done by editing a text file, and in this example we use nano a very simple text editor.

# Add CRAN mirror to custom sources.list file using nano
sudo nano /etc/apt/sources.list.d/sources.list

#Add following line (or your favorite CRAN mirror)
deb precise/
# or
deb precise/

After adding the new repository, we need to update the database of available software again. This triggers an error that the comment in the instructions I used told to ignore.

# Update files to use CRAN mirror
# Don't worry about error message
sudo apt-get update

I do not like ignoring errors, specially related to checks of whether files have been damaged or tempered with before or during download. Getting the missing key (signature) is easy, so why not do it?

We can eliminate the error above by fetching the missing public key, just copy the KEYID at the end of the error message instead of KEYID in the command below.

sudo apt-key adv --keyserver --recv-keys KEYID
sudo apt-get update

Now we can easily install base R, what a normal user would need to start using R.

# Install latest version of R
# Install without verification
sudo apt-get install r-base

If we will build R itself from sources or develop our own packages we need to also install the “development” part of the R system.

# Install latest version of R development
# Install without verification
sudo apt-get install r-base-dev

Now can start R at the command line by typing “R”.

As most Unix and Linux commands are in lower case, if we rather call R using “r” we can install littler (little R)
[sudo apt-get install littler

Just in case we will download data using http protocol or want to parse XML files, as some R packages do, it is easier just to install the dependencies already at the start.

# Install in order to use RCurl & XML
sudo aptitude install libcurl4-openssl-dev
sudo apt-get install libxml2-dev

Now we should have a fully working version of R, which can be called at the command prompt in shell like sh or bash.

Next step is to install Git the version control system.

# Install git
sudo apt-get install git

Next step is to install a TeX distribution. Under Linux TeXLive is the standard distribution to use.

As with R, the TeXLive distribution in the Ubuntu repository is normally out-of-date. This is usually less of a problem, unless we plan to use LaTeX and TeX advanced or newer packages.

# Install TeXLive
sudo apt-get install texlive

Now we will install RStudio server itself, but RStudio uses a different installer system called gedebi that we first need to install.

# Install a few needed packages for installing RStudio
sudo apt-get install gdebi-core
sudo apt-get install libapparmor1

To install RStudio server, the process is a bit less automatic. We first download the installer and in a second step install it. We need to save this file to a folder where we (current user) have write rights. depending on whether we have a server running a 32 bit or 64 bit version on Ubuntu we download the i386 or the amd64 version of RStudio.

# Change to a writeable directory
# Download & Install RStudio Server
cd /tmp
sudo gdebi rstudio-server-0.98.1103-amd64.deb

We are done. We now test the server, which is started during installation. By default it listens to port 8787 instead of the default port 80 of http protocol. Before accessing the server, you will need to open port 8787 for incoming traffic in the firewall, or change the RStudio configuration to listen to port 80, and open this port. Opening the port in an EC2 instance is done through the AWS EC2 management console, to which we login with our normal Amazon credentials.

To install a review version of the RStudio server you simply need to copy the url to the latest preview, and use this for the install as above.
# For the preview check the link from the download page

# today (2015-03-13)
cd /tmp
sudo gdebi rstudio-server-0.99.332-amd64.deb

After this you may like to add additonal user using normal Linux commands. For example you can use adduser filling-in the rest of the information when prompted. In the example “aname” is the username we want to create. adduser also creates the home directory for the user.
sudo adduser aname

Users can change their own password using command passwd directly. Only root (the superuser) can change another user’s password or create new users. A normally logged-in user can run one command as root by starting the line with sudo. However, not all users of the system have enough rights to use sudo.

We can update the RStudio server by simply installing the latest version over the old installation. The process is fully automatic, even if there are users currently logged-in to RStudio with active sessions.

R itself is upgraded by means of upt-get at the same time as Ubuntu itself is upgraded, including security upgrades.

sudo apt-get update
sudo apt-get upgrade

Share with

Leave a Reply