How to Install R on Debian 10
3 min read
R is an open-source programming language and free environment that specializes in statistical computing and graphical representation. It is supported by the R Foundation for Statistical Computing and mainly used by statisticians and data miners for developing statistical software and performing data analysis.
This article provides information on how to install R on a Debian 10.
Ensure that you have met the following prerequisites before continuing with this tutorial:
- Debian 10 system with at least 1G of RAM. If your machine has less than 1GB of RAM, you can create a swap file .
- You are logged in as a user with sudo privileges .
Installing R on Debian
The R packages from the Debian repositories are often outdated. We’ll install R from the repository maintained by CRAN .
To install R on Debian 10, follow these steps:
The following steps describe how to install the latest stable version of R on Debian 10:
Install the packages necessary to add a new repository over HTTPS:
sudo apt install dirmngr apt-transport-https ca-certificates software-properties-common gnupg2
Run the following commands to enable the CRAN repository and add the CRAN GPG key to your system:
sudo apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/debian buster-cran35/'
Update the packages list and install the R package:
sudo apt update
sudo apt install r-base
Verify the installation by printing the R version:
At the time of writing this article, the latest stable version of R is version 3.6.3:
R version 3.6.3 (2020-02-29) -- "Holding the Windsock" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under the terms of the GNU General Public License versions 2 or 3. For more information about these matters see https://www.gnu.org/licenses/.
Installing R Packages from CRAN
One of the main reasons why R is so popular is the vide array of packages available through the Comprehensive R Archive Network (CRAN).
If you already don’t have installed, install the
build-essential package which contains the tools required for compiling R packages:
sudo apt install build-essential
R binary is launched as root or sudo the packages are installed globally and available for all system users. To set up a personal library for your user, invoke the binary as a regular user.
As an example, we’ll install a package named
stringr , which provides fast and correct implementations of common string manipulations.
Open the R console as root:
sudo -i R
R version 3.5.1 (2018-07-02) -- "Feather Spray" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >
The commands below are executed within the R console.
Installation will take some time. Once completed, load the library:
Create a simple character vector named
tutorial <- c("How", "to", "Install", "R", "on", "Debian", "9")
Run the following function which prints the length of a string:
 3 2 7 1 2 6 1
You can find more R packages at the CRAN Packages page, and install them with
We’ve shown you how to install R on Debian 10 and how to install R packages.
If you hit a problem or have feedback, leave a comment below.