MongoDB在Ubuntu 22.04上安装失败 - 依赖于libssl1.1,但无法安装。

以下是网站上的标准安装说明:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

sudo apt install -y mongodb-org
Reading package lists... Done
Building dependency tree... Done
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:
 mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but it is not installable
 mongodb-org-server : Depends: libssl1.1 (>= 1.1.1) but it is not installable
 mongodb-org-shell : Depends: libssl1.1 (>= 1.1.1) but it is not installable
E: Unable to correct problems, you have held broken packages.

我尝试直接安装依赖项,但似乎并没有解决这个问题。
sudo apt install libssl1.1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libssl1.1 is already the newest version (1.1.0g-2ubuntu4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
6个回答

编辑2022年12月

MongoDB 6.0现在可以从Jammy的mongodb软件库中安装,无需libssl1.1。

原始回答

目前MongoDb没有针对Ubuntu 22.04的官方版本。

Ubuntu 22.04已升级到libssl3,并不提供libssl1.1。

您可以通过添加Ubuntu 20.04源来强制安装libssl1.1:

echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list

sudo apt-get update
sudo apt-get install libssl1.1

然后使用您的命令安装mongodb-org。
然后删除您刚创建的focal-security列表文件。
sudo rm /etc/apt/sources.list.d/focal-security.list

11将整个安全仓库添加到不同版本的Ubuntu上,这样做不安全吗? - Aaron Franke
2目前我找不到其他的选择。无论如何,出于同样的考虑,在安装所需的软件包后,我立即删除了存储库条目... - Javier
另一种选择是将MongoDB安装为Docker容器,并转发相关端口。 - Artur Meinild
Libssl1.1让我能在PopOS 22.04上成功安装RStudio! - mccurcio
1@Javier,你介意加上删除仓库的命令吗? - TheTanic
2@TheTanic只需在“etc/apt/sources.list”中的存储库行上发表评论或删除即可。 - Javier
1在安装后,删除 /etc/apt/sources.list.d/ 目录下的 impish-security.list 文件。 - BOT_bkcd
4在我的安装中,存储库"没有Release文件",并将其禁用。 - JMCampos
4请注意,目前似乎无法访问淘气的软件库:您可以回退到使用Focal Fossa的软件库:echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list您可以使用任何其他尚未达到其生命周期结束(即End Of Life)的发行版,详情请参见此处 - Collado
1答案不正确。这是您从22.04得到的全部内容:E:存储库'http://security.ubuntu.com/ubuntu impish-security Release'没有发布文件。 - Seamus
1谢谢@Collado,我已经用focal更新了流程。 - Lionep
据我所知,MongoDB 4.4仍然需要libssl1.1,对吗? - Eli B.
你应该考虑从@128KB选择答案,这是正确的安全修复方法。 - Sharcoux
截至一月份,https://www.mongodb.com/try/download/community 上尚未提供Ubuntu 22.04的官方版本。 - fIwJlxSzApHEZIl
根据此帖子https://stackoverflow.com/a/76611493/11851843上的评论,使用tee -a而不是tee可以防止覆盖apt源文件。 - Titus Buckworth
@TitusBuckworth focal-security.list不是标准文件,尤其在jammy版本中。因此,没有使用"-a"选项的tee命令确保它是文件中唯一的一行。 然后,脚本可以“安全地”多次运行,其中"tee -a"将重复追加相同的行。 - Lionep
谢谢!我曾经使用同样的技巧在不再支持的Ubuntu 23.04上安装libssl1.1依赖项,以供dotnet 5.0 SDK使用。 - Efran Cobisi

Ubuntu 22.04目前还没有官方的MongoDB软件包,因此现在最好的选择是使用Ubuntu 20.04,因为官方的MongoDB软件包是可用的。

不建议在Ubuntu 22.04中使用任何解决方法来安装MongoDB,因为如果您要在生产环境中使用它,可能会导致问题。以下是对我有效的解决方法:

  1. 从官方仓库下载 libssl1.1_1.1.1f-1ubuntu2_amd64.deb

    wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
    
  2. 安装它:

    sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
    
  3. 继续安装 MongoDB:

    sudo apt-get install -y mongodb-org
    
这个解决方案来自MongoDB论坛,但我也添加了一些需要注意的注释。

2对于偶然发现这个问题的任何人:这也解决了Azure Speech SDK在Ubuntu 22.04上无法直接使用的问题。 - Fabien Snauwaert

wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
sudo dpkg -i ./libssl1.1_1.1.0g-2ubuntu4_amd64.deb
rm -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb

1这让我成功安装了Katrain。谢谢! - Kyle Baker
1我不得不使用http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb,但是这样就可以了。 - PenumbraBrah

新的官方(且安全)修复方法是:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc |  gpg --dearmor | sudo tee /usr/share/keyrings/mongodb.gpg > /dev/null
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update
sudo apt install mongodb-org

编辑:来源

官方的?来源是什么? - Michael Cole
1这是最好的和正确的答案。 - Chuma Umenze
@MichaelCole 给你添加了来源 - 128KB
答案已修正,以正确的密钥安装。 - Artur Meinild

@yehuda建议使用libssl1.1_1.1.0g,但它不符合依赖条件>=1.1.1。在此基础上,我尝试了以下方法,并且成功了。
根据Ubuntu提供的libssl软件包
  • bionic (18.04LTS)(libdevel):安全套接字层工具包 - 开发文件
    • 1.1.1-1ubuntu2.1~18.04.17 [安全更新]:amd64 i386
    • 1.1.0g-2ubuntu4 [端口]:arm64 armhf ppc64el s390x
  • bionic-updates(libdevel):安全套接字层工具包 - 开发文件
    • 1.1.1-1ubuntu2.1~18.04.17:amd64 arm64 armhf i386 ppc64el s390x
  • focal (20.04LTS)(libdevel):安全套接字层工具包 - 开发文件
    • 1.1.1f-1ubuntu2.13 [安全更新]:amd64 i386
    • 1.1.1f-1ubuntu2 [端口]:arm64 armhf ppc64el s390x
  • focal-updates(libdevel):安全套接字层工具包 - 开发文件
    • 1.1.1f-1ubuntu2.13:amd64 arm64 armhf i386 ppc64el s390x
  • impish (21.10)(libdevel):安全套接字层工具包 - 开发文件
    • 1.1.1l-1ubuntu1.3 [安全更新]:amd64 i386
    • 1.1.1l-1ubuntu1 [端口]:arm64 armhf ppc64el s390x
  • impish-updates(libdevel):安全套接字层工具包 - 开发文件
    • 1.1.1l-1ubuntu1.3:amd64 arm64 armhf i386 ppc64el s390x
http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/下载其中任何一个。 我选择 libssl1.1_1.1.1l-1ubuntu1.3_amd64.deb,因为我之前在Impish(21.10)中使用过这个。
cd ~/Downloads
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1l-1ubuntu1_amd64.deb
sudo dpkg -i ./libssl1.1_1.1.1l-1ubuntu1_amd64.deb
rm -i libssl1.1_1.1.1l-1ubuntu1_amd64.deb

1libssl1.1_1.1.1l-1ubuntu1_amd64.deb无法找到,返回"404 未找到"错误,但libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb适用于我,并且来自于20.04(Focal),这是当前官方支持的MongoDB版本。 - Bart

我不得不安装libssl-dev 1.1.1l以及libssl1.1.1l。
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
apt get update


wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1l-1ubuntu1.5_amd64.deb
dpkg -i libssl1.1_1.1.1l-1ubuntu1.5_amd64.deb
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl-dev_1.1.1l-1ubuntu1.5_amd64.deb
dpkg -i libssl-dev_1.1.1l-1ubuntu1.5_amd64.deb

apt install -y mongodb-org

对于像我一样尝试在Apple M1上运行Ubuntu虚拟机的人来说,可以使用ARM版本的Openssl二进制文件,方法如下:
wget http://ports.ubuntu.com/pool/main/o/openssl/libssl1.1_1.1.1l-1ubuntu1.5_arm64.deb
dpkg -i libssl1.1_1.1.1l-1ubuntu1.5_arm64.deb
wget http://ports.ubuntu.com/pool/main/o/openssl/libssl-dev_1.1.1l-1ubuntu1.5_arm64.deb
dpkg -i libssl-dev_1.1.1l-1ubuntu1.5_arm64.deb

apt-key已被弃用,请参考其他答案以迁移到gpg - sastorsl