Skip to content

Instantly share code, notes, and snippets.

@jaeddy
Last active January 22, 2024 21:36
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jaeddy/5d564005c39aa608b4c28850e03fcb45 to your computer and use it in GitHub Desktop.
Save jaeddy/5d564005c39aa608b4c28850e03fcb45 to your computer and use it in GitHub Desktop.
steps for creating and configuring a new AMI with RStudio Server

Building a new RStudio Server AMI

The steps below can be followed to create a new AMI for use with Amazon EC2 instances that includes the latest versions of R, RStudio, and RStudio Server. The idea is inspired by the work of Louis Aslett, who creates and hosts his own public AMIs for RStudio. My own goal was to create an AMI with RStudio v1.0.0 or higher, such that I could use the recent R Notebooks feature. However, the instructions should generally apply for whenever you might be impatient accessing the latest version of R-related software on AWS (via an interactive browser interface...).

Getting started

  1. Create a new EC2 instance with the latest Ubuntu AMI (should be fine to do with Spot); based on Louis Aslett's AMI, I opted to include a general purpose SSD EBS volume with 10GB of storage space
  2. SSH into the instance

Downloading/installing RStudio Server

  1. Follow instructions here: https://www.rstudio.com/products/rstudio/download-server/
  2. Run the following command to verify installation:
sudo rstudio-server verify-installation
  1. Add default rstudio user (with password: rstudio) using the following command:
sudo adduser rstudio
  1. Verify rstudio user created with command:
cut -d : -f 1 /etc/passwd

Upgrading R

  1. Following instructions on this page (https://support.rstudio.com/hc/en-us/articles/200716773-Upgrading-the-Version-of-R-on-RStudio-Server), run the following commands:
sudo rstudio-server offline
sudo rstudio-server force-suspend-all
  1. Change the CRAN mirror and update R install using the commands below (taken from this post: https://askubuntu.com/questions/614530/how-to-install-latest-version-of-r-on-ubuntu-12-04-lts)
codename=$(lsb_release -c -s)
echo "deb http://cran.fhcrc.org/bin/linux/ubuntu $codename/" | sudo tee -a /etc/apt/sources.list > /dev/null
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo add-apt-repository ppa:marutter/rdev
sudo apt-get update
sudo apt-get upgrade
  1. Run this command to finish the process:
sudo rstudio-server online

Changing web port

  1. Following on instructions on this page (https://support.rstudio.com/hc/en-us/articles/200552316-Configuring-the-Server), edit /etc/rstudio/rserver.conf to include this line:
www-port=80
  1. Restart the server:
sudo rstudio-server restart

Installing R packages

  1. Install dependencies for tidyverse package:
sudo apt-get install -y \
    libcurl4-openssl-dev \
    libssl-dev \
    libxml2-dev && \
    sudo apt-get clean && \
    sudo apt-get purge && \
    sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
  1. Open R (via public IP for instance) and install tidyverse package as normal:
install.packages(“tidyverse”)
  1. Install devtools package as normal:
install.packages(“devtools”)
  1. Install Bioconductors packages:
source("https://bioconductor.org/biocLite.R”)
biocLite()

Creating AMI

  1. In EC2 Console, select current instance
  2. Under ‘Actions’, select ‘Image’ -> ‘Create Image’
  3. Provide name and description for AMI, hit the button to create image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment