How To Install R on Ubuntu 18.04

How To Install R on Ubuntu 18.04

The R programming language is focused on graphics and statistical computing. This language is a key asset for developers as it is used to develop statistical software as well as perform data analysis.

Being one of the most popular languages, R offers user-friendly packages for certain different study areas, making it the easiest to use in many fields.

In this article, we will show you how to install R on Ubuntu 18.04 Bionic Beaver Linux.

Prerequisites

Before you start, make sure you have the following:

  • Ubuntu 18.04 server
  • 1GB of RAM
  • A non-root user (with Sudo privileges)

Once you have these requirements, you’re set to start.

Step 1 – Installing R

R project keeps on being updated, so the latest version may not always be available when searched in Ubuntu’s repositories. For this reason, it is recommended to begin the process using Comprehensive RArchive Network, CRAN to add the external repository.

CRAN, in this case, helps maintain the reliable repositories in a given network.

Here, you must be careful because not all third-party repositories are reliable. For this reason, always ensure you install CRAN only from reputable sources.

Start by adding the necessary GPG key.

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

Once you run this command, you should see the output below:

Executing: /tmp/apt-key-gpghome.4BZzh1TALq/gpg.1.sh--keyserverkeyserver.ubuntu.com--recv-keysE298A3A825C0D65DFD57CBB651716619E084DAB9
gpg: key51716619E084DAB9: publickey"Michael Rutter <marutter@gmail.com>"imported
gpg: Totalnumber processed: 1
gpg:               imported: 1

After acquiring the trusted key, now add the external repository. To find the required repository file, go to Ubuntu Packages for R list to see all the relevant repository for each releases.

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

From the information that shows on your screen, you should see the following lines:

...
Get:5https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ InRelease [3609 B]                 
...                    
Get:6https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages [21.0 kB]
...

Once you have identified these lines, run the update to include the manifests from the new repository.

$ sudo apt update

You should see the line below from the output:

...
Hit:2 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ InRelease
...

If you see this line after running the update command, then it means the new repository has been added successfully. This confirms that you have installed the latest version.

Now the platform is set, install R by running the command below:

$ sudo apt install r-base

You will be asked to confirm the installation, do so and press y to proceed.

At the time of compiling this article, the latest version of R according to CRAN is 3.5.1, which should appear once you run R.

Our plan is to install a sample package for every local user, so we will run R as root to make the libraries available to every user automatically.

Alternatively, run R command without sudo to set up a personal library for every user. To start the interactive shell of R as root, run the following command:

$ sudo -i R

You should have the following output:

 R version 3.5.1 (2024-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
Type 'demo()' for some demos, 'help()' foron-linehelp, or
'help.start()' foran HTML browser interface to help.
Type 'q()' to quit R.
>

This shows that R is installed successfully on your system. Now, let’s install R packages.

Now that you have successfully learned how to install R on Ubuntu system, it’s time to try if the process will work on your side.

Check out these top 3 VPS services:

Kamatera
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
Ultahost
$2.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to Create a Non-root User on Your Ubuntu 18.04 VPS or Dedicated Server

This guide shows you how to create a user on your Ubuntu 18.04 virtual server.
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Install a Self-Signed SSL Certificate on Your Ubuntu 18.04 VPS or Dedicated Server

This how-to article will teach you how to create a self-signed SSL certificate o
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Set Up Cron Jobs on Your Ubuntu 18.04 Dedicated Server or VPS

This guide shows webmasters and administrators how to set up cron jobs on your U
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install WordPress on Your Ubuntu 22.04 VPS or Dedicated Server

This tutorial will show you how to install WordPress on your Ubuntu 22.04 virtua
3 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top