• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install R on Ubuntu 22.04

Written by Admin, Updated On January 19, 2023
r, ubuntu
How to Install R on Ubuntu 22.04

R is an open-source, widely used and free programming language used for developing statistical software and performing data analysis. It is supported by the R Foundation for Statistical Computing. This tutorial explains how to install R on Ubuntu 22.04.

Prerequisites#

  • You should logged in as root or user account with sudo privileges.
  • Ubuntu 22.04 system should have at least 1 GB of RAM.

How to Install R on Ubuntu 22.04#

R is a fast-moving project, the latest stable version isn’t always available from Ubuntu repositories, so we’ll need to add the external repository maintained by CRAN.

Follow the below steps to install latest stable version of R on Ubuntu:

Step 1 – Install Dependencies#

First, you should install required packages to add new repository. Run following command to install dependencies:

sudo apt install apt-transport-https software-properties-common

Step 2 – Enable CRAN Repository#

Enable CRAN repository and add the CRAN GPG key to your system by issuing below command:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

Step 3 – Update Package Index#

Once the repository added you should update package list by typing:

sudo apt update

Step 4 – Install R#

Next issue below command to install R on Debian:

sudo apt install r-base

Step 5 – Verify Installation#

Verify the installation by running the following command which will print the R version:

R --version
R version 4.2.2 (2022-12-08) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
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.

>

Install R Packages from CRAN#

R has wide range of add-on packages through the Comprehensive R Archive Network (CRAN). You should install build-essential package which contains the tools required for compiling R Packages.

sudo apt install build-essential

For demonstration purposes, we will install stringr package which provides fast, correct implementations of common string manipulations.

Start by opening the R console as root:

sudo -i R

It will show as below:

R version 4.2.2 (2022-12-08) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
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.

>

To install stringr package, type:

install.packages("stringr")

Installation will take some time and after completion load library using:

library(stringr)

Let’s create a simple vector named demo:

demo <- c("How", "to", "Install", "R", "on", "Ubuntu", "22.04")

Now run the below command to print the length of a string:

str_length(demo)
[1] 3 2 7 1 2 6 5

If you want to install more packages you can find it at CRAN Packages.

Conclusion#

You have successfully learned how to install R on Ubuntu 22.04 Jemmy Jelifish.

If you have any problem or suggestion please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Change Hostname on Debian 11
Next Article   How to Install Composer on Debian 11

Related Posts

  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023
  • How to Install Memcached on Ubuntu 22.04

    How to Install Memcached on Ubuntu 22.04

    March 16, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook