

Alternatively, if you run the R command without sudo, a personal library can be set up for your user. Since this tutorial will explore installing an example package for every user on the system, start R as root so that the libraries will be available to all users automatically. The -no-install-recommends arguments ensures that no extra packages are installed.Īs of the time of writing, the latest stable version of R from CRAN is 4.2.0, which is displayed when you start R. If prompted to confirm installation, press y to continue. sudo apt install -no-install-recommends r-base.Now you can be sure we won’t accidentally install an older version.Īt this point, you’re ready to install R with the following command. If the lines above appear in the output from the update command, you’ve successfully added the repository. Next, update your package lists so APT will read the new R source:Īmong the output that displays, you should identify lines similar to the following: The portion of the file instructs apt to use the key that you downloaded to verify repository and file information for R packages. echo "deb jammy-cran40/" | sudo tee -a /etc/apt//r-project.list.Next, add the R source list to the directory, where APT will search for new sources:

wget -qO- | sudo gpg -dearmor -o /usr/share/keyrings/r-project.gpg.First you’ll download the key with the wget command and convert it to a format that apt can use to verify downloaded packages using the gpg -dearmor command. To begin you’ll need to add the R project’s public GPG key to your server, and then configure the package repository. Be sure to install only from trusted sources.

Note: CRAN maintains the repositories within their network, but not all external repositories are reliable. Step 1 - Installing Rīecause R is a fast-moving project, the latest stable version isn’t always available from Ubuntu’s repositories, so you’ll start by adding the external repository maintained by CRAN. Once these prerequisites are in place, you’re ready to begin. To learn how to achieve this setup, follow our initial server setup guide. To follow along with this tutorial, you will need an Ubuntu 22.04 server with: In this tutorial, you will install R and show how to add packages from the official Comprehensive R Archive Network (CRAN). R offers many user-generated packages for specific areas of study, which makes it applicable to many fields. Supported by the R Foundation for Statistical Computing, it is an increasingly popular and extensible language with an active community. IntroductionĪn open-source programming language, R is widely used for performing data analysis and statistical computing. A previous version of this tutorial was written by Lisa Tagliaferri.
