Ubuntu

How to Install R and RStudio on Ubuntu 22.04

R is a popular programming language widely used by professional programmers and data scientists to create and analyse graphical representations. This programming language has a simple, well-developed, and fully-featured open-source programming environment which can be utilized to write codes in the R language.

This article is a guide on how to install R and RStudio on Ubuntu 22.04; let’s begin:

How to install R and RStudio on Ubuntu 22.04

In this tutorial, we will provide you step by step guidance to install R and RStudio on your Ubuntu 22.04 . Each step includes different commands which need to be executed to successfully run R and RStudio on Ubuntu 22.04. Let’s start discussing each step.

Step 1: First, you will require to update the packages list using the following commands:

$ sudo apt update
$ sudo apt upgrade

Step 2: Next, you must download the essential dependencies used for running R on Ubuntu 20.04 . This can be done through following command:

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

Step 3: After installing the required dependencies now to authenticate package, use:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

Step 4: Add the CRN repository using the following command:

$ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

Step 5: Once the above installation is completed, you can now run the R installation using the command.

$ sudo apt install r-base

If you encounter the libicu66 package error while installing R, you need to download the libicu66 package from the website. Once it is downloaded, go to the directory of the downloaded deb package using the following command.

$ cd ~/Downloads

You can install the package using the below given command.

$ sudo dpkg -i libicu66_66.1-2ubuntu2_amd64.deb

When the package installation is completed, you can then rerun the R installer again, and this time it will be installed on your Ubuntu 22.04 desktop.

Step 6: To check the R version, use the following command.

$ sudo -i R

Step 7: In the next step, let’s start running a simple R program to test whether the environment is working fine. We will use the txtplot library to output a graph which includes scatter plot, line plot, bar plot and much more.

First, use the “R” command in the terminal to run theenvironment and then use the following command to install txtplot.

install.packages('txtplot')

Then load the textplot in R as:

> library('txtplot')

Once the txtplot is loaded, execute the following code below to output a graph.

> txtplot(cars[,1], cars[,2])

You can also add labels to the x and y axis using the following command.

> txtplot(cars[,1], cars[,2], xlab = 'Speed', ylab = 'Distance')

This ensures that R is up and running on your Ubuntu 22.04 desktop. You can now write, text, and execute other codes of R programming language. You can find other codes from the GitHub website.

How to install RStudio on Ubuntu 22.04

RStudio is an IDE used for running codes written in R language. To install RStudio on Ubuntu 22.04, you will require the following steps.

Step 1: Execute the following command to download the RStudio deb package on Ubuntu 22.04.

$ wget https://download1.rstudio.org/desktop/bionic/amd64/rstudio-2022.02.1-461-amd64.deb

Step 3: Now use the following command to run the RStudio installation using dpkg.

$ sudo dpkg -i rstudio-2022.02.1-461-amd64.deb

This will install  RStudio on Ubuntu. Use the “rstudio” command in the terminal to run it or find it in the applications.

Conclusion

is a widely used programming language adopted mainly by data scientists to perform different operations like data analysis, graphics, statistical commutating, and more. The above installation steps will aid you in installing R on your Ubuntu 22.04 desktop and then you can write and execute different codes written in language directly onto the terminal.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.