在 Ubuntu 20.04 上安装 R 的最佳方式是啥?

Posted

技术标签:

【中文标题】在 Ubuntu 20.04 上安装 R 的最佳方式是啥?【英文标题】:Best way to install R on Ubuntu 20.04?在 Ubuntu 20.04 上安装 R 的最佳方式是什么? 【发布时间】:2020-10-17 04:36:23 【问题描述】:

有没有人有在 Ubuntu 20.04 上安装 R 的好方法?我似乎无法通过 apt 找到针对 20.04 焦点的特定解决方案。

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

编辑:通过链接here 并将条目添加到sources.list 后,我​​遇到了依赖项问题:

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.

根据@DirkEddelbuettel 的评论,我运行 sudo apt install r-base-core r-recommended r-base-html 来查看下一级依赖项:

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.

当我尝试安装 r-base 时,有一个更根本的问题。我最终发现在添加 PPA 后我遇到了未满足的依赖项问题。我使用此链接here 来解决未满足依赖项的潜在问题,这反过来又使我能够轻松安装并且没有任何安装问题。

【问题讨论】:

cloud.r-project.org/bin/linux/ubuntu/README.html 你尝试了什么命令?一般来说,sudo apt install r-base r-base-dev 应该可以工作 @HongOoi 我尝试通过将条目添加到 sources.list 来跟踪链接,运行 sudo apt-get update 和 sudo apt-get install r-base 并得到错误 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. @duckmayr 我也这么认为。它不应该像我想象的那么艰难 无论如何,您现在需要继续。将libblas3 liblapack3 libtcl8.6 libtk8.6 添加到同一行,看看你得到了什么。 这确实收敛。某处的某事造成了冲突。 (我是从几年前建成后每六个月升级一次的 20.04 系统打字的。) 【参考方案1】:

先决条件

您将需要一个 Ubuntu 20.04:

至少 1GB 内存 具有 sudo 权限的 root 用户/非 root 用户

安装 R

由于 R 是一个快速发展的项目,最新的稳定版本并不总是可以从 Ubuntu 的存储库中获得,因此我们将从添加由 CRAN 维护的外部存储库开始。

注意:CRAN 在其网络中维护存储库,但并非所有外部存储库都是可靠的。请务必仅从受信任的来源安装。

让我们先添加相关的 GPG 密钥。

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

请注意,如果您使用的不是 20.04,您可以从 R Project Ubuntu 列表中找到相关存储库,该列表为每个版本命名。 Ubuntu 20.04 被称为 Focal Fossa,而 R 的最新版本是 4.0.0,因此下面的存储库的命名约定是——focal-cran40。

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

现在,我们需要在此之后运行更新,以包含来自新存储库的包清单。

sudo apt update

此时,我们已准备好使用以下命令安装 R。

sudo apt install r-base

如果提示确认安装,请按 y 继续。

终于进入R shell-

sudo -i R

这确认我们已经成功安装了 R 并进入了它的交互式 shell。

【讨论】:

【参考方案2】:

这是我在Rocker container r-ubuntu for the 20.04 image 中所做的:

    安装software-properties-common可以说add-apt-repository

    为 R 本身添加 rrutter4.0 PPA(与 CRAN 相同)add-apt-repository --enable-source --yes "ppa:marutter/rrutter4.0"

    为超过 4k 的 CRAN 包添加 c4d4u.teams 存储库:add-apt-repository --enable-source --yes "ppa:c2d4u.team/c2d4u4.0+"

    运行apt install r-base(以及更多)。

从狭义上讲,您只需要 2 个(因为在完整的 Ubuntu 系统上您可能不需要 1 个)和 4 个,但您也可能需要 3 个。

当然,您也可以直接到 docker pull rocker/r-ubuntu:20.04 获取预制容器,但我同时使用:用于测试的容器和我的 20.04 机器上的这些设置。

【讨论】:

这正是我想要的。我遇到了另一个 apt 问题,它无法让我在 PPA 之后解决未满足的依赖关系。我解决了这个问题,遵循了这个,现在我安装了 R。我还测试了容器,效果非常好。谢谢。 很高兴听到它奏效了。如果在与另一个 PPA 的交互中需要学习一般性的课程,也许可以将其作为编辑添加到问题中?

以上是关于在 Ubuntu 20.04 上安装 R 的最佳方式是啥?的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu20.04下安装 R 及 CRAN 软件包(命令行操作)

在 Ubuntu 20.04 上安装 MySQL 5.6

ubuntu18.04/20.04 安装docker

Ubuntu server 20.04 关闭图形界面

无法在 Ubuntu 20.04 上安装 ROS Melodic

在 ubuntu 20.04LTS 上安装 pygame 的问题