How to Install R Lang on Ubuntu 22.04 or 20.04

R Programming Language is a powerful and flexible open-source programming language and environment for data analysis, statistics, and graphics. Its syntax is easy to learn, making it a popular choice among data scientists, statisticians, and researchers.

Here are some key features of the R Programming Language:

  • Open source: R is an open-source language, which means it is free to use and can be easily customized.
  • Wide range of statistical and graphical techniques: R offers an extensive library of statistical and graphical techniques, making it suitable for various data analysis tasks.
  • Cross-platform: R can run on Windows, Mac, and Linux, making it accessible to many users.
  • Data manipulation: R has built-in functions for data manipulation, such as merging, sorting, and reshaping data.
  • Reproducibility: R makes it easy to reproduce analyses and results, making it a popular choice for research and scientific studies.

R Programming Language was developed in the early 1990s by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand. Originally designed for statistical computing, R has grown in popularity and is now widely used in various industries, including finance, healthcare, and government.

Some of the areas where R Programming Language is used include:

  • Data analysis and statistics: R is widely used for statistical analysis and modeling, data visualization, and machine learning.
  • Academic research: R is a popular choice among researchers and academics for data analysis and visualization.
  • Finance: R is used extensively in the finance industry for risk analysis, portfolio management, and financial modeling.
  • Healthcare: R is used for data analysis, research, clinical trials, and predictive modeling.

This guide will demonstrate how to install R Programming Language on Ubuntu 22.04 Jammy Jellyfish or Ubuntu 20.04 Focal Fossa using the command line terminal and importing the official CRAN repository to install the latest version of R as Ubuntu’s repository version often falls far behind. Following these steps, you can start with R and use its powerful data analysis and statistics features.

Step 1: Import CRAN Repository

To install the latest version of R Programming Language on Ubuntu 22.04 Jammy Jellyfish or Ubuntu 20.04 Focal Fossa, the first step is to update your system to ensure all existing packages are up to date. Open the terminal and enter the following command:

sudo apt update && sudo apt upgrade

Next, you need to install the necessary packages to complete the installation by entering the following command:

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

By default, R is present in Ubuntu’s repositories. However, it can get outdated quickly, and installing R from the CRAN repository is highly recommended.

To import the GPG required to verify the R package’s authenticity, enter the following command:

curl -fSsL https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/cran.gpg >> /dev/null

Next, import the CRAN repository by entering the following command:

echo deb [signed-by=/usr/share/keyrings/cran.gpg] https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/ | sudo tee /etc/apt/sources.list.d/cran.list

Once the CRAN repository is imported, refresh your APT repository list by entering the following command:

sudo apt update

Step 2: Install R Programming Language

Once the CRAN repository has been imported, you can install R Programming Language on your Ubuntu system. Open the terminal and enter the following command:

sudo apt install r-base

This will install the base R system. If you want to install additional development tools and packages, you can also install r-base-dev by entering the following command:

 sudo apt install r-base r-base-dev

Once the installation is complete, you can verify its success by checking the build version. To do this, enter the following command in the terminal:

R --version

This command will display the R version and build information, indicating that the installation was successful.

Example of R terminal version printout on Ubuntu:

Additional Installation Options

Below are some additional packages that you may want to install:

  1. r-recommended: This package includes a set of recommended R packages commonly used in data analysis and statistical modeling.

The installation command for this package is:

sudo apt install r-recommended
  1. libssl-dev: This package is required if you plan to install packages from CRAN that require SSL (Secure Sockets Layer) encryption, such as the “httr” package.

The installation command for this package is:

sudo apt install libssl-dev
  1. libxml2-dev: This package is required if you plan to install packages from CRAN that require XML parsing, such as the “XML” package.

The installation command for this package is:

sudo apt install libxml2-dev
  1. libcurl4-openssl-dev: This package is required if you plan to install packages from CRAN that require CURL (Client URL) support, such as the “curl” package.

The installation command for this package is:

sudo apt install libcurl4-openssl-dev

Overall, installing these additional packages can greatly enhance the functionality of R on Ubuntu and allow it to interact with other software and tools more easily. Using the above installation commands; you can easily install these packages alongside “r-base” and “r-base-dev” using the CRAN repository.

Step 3: Install R Packages from CRAN

Now that you have successfully installed R Programming Language on your Ubuntu system, you can install R packages from CRAN.

To launch the R interpreter, open the terminal and enter the following command:

sudo -i R

This command will start the R interpreter as the root user. Once inside the R environment, you can install R packages by using the install.packages() function. For example, to install the dplyr package, enter the following command:

install.packages(c("ggplot2", "tidyr"))

Example output:

You can also search for packages available in the CRAN repository by using the available.packages() function. For example, to search for packages related to machine learning, enter the following command:

available.packages("machine learning")

This command will return a list of packages related to machine learning, along with their descriptions.

To update R packages installed on your system, use the update.packages() function. For example, to update all installed packages, enter the following command:

update.packages(ask = FALSE)

This command will update all installed packages without asking for confirmation.

To remove an R package, use the remove.packages() function. For example, to remove the dplyr package, enter the following command:

remove.packages("dplyr")

Conclusion

Installing R Programming Language on Ubuntu is a simple process that involves importing the CRAN repository and installing the R base system. R is an open-source language widely used in various industries, including finance, healthcare, and government. With its extensive library of statistical and graphical techniques, R is a popular choice among data scientists, statisticians, and researchers. By importing the CRAN repository and installing the latest version of R, you can take advantage of the latest features and updates and ensure that your R environment stays up-to-date.

Overall, R Programming Language is a powerful data analysis and statistics tool. By installing it on your Ubuntu system, you can unlock its full potential and use it to gain valuable insights from your data. Whether you’re an academic researcher, finance professional, or healthcare practitioner, R offers a range of tools and techniques to help you easily analyze and visualize your data.

Further Learning

To continue learning and exploring R Programming Language on Ubuntu, here are some useful resources and community links:

These resources provide a wealth of information and support for R Programming Language on Ubuntu, including forums for community discussion and collaboration, official documentation and tutorials, and R packages and libraries repositories. By exploring these resources, you can deepen your knowledge of R and stay up-to-date with the latest developments and best data analysis and statistics practices.

Share to...