Options to install R on a Raspberry Pi and other ARM systems
This started out as a section in some of my other posts but as installation options started to pile up it began to take too much space to be just a section in an article so I’ve decided to turn it into an article of its own.
The options described here are mostly applicable to the Raspberry Pi family of Single Board Computers but since most options also work on Ubuntu distributions they can also be applicable to other Linux ARM systems like other SBCs or even “full-size” ARM computers like Ampere Altra or AWS Graviton.
Install from the Operating System’s repositories
This is the easiest option, you can install R from the standard repositories for your OS, but those R versions are usually quite old, for example, the latest Raspberry Pi OS comes with R 4.2.2 and Ubuntu 22.04 comes with R 4.1.2.
To install R with this option you just need to run this command in your system terminal:
This is fine if you just want to try R or do simple stuff with it but if you are going to work on a serious project, chances are you want to start with an up-to-date version of R instead.
Compile R from source
Another option is to compile the latest R version yourself (4.3.1 at the moment of writing) from the source code files, this is a time-consuming task and it might feel a little intimidating for newcomers but it gives you the most flexibility when it comes to set compilation options, for example, you can choose options like compiling with BLAS and LAPACK to speed up matrix calculations.
You can compile R from source by running this script on a system terminal, it works for both Raspberry Pi OS and Ubuntu distributions:
# Set the R version to install
apt install -y g++ gcc gfortran libreadline-dev libx11-dev libxt-dev \
libpng-dev libjpeg-dev libcairo2-dev xvfb \
libbz2-dev libzstd-dev liblzma-dev libtiff5 \
libssh-dev libgit2-dev libcurl4-openssl-dev \
libblas-dev liblapack-dev libopenblas-base \
zlib1g-dev openjdk-11-jdk \
texinfo texlive texlive-fonts-extra \
screen wget libpcre2-dev make cmake
tar zxvf R-$R_VERSION.tar.gz
./configure --enable-R-shlib --enable-memory-profiling --with-blas --with-lapack #BLAS and LAPACK are optional
rm -rf R-$R_VERSION*
Install R using rig
rig is an R installation manager that allows you to install multiple R versions side by side, it has recently added support for Linux ARM64 systems through the
rstudio/r-builds GitHub repository, although, these builds are stated to be a community resource, they are not professionally supported by Posit. It currently supports only Ubuntu and Debian distributions (The latest Raspberry Pi OS version is based on Debian 12 so it is compatible too).
You can install
rig in your system by running this command on a system terminal:
Then you can install the latest stable R version with these commands:
Optionally, you can manually download and install R from R-hub as explained on the
rstudio/r-builds GitHub repository, but this is a more involved procedure only worthy if you are going to integrate this into your own infrastructure management workflow and you want to avoid the overhead of installing
Install R from the R4Pi Project
And last but not least, my new favorite, you can install R from the R4Pi project through its deb repository, which means you will always get R version updates just by running
sudo apt update && sudo apt upgrade. Currently supports both the legacy (Debian 11) and latest (Debian 12) Raspberry Pi OS versions but support for the latest version is 64-bits only. There is some experimental work to support Ubuntu 22.04 LTS arm64, but there is no public access yet.
To add the R4Pi deb repository to your deb source list and install R run these commands on a system terminal:
The main benefit of the R4Pi project is that it also provides R package repositories with precompiled binaries for a big selection of R packages which greatly reduces the time and effort required to install R packages on the Raspberry Pi, and by the way, you can also use the R4Pi package repository with all the previous installation options just by setting the “repos” option in a