Log inSign up

Running R and RStudio Server on a VPS

Add the CRAN repository for your Ubuntu or Debian release and install r-base, which gives you a current R that R --version confirms. Then download the RStudio Server package for your release from the Posit download page and install it with apt; the service listens on port 8787. Bind it to 127.0.0.1 and reach it through an SSH tunnel or an Nginx proxy with a Let's Encrypt certificate, logging in with a normal Linux account.

Topic: Go, Ruby, Java and other runtimes · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

Why run R on a server instead of a laptop?

A server keeps long analyses running after you close the lid, gives a team one shared environment, and sits close to data that already lives online. RStudio Server puts the familiar IDE in a browser tab, so collaborators need nothing installed locally. On BitcoinVPS you get full root on a KVM instance, which is what RStudio Server needs: a systemd service, PAM logins and local disk for project files.

Size the instance by your data, not by R itself. R holds data frames in memory, so a 2 GB plan handles modest datasets and package builds, while larger models want 4 to 8 GB. This page covers Ubuntu 24.04 and 22.04 and Debian 12 and 13.

How do you install current R from CRAN on Ubuntu?

The distribution packages lag behind, so add the repository maintained by the CRAN team. It tracks every R release for each supported Ubuntu version.

sudo apt update
sudo apt install -y --no-install-recommends software-properties-common dirmngr wget
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
sudo add-apt-repository -y "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
sudo apt install -y --no-install-recommends r-base r-base-dev
apt policy r-base

The apt policy output should show the candidate coming from cloud.r-project.org. r-base-dev brings compilers and headers, which you need because R packages on Linux usually install from source.

How do you install R from CRAN on Debian?

Debian uses its own CRAN directory and a different signing key. Fetch the key, add the source for your codename (bookworm for Debian 12, trixie for Debian 13) and install.

sudo apt update
sudo apt install -y gnupg dirmngr ca-certificates
gpg --keyserver keyserver.ubuntu.com --recv-key 95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7
gpg --armor --export 95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7 | sudo tee /etc/apt/trusted.gpg.d/cran_debian_key.asc
echo "deb https://cloud.r-project.org/bin/linux/debian $(. /etc/os-release; echo $VERSION_CODENAME)-cran40/" | sudo tee /etc/apt/sources.list.d/cran.list
sudo apt update
sudo apt install -y r-base r-base-dev

Confirm the result on either system with a quick check:

R --version
Rscript -e 'x <- rnorm(1e6); cat(mean(x), sd(x), "\n")'

Two numbers close to 0 and 1 mean the interpreter and its math libraries work.

Which system libraries do common R packages need?

Packages that talk to the web, read XML or draw graphics compile against C libraries, and the build stops with a clear error when one is missing. Installing the usual set up front saves several retries:

sudo apt install -y libcurl4-openssl-dev libssl-dev libxml2-dev \
  libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev \
  libpng-dev libtiff5-dev libjpeg-dev libgit2-dev

Then install packages as your own user; R offers to create a personal library under ~/R the first time:

Rscript -e 'install.packages(c("data.table", "ggplot2"), repos = "https://cloud.r-project.org")'

Compiling large packages such as the tidyverse takes a while on one or two vCPUs. Setting options(Ncpus = 2) in ~/.Rprofile builds several packages in parallel. Precompiled Linux binaries from the Posit Public Package Manager are another option if build time matters; point repos at its URL for your release.

How do you install RStudio Server?

Posit publishes RStudio Server as a .deb file per release family. Open the RStudio Server download page, choose the build for your system (the Ubuntu 22 build also covers Ubuntu 24.04; Debian has its own), copy the link and install it with apt, which resolves dependencies.

cd /tmp
RSTUDIO_DEB_URL="paste-the-link-from-the-download-page"
wget -O rstudio-server.deb "$RSTUDIO_DEB_URL"
sudo apt install -y ./rstudio-server.deb
sudo rstudio-server verify-installation
systemctl status rstudio-server --no-pager

Installing a newer .deb the same way later upgrades the server in place. Sessions that are open during an upgrade are suspended and resume on the next login.

How do you keep RStudio Server off the public internet?

Bind it to localhost so only a tunnel or a local proxy can reach it. Edit /etc/rstudio/rserver.conf:

www-address=127.0.0.1
www-port=8787
sudo systemctl restart rstudio-server
sudo ss -ltnp | grep 8787

For a single user, an SSH tunnel is the simplest secure route and needs no certificate. From your own computer run the command below and open http://localhost:8787 in a browser:

ssh -N -L 8787:127.0.0.1:8787 deploy@198.51.100.24

The tunnel rides on your SSH keys, so harden SSH as shown in SSH keys and hardening.

How do you publish it with Nginx and HTTPS?

For a team, put Nginx in front with a certificate. RStudio uses WebSockets, so the proxy must pass the upgrade headers and allow long-lived connections.

sudo apt install -y nginx certbot python3-certbot-nginx
sudo nano /etc/nginx/sites-available/rstudio
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
    listen 80;
    listen [::]:80;
    server_name rstudio.example.net;

    location / {
        proxy_pass http://127.0.0.1:8787;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 20d;
        client_max_body_size 200m;
    }
}
sudo ln -s /etc/nginx/sites-available/rstudio /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo certbot --nginx -d rstudio.example.net

Create the DNS record for rstudio.example.net first. Port 8787 stays closed in the firewall the whole time.

How do users log in?

RStudio Server authenticates against the Linux user database through PAM, so every analyst needs a normal account with a password. Accounts below UID 1000 are refused by default, which keeps system users out.

sudo adduser analyst
sudo passwd analyst

Use strong passwords, since the login page is reachable by anyone who knows the address. Adding Fail2ban with a filter for the RStudio log, or allowing only your office address in the firewall, cuts down on guessing attempts. Each user gets their own R library and project folders in their home directory.

How do you maintain and troubleshoot it?

R updates come with sudo apt upgrade. A new minor release, for example 4.5 to 4.6, uses a fresh personal library, so reinstall packages afterwards; patch releases keep the existing library. Useful commands:

sudo rstudio-server status
sudo rstudio-server active-sessions
sudo rstudio-server suspend-all
sudo rstudio-server restart
sudo journalctl -u rstudio-server -n 50 --no-pager
  • Grey screen or disconnects: WebSocket headers are missing in the proxy.
  • Login fails for a valid user: the account has no password or a UID under 1000.
  • Session crashes on large data: the process ran out of memory; check journalctl -k | grep -i oom and add swap or move to a larger plan.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A2-4everyday analysis for one or two users2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months
A4-8larger datasets and a small team4 vCPU, 8 GB RAM, 180 GB NVMe$28.80/mo$86.40 for 3 months

Questions about R and RStudio Server

Is RStudio Server free?

The open source edition is free under the AGPL license. A commercial edition adds features such as multiple R versions and single sign-on; this page covers the open source one.

Can I run RStudio Server on Rocky Linux or AlmaLinux?

Posit also ships RPM builds for the RHEL 9 family, and R itself comes from EPEL there. The steps on this page cover Ubuntu and Debian only.

How much memory does RStudio Server need?

The server itself is light, but every R session holds its data in RAM. Plan 2 GB for light work and 4 GB or more for real datasets.

Can several people use it at the same time?

Yes, each Linux user gets a separate session. Memory and vCPU are shared, so size the plan for the heaviest concurrent jobs.

How do I run R scripts on a schedule?

Call Rscript /path/to/job.R from a cron job or a systemd timer, using full paths and writing output to a log file.