Setting up an AWS instance for R, RStudio, OpenCPU, or Shiny Server 8

While most web-developers have worked with Amazon AWS, Microsoft Azure, or similar platforms before, this is still not the case for many R number crunchers. Especially researchers at academic institutions have less exposure to these commercial offerings. Time to change that!

In this post, we explain how to set up an Ubuntu server instance on AWS, and how to install R on it. In later posts, we will explain how to add RStudio server and Shiny Server Open Source.

Our main goal is to get you started quickly, so we ignore many of the useful options offered by AWS, such as e.g. security aspects.


You might as well chose another platform, and we do not claim that AWS is the best or the cheapest. So do let us know if you think there are reasons why some other cloud service is better suited for R developers.

For a start, depending on your use case, any of the following alternatives might be useful:

  • Another cloud service (Azure, Digital Ocean, Rackspace,  ElasticHost, etc.)
  • Docker (container on any machine, including an AWS instance, or on your development machine, be it Linux or Windows)
  • Or, also on AWS, you might take the fabulous RStudio Server AMI from here. This is a good choice if you only want to get started with RStudio Server as quickly as possible.

Step by step guide to create your AWS instance

Prerequisite: AWS account

If you do not have an AWS account yet, it’s time you get one here. You’ll get a free micro instance for a year or so. This means that you can run this tutorial at no cost. If you already have an AWS account, you’re ready for the next step: Creating an AWS instance.

1. Create AWS EC2 Ubuntu instance

Within the AWS management console, go to EC2 and create a new Ubuntu instance:

Click Select on the latest Ubuntu Server, and then click Review and Launch. Ignore the warnings about the security groups, we’ll worry about that later.

Next, the wizard will ask you about the key pair. The AWS key pair is needed to ssh into your Ubuntu instance, and we’ll use it later to connect to our AWS instance and install R. If you have created an EC2 instance before, you can re-use its keys. Otherwise, create and download a new key pair:

Save the *.pem file to your local disk. Then click Launch Instances

2. Connect to your Ubuntu cloud instance

The wizard will take you to the EC2 instances dashboard, where you’ll find your new instance, initially in a pending state. You can give it a name by clicking into the Name field (AWS Tutoril in the example below):

Once the Status Checks indicate that all checks are done, we are ready to connect to our instance: Select the instance and click on Connect. The browser displays detailed connection instructions, including a link to even more details. If your local machine is a Linux or Mac, you’re ready to go and you can follow directly the instructions provided by AWS.

Connect to your Ubuntu cloud instance from Windows

On Windows, you need an additional software, such as Putty, and you’ll need to convert your pem key file into a ppk file with puttygen. You’ll find detailed instructions in this EC2 installation guide.

If you follow through, upon first connection you’ll receive a security alert, looking like this:

You can – at least in the context of the hands-on tutorial – ignore it by clicking on Yes. If prompted for a user name, enter ubuntu.

3. Upgrade Ubuntu

What now follows is not specific to AWS. You would need to perform the following steps on any Ubuntu system, too.

You should now see a window that looks something like this:

Congrats, you’re connected to your AWS instance!

First thing you might want to do is to upgrade your system, by typing:

This will download and install the latest versions. When prompted, type Y. You might also get a screen like this:

I suggest to install the package maintainer’s version.

4. Installing R

Time to install R! Unfortunately, this is not as easy as it should be, but that’s due to Ubuntu, and not AWS. Anyway, it’s not that hard either. Specifically, to make sure that we get the latest R packages, we need to add a CRAN mirror to the sources.list file. And we need to install r-base. More details can be found here, but what you essentially want to do is this:

Between commands, hit Y if prompted.

Now you need to install R, by typing:

5. Running R on Ubuntu

Again, that’s not different than running R on any Ubuntu system. If you have done sudo su  as above, simply type

otherwise, type the following to start R as a super user:

If everything worked fine, you will see the latest version of R. At the time of this writing, this is R 3.2.2

And off you go! To quit, type

If you enjoyed this tutorial, come back for more.

In the next tutorial of the series, we’ll learn how to install Shiny Server on your AWS instance.

Leave a Reply

8 thoughts on “Setting up an AWS instance for R, RStudio, OpenCPU, or Shiny Server