How to Install R on Debian 11

R is an open-source programming language which is widely used for performing analysis and data visualization, along with developing statistical applications. It offers support for a plethora of packages that make it very useful in a wide array of fields. After getting through the initial learning curve, you can create effective and efficient data visualization to leave your users in awe. Let’s see how you can leverage the power given to you by R by installing it on Debian 11.

Update Systen

First lets update the system to make sure packages and dependencies are up to date before installation.

sudo apt update
sudo apt dist-upgrade

Installing R

The default package for R included in the Debian 11 repositories features an older stable version of R. In your terminal; you can use the following to install R:

sudo apt install r-base

For your reference the r-base package contains the main parts of the R programming language. The package is here, and the R programming language reference is here.

Voila with the apt install command R is installed now type the command R at the shell to open the interpeter:


R Lang Terminal

Running this command will launch R in your terminal and give you the current version installed (4.0.4). This confirms that R has been successfully installed on your Debian 11.

Run some simple R Program interactively

You can use basic variables and do arithmetic operations in R programming language, you can even do this interactively in the R terminal. Here is a simple code example for sum of 2 numbers.

x <- 3
y <- 4
z <- x+y

Sum 2 numbers in R shell

Basic If Else Conditional in R

We won’t teach R programming this post, but just to get you started a little, R has many common programming language features. We will demonstrate the IF ELSE conditional of R programming language in this example. Here is the code:

x <- 3
y <- 4

if (x+y>10) {
    print("Result is big")
} else {
    print("Result is not too big")

But running in interactive terminal R helps make a little less typing as shown below:

R Conditional IF ELSE

Run from Script

We can also run R programs from a script. Lets run code from above example in a script like this at the bash terminal using the Rscript command as shown here:

Rscript ./test.R

Run Rscript from command line


R is a programming language used for statistics and data science. It can be easily installed on Debian Linux as shown in this article and you can be writing code and running it in R in just minutes.

About the author

Linux Wolfman

Linux Wolfman is interested in Operating Systems, File Systems, Databases and Analytics and always watching for new technologies and trends. Reach me by tweeting to @linuxhint and ask for the Wolfman.