user7298979
user7298979

Reputation: 549

Best way to install R on Ubuntu 20.04?

Does anyone have a good approach to installing R on Ubuntu 20.04? I can't seem to find a solution for this specific to 20.04 focal through apt.

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:    20.04
Codename:   focal

Edit: after going through the link here and adding the entry to sources.list, I ran into issues with dependencies:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 r-base : Depends: r-base-core (>= 4.0.2-1.2004.0) but it is not going to be installed
          Depends: r-recommended (= 4.0.2-1.2004.0) but it is not going to be installed
          Recommends: r-base-html but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Per @DirkEddelbuettel's comment, I ran sudo apt install r-base-core r-recommended r-base-html to see next level dependencies:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 r-base-core : Depends: libblas3 but it is not installable or
                        libblas.so.3 but it is not installable
               Depends: liblapack3 but it is not installable or
                        liblapack.so.3 but it is not installable
               Depends: libtcl8.6 (>= 8.6.0) but it is not installable
               Depends: libtk8.6 (>= 8.6.0) but it is not installable
               Recommends: r-base-dev but it is not going to be installed
               Recommends: r-doc-html but it is not going to be installed
 r-recommended : Depends: r-cran-kernsmooth (>= 2.2.14) but it is not going to be installed
                 Depends: r-cran-mgcv (>= 1.1.5) but it is not going to be installed
                 Depends: r-cran-rpart (>= 3.1.20) but it is not going to be installed
                 Depends: r-cran-survival (>= 2.13.2-1) but it is not going to be installed
                 Depends: r-cran-matrix but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

There was a more underlying issue when I worked on trying to install r-base. I ended up finding out that I had problems with unmet dependencies after adding a PPA. I used this link here to fix the underlying problem of unmet dependencies, which in turn allowed me to apt install and not have any issues installing.

Upvotes: 4

Views: 6181

Answers (2)

THE_BLESSED_MEDIUM
THE_BLESSED_MEDIUM

Reputation: 1034

Prerequisites

You will need an Ubuntu 20.04 with:

at least 1GB of RAM a root user / non-root user with sudo privileges

Installing R

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

Note: CRAN maintains the repositories within their network, but not all external repositories are reliable. Be sure to install only from trusted sources.

Let’s first add the relevant GPG key.

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

Note that if you’re not using 20.04, you can find the relevant repository from the R Project Ubuntu list, named for each release. Ubuntu 20.04 is referred to as Focal Fossa, and the most recent version of R is 4.0.0, hence the naming convention of the repository below — focal-cran40.

sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

Now, we’ll need to run update after this in order to include package manifests from the new repository.

sudo apt update

At this point, we’re ready to install R with the following command.

sudo apt install r-base

If prompted to confirm installation, press y to continue.

Finally get into R shell-

sudo -i R

This confirms that we’ve successfully installed R and entered its interactive shell.

Upvotes: -1

Dirk is no longer here
Dirk is no longer here

Reputation: 368181

Here is what I do in the Rocker container r-ubuntu for the 20.04 image:

  1. Install software-properties-common to be able to say add-apt-repository

  2. Add the rrutter4.0 PPA for R itself (same as CRAN)
    add-apt-repository --enable-source --yes "ppa:marutter/rrutter4.0"

  3. Add the c4d4u.teams repo for over 4k CRAN packages:
    add-apt-repository --enable-source --yes "ppa:c2d4u.team/c2d4u4.0+"

  4. Run apt install r-base (and a few more).

In a narrow sense you only need 2 (as you likely do not 1 on a full Ubuntu system) and 4 but you may as well do 3.

You can of course also just to docker pull rocker/r-ubuntu:20.04 and get that container pre-made, but I use both: a container for tests, and these settings on my 20.04 machine(s).

Upvotes: 6

Related Questions