How to Install R Programming Language on Debian 11 Bullseye

R is an open-source programming language and free software environment for statistical computing and graphical representation created and supported by the R Core Team and the R Foundation. R’s popularity is widely used amongst statisticians and data miners for statistical and data analysis software developers.

In the following tutorial, you will learn how to install R on Debian 11 Bullseye.

Prerequisites

  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo or root access.

Update Operating System

Update your Debian operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@debian~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on Adding a User to Sudoers on Debian.

To use the root account, use the following command with the root password to log in.

su

The tutorial will utilize the terminal for the installation found in Activities > Show Applications > Terminal.

Example:

How to Install R Programming Language on Debian 11 Bullseye

Install Dependecies for R

Before proceeding any further, you will need to open your terminal and use the following command to make sure the following dependencies are installed.

sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

Type “Y”, then press the “ENTER KEY” to proceed and complete the installation.

Import R GPG Key & CRAN Repository

By default, R is present in Debian 11’s repositories. However, it is very outdated. It is highly recommended to install R from the CRAN repository.

First, import the GPG key that is required the verify the authenticity of the R package.

apt-key adv --keyserver keyserver.ubuntu.com --recv-key '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7'

Next, import the CRAN repository.

sudo add-apt-repository 'deb http://cloud.r-project.org/bin/linux/debian bullseye-cran40/'

Once imported, refresh your APT repository list.

sudo apt update

Install R Programming Language

With the dependencies and the newly added CRAN repository installed, you can install the R language by executing the following command in your terminal.

sudo apt install r-base r-base-dev

Example output:

How to Install R Programming Language on Debian 11 Bullseye

Once the installation has finished, verify if it was successful by checking the build version.

R --version

Example output:

How to Install R Programming Language on Debian 11 Bullseye

How to Install R Packages from CRAN

Now that R is installed on your system, you can now launch the R terminal instance.

In your terminal, use the following command.

sudo -i R

Example out R terminal:

How to Install R Programming Language on Debian 11 Bullseye

R has quite an extensive range of packages that you can install. For the tutorial, the “txtplot” package returns ASCII graphs with “line plot, scatter plot, bar charts, and density plot.” This is installed by using the install.packages(”) command in R’s terminal shell.

install.packages('txtplot')

Example output:

How to Install R Programming Language on Debian 11 Bullseye

With “textplot” now installed, you can run a test by activating the package in the R shell terminal.

library('txtplot')

Next, an example is shown by using the example data supplied by R’s “datasets” package with contains the speed of cars and the distance required to stop based on data from the 1920s:

txtplot(cars[,1], cars[,2], xlab = 'speed', ylab = 'distance')

From this input command, you will then receive a plot graph.

Example:

How to Install R Programming Language on Debian 11 Bullseye

Additionally, to get help on the packages installed, you can use the following command.

help(package name)

Replace “package name” with the package installed. In the tutorial’s case, this was “txtplot”.

Example:

help(txtplot)

To remove a package, or “txtplot” use the following remove command in the R shell terminal.

remove.packages('txtplot')

To exit the R shell terminal interface, use the “q()” command.

q()

You will see the following prompt:

Save workspace image? [y/n/c]: 

Select your option to exit by typing y, n, or c and pressing the “ENTER KEY”.

Comments and Conclusion

In the tutorial, you have learned how to install R on Debian 11 Bullseye by using the CRAN repository, which you can draw upon packages and updates frequently.

One of the best parts about R programming is that it is more of a community-run software, which means that anyone can provide code enhancements and new packages. The consistency in the R community environment is a testament to this approach to developing specific software by sharing and encouraging inputs. This tool is also compatible across platforms, and thereby it runs on many operating systems as well as hardware.

Additionally, you can find more R packages at Available CRAN Packages By Name.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!