How to install R-base Ubuntu 22.04 LTS Jammy

Learn the commands to install R- Base on Ubuntu 22.04 LTS Linux Jammy JellyFish, a free programming language for statistical calculations and graphics using the terminal.

Unlike Python, for example, which also enjoys a high degree of distribution in the field of data science, R is a language specially developed for statistical applications. Its core functions are the statistical evaluation and visualization of data.

Well, as compared to R language commercial competitors (such as SPSS) it doesn’t offer a fancy graphical user interface that allows the statistical functions to be called even without any programming knowledge. After downloading and installing R (obtained via one of the mirror servers of the CRAN), which is available for Windows, Linux, and macOS, the unsightly RGui only offers some very rudimentary functions for editing and executing R code and installing packages. To close the gap and developed more comfortable R editors. There is a platform called RStudio, it is an Integrated development environment GUI platform created for developers who are interested in the statistical programming language R.

The platform is available in both open-source and commercial editions, of course, the feature difference will be there. The paid version will have more extensive features than the open-source one. The software offers an editor with syntax highlighting, console, and direct code execution. Whereas those running the CLI server can use the Rstudio Server or RStudio Server Pro to access it via a web browser.

Steps to install R programming language on Ubuntu 22.04

The steps given here can be used for other versions of Ubuntu such as 18.04/20.04 including the Linux based on it such as POP_OS, Linux Mint, Elementary OS, and more…

1. Run system update

Let’s first start with the update command and along with the installation of a few other packages. Running of system update command will not only install the latest security updates but also refresh the APT package manager index cache.

sudo apt update
sudo apt install software-properties-common dirmngr

2. Add R project GPG key

The packages we install using the repository of the R project need to check by the system using the GPG key used by the developers of the R programming language to sign its packages.

wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

3. Add R-base repository

Although we can install the R-base programming language package using the standard repository of Ubuntu 22.04 without the help of some additional repository. However, the version of the programming language will not be the latest one.

In the screenshot you can see the difference:

Therefore to get the latest version we need to add the R-project repository manually. Here is the command to follow

sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

Again run the system update command after adding the repository.

sudo apt update

4. Install R programming language on Ubuntu 22.04

Finally, we can use our system’s Apt package manager to install the latest version of the R language on our Ubuntu 22.04.

sudo apt install r-base

To check the version, once the installation is completed, use:

R --version

Check R Base version

5. How to install R Packages

Once the base package of the R programming language is installed on our system, we can install the further packages to extend its capabilities. You can have a list of all packages on the Cran R-project page.

for example, if you want to create textbase plots then download a package called ‘txtplot’.

Switch to the R command line:

sudo -i R

Install the R Package called – txtplot

install.packages('txtplot')

Once the installation is completed, call it

library('txtplot')

Create a simple graph using the txtplot library. Here we are using the data that gives the speed of cars and the distances taken to stop recorded in the 1920s.

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

Text base plot

The above example will generate the graph on your command terminal. However, if you are using a graphical desktop then we can create a more interactive graph using ‘plot’.

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

GUI Plot using R Base langauge

To quite the R command line use:

q()

6. Update or upgrade

To receive and install the future updates of R Language on your system, simply use the update and upgrade command of Ubuntu using the APT package manager.

sudo apt update && sudo apt upgrade

7. Uninstall or Remove R language – Ubuntu 22.04

Maybe after some time, you don’t want this programming language anymore on your system. If that is the case, we can remove it using the given command:

sudo apt autoremove --purge r-base

To remove the repository and GPG key as well:

sudo add-apt-repository --remove "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
sudo rm /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

Other Articles:

Install PostgreSQL Server & Client on Ubuntu 22.04 LTS
Install FileZilla FTP Client on Ubuntu 22.04
How to install Thunderbird on Ubuntu 22.04

Leave a Comment