在 ubuntu 20.04 LTS 中安装最新版本的 R 时出现问题

在 ubuntu 20.04 LTS 中安装最新版本的 R 时出现问题

我一直试图在 ubuntu 上安装 R 4.1,但每次都出现同样的错误

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

我查了一下,这似乎是一个常见问题,我尝试了所有建议的解决方案 - 卸载并重新安装 R,删除并重新创建一个新的 /etc/apt/sources.list 文件,恢复默认存储库,确保 focal-cran40 在 sources.list 上,更新并升级所有内容。但我仍然遇到同样的问题。这是我的代码

sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo apt update && sudo apt upgrade
sudo apt install r-base

以下是 apt-cache 策略的输出

sudo apt-cache policy r-base r-base-dev r-base-core r-recommended
r-base:
  Installed: (none)
  Candidate: 4.1.2-1.2004.0
  Version table:
     4.1.2-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.1.1-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.1.0-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.5-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.4-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.3-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.2-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.1-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.0-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
r-base-dev:
  Installed: (none)
  Candidate: 4.1.2-1.2004.0
  Version table:
     4.1.2-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.1.1-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.1.0-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.5-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.4-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.3-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.2-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.1-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.0-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
r-base-core:
  Installed: 3.6.3-2
  Candidate: 3.6.3-2
  Version table:
 *** 3.6.3-2 100
        100 /var/lib/dpkg/status
r-recommended:
  Installed: (none)
  Candidate: 4.1.2-1.2004.0
  Version table:
     4.1.2-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.1.1-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.1.0-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.5-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.4-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.3-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.2-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.1-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages
     4.0.0-1.2004.0 500
        500 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages

答案1

这可能是因为 source.lists 文件。我也遇到过同样的问题。按照官方的安装方法,您必须运行以下命令:

add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

如果你添加了多个存储库,这可能是你遇到此问题的原因。也许你应该编辑/etc/apt/source.lists并删除其他存储库,只保留唯一的官方存储库。

答案2

我遇到了同样的问题。看起来默认库的版本不兼容,特别是r-base-核心仅适用于 3.6.3-2 版本(使用 检查apt-cache show r-base-core

鉴于某些库在 4.x 版本中不可用,我决定使用以下代码安装 3.6 版本,并且它有效:

apt install r-recommended=3.6.3-2 r-base=3.6.3-2 r-base-dev=3.6.3-2

答案3

您是否尝试在 Ubuntu 上为 ARM64 安装 R?我在尝试在 arm64 机器上的 ubuntu 上安装 R 时遇到了同样的问题。我确实从源代码安装了 R。

相关内容