How to Install R Lang on Linux Mint 21/20

The R programming language is a versatile, open-source language primarily used for statistical computing and data analysis. Developed in 1993 by Ross Ihaka and Robert Gentleman, R has gained immense popularity among data scientists, statisticians, and researchers due to its robust capabilities and an extensive collection of packages.

Key Features of R Programming Language:

  • Open-source and Cross-platform: R is freely available under the GNU General Public License, which means users can access, modify, and distribute the source code. It is also cross-platform, allowing you to run R on various operating systems such as Windows, macOS, and Linux.
  • Extensive Libraries and Packages: With over 15,000 packages available in the Comprehensive R Archive Network (CRAN), R provides a wealth of tools for data manipulation, visualization, and statistical analysis. This vast library of packages enables users to perform various tasks and easily solve complex problems.
  • Powerful Data Analysis and Visualization: R is renowned for its excellent data analysis and visualization capabilities. Its core functionality facilitates data exploration, statistical modeling, and hypothesis testing. Additionally, the popular ggplot2 package makes it easy to create stunning and informative visualizations.
  • Active Community Support: R benefits from a large and engaged community of users and developers. The community regularly contributes to developing new packages, offers support through mailing lists and forums, and organizes conferences and workshops to share knowledge and expertise.
  • Integration with Other Languages: R can be easily integrated with other programming languages such as C, C++, Python, and Java, allowing you to utilize the best features of each language and expand R’s capabilities.
  • Reproducible Research: R enables you to create reproducible research by combining your code, data, and analysis in a single document using tools like R Markdown and knitr. This simplifies the process of sharing your work and ensures that others can easily replicate your results.

Now that we have a solid understanding of the R programming language, its features, and its applications, it’s time to get started. In the following guide, we will demonstrate how to install R programming language on Linux Mint 21 or Linux Mint 20 distribution using the latest R version from the CRAN repository with the command line terminal.

Section 1: Import R Lang Repository

In this section, we will guide you through the process of importing the R language repository and installing R on Linux Mint.

Step 1: Update Linux Mint System

To ensure all existing packages are up to date, update your Linux Mint operating system with the following command:

sudo apt update && sudo apt upgrade

Step 2: Install the Required Packages

Some dependencies are required for a successful installation. Install them using the following command:

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

Step 3: Import CRAN Repository

R is present in Linux Mint’s repositories by default, but the version is outdated. We recommend installing R from the CRAN repository for the most up-to-date version.

First, import the GPG key required to verify the authenticity of the R package:

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 and ensure you import the correct repository to match your Linux Mint distribution version:

Linux Mint 21:

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

Linux Mint 20:

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

Once imported, refresh your APT repository list:

sudo apt update

Section 2: Install R Lang on Linux Mint

In this section, we will cover the installation of the R programming language on Linux Mint and explore additional packages that you might find useful.

Step 1: Install R Programming Language

Once the CRAN repository has been imported, you can install the R programming language on your Linux Mint 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.

Step 2: Additional Installation Options

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

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

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

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

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 Linux Mint 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.

Section 3: Install R Packages from CRAN

This section will cover how to install, update, and remove R packages from CRAN on your Linux Mint system.

Step 1: Launch the R Interpreter

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.

Step 2: Install R Packages

For example, to install the data.table and shiny packages, enter the following command:

install.packages(c("data.table", "shiny"))

Step 3: Search for R Packages

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

available.packages("data visualization")

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

Step 4: Update R Packages

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.

Step 5: Remove R Packages

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

remove.packages("data.table")

With these steps, you now have the necessary knowledge to install, search, update, and remove R packages from CRAN on your Linux Mint system.

Conclusion: Installing R Programming Language on Linux Mint

In summary, installing the R programming language on Linux Mint is a straightforward process that involves importing the CRAN repository, updating your system, and installing the necessary packages. Following the steps outlined in this guide, you can successfully set up R on your Linux Mint system and begin working with powerful data analysis and statistical tools.

Additional Resources and Links

To further expand your knowledge and skills with R programming, here is a list of additional resources and official documentation:

  • The R Project for Statistical Computing: The official website of the R Project, which provides comprehensive information about the R programming language, including news, events, and downloads.
  • CRAN (Comprehensive R Archive Network): The official repository of R packages, where you can find, download, and contribute to a vast collection of R packages.
  • R Documentation: A platform aggregating official R documentation and user-contributed examples, making it easy to search and discover R functions and packages.
  • R Journal: The official, peer-reviewed, open-access journal of the R Project, which publishes articles related to R packages, applications, and development.

Share to...