正在读这篇文章 https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/
我尝试在远程 ubuntu 18 上安装 mongodb,但出现错误:
root@nsn-do-lamp:~# wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
OK
root@nsn-do-lamp:~#
root@nsn-do-lamp:~# wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
OK
root@nsn-do-lamp:~# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse
root@nsn-do-lamp:~# sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mongodb-org
root@nsn-do-lamp:~# sudo apt-get update
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://ppa.launchpad.net/certbot/certbot/ubuntu bionic InRelease
Hit:3 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease
Hit:4 http://mirrors.digitalocean.com/ubuntu bionic InRelease
Hit:5 https://deb.nodesource.com/node_14.x bionic InRelease
Hit:6 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:7 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease
Hit:8 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease
Ign:9 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 InRelease
Get:10 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 Release [4412 B]
Get:11 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 Release.gpg [801 B]
Get:12 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0/multiverse amd64 Packages [6644 B]
Get:13 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0/multiverse arm64 Packages [5562 B]
Fetched 17.4 kB in 2s (9957 B/s)
Reading package lists... Done
root@nsn-do-lamp:~# sudo apt-get install -y mongodb-org
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:
mongodb-org : Depends: mongodb-org-database but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
...
root@nsn-do-lamp:~# uname -a
Linux nsn-do-lamp 4.15.0-191-generic #202-Ubuntu SMP Thu Aug 4 01:49:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
root@nsn-do-lamp:~# lsb_release -d; uname -r; uname -i
Description: Ubuntu 18.04.5 LTS
4.15.0-191-generic
x86_64
为什么我会收到这个错误?如何修复?
更新 :
我尝试使用建议的方法解决这个问题,但出现错误:
sudo apt-get install -y mongodb-org-mongos mongodb-org-server mongodb-org mongodb-org-database
...
The following packages have unmet dependencies:
mongodb-org-mongos : Depends: libc6 (>= 2.29) but 2.27-3ubuntu1.6 is to be installed
Depends: libgcc-s1 (>= 4.2) but it is not installable
mongodb-org-server : Depends: libc6 (>= 2.29) but 2.27-3ubuntu1.6 is to be installed
Depends: libgcc-s1 (>= 4.2) but it is not installable
E: Unable to correct problems, you have held broken packages.
看来我使用的是老版本的 ubuntu 18,这样可以缓解这个错误
我认为可以通过“安装特定版本的 MongoDB”选项来解决这个问题。
但我不确定我应该安装哪个版本的 MongoDB(如何找到它)?
谢谢!
答案1
在 Ubuntu 18.04 LTS 中安装 MongoDB 6.0:
首先,如果之前安装了 MongoDB,请将其删除:
sudo apt remove --autoremove mongodb-org
删除所有 mongodb repo 列表文件:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
添加新密钥:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
添加新的 repo:
echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
针对新的 repo 更新系统:
sudo apt update
安装 MongoDB 6.0:
sudo apt install mongodb-org
启用并启动 mongod 服务器服务:
systemctl enable mongod.service
systemctl start mongod.service
检查服务是否已经启动:
terrance@ubuntu-virtualbox:~$ systemctl status mongod.service
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-08-21 09:08:43 MDT; 9min ago
Docs: https://docs.mongodb.org/manual
Main PID: 1015 (mongod)
CGroup: /system.slice/mongod.service
└─1015 /usr/bin/mongod --config /etc/mongod.conf
Aug 21 09:08:43 ubuntu-virtualbox systemd[1]: Started MongoDB Database Server.
Aug 21 09:09:28 ubuntu-virtualbox systemd[1]: mongod.service: Current command vanished from the unit file, execution of the command list won't be resumed.
检查 MongoDB 服务器版本:
terrance@ubuntu-virtualbox:~$ mongos --version
mongos version v6.0.1
Build Info: {
"version": "6.0.1",
"gitVersion": "32f0f9c88dc44a2c8073a5bd47cf779d4bfdee6b",
"openSSLVersion": "OpenSSL 1.1.1 11 Sep 2018",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu1804",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
答案2
您忘记在以下时间之间重新加载源:
root@nsn-do-lamp:~# echo "deb ...
和
root@nsn-do-lamp:~# sudo apt-get install -y mongodb-org
按照步骤 2 所述执行
sudo apt update
然后它就会安装。注意gnupg
也需要安装。
root@nsn-do-lamp:~# sudo apt-get install -y mongodb-org”
这很糟糕:永远不要使用 root 身份和 sudo 登录。因此,如果您想使用 root 身份,请放弃 sudo。但我建议不要使用 root 身份,而是使用管理员用户和 sudo。
答案3
Monogodb 已安装,但缺少依赖项,就是这样,
每次你使用 wget 或 package install 遇到这个问题时,
添加此命令
apt-get install --fix-missing ; sudo apt-get install -f