简体   繁体   中英

How can I install mongodb on Ubuntu 21.04?

我按照官方指南进行安装,但在检查状态时出现以下错误。

Active: failed (Result: core-dump) since

First remove previously installed files related to Mongodb

sudo service mongod stop 
sudo apt-get purge mongodb-org* 
sudo rm -r /var/log/mongodb 
sudo rm -r /var/lib/mongodb

After multiple install and uninstall I found the issue, with official guide, as of 13/08/2021 it does not have information on 21.04, but if you check in the command their only one thing is changing that is codename, 20.04 has focal, 18.04 bionic same way 21.04 has "hirsute"在此处输入图像描述

you can check this by typing in terminal "lsb_release -dc"

在此处输入图像描述

command with correct codename

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu hirsute/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod

run the able commands in order.

This works for me!

curl -fsSL https://www.mongodb.org/static/pgp/server-5.0.asc | \
    sudo tee /etc/apt/trusted.gpg.d/mongodb.asc > /dev/null
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 upgrade
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod

I installed like Harish suggested but left it with Focal when creating the apt source list instead of Hirsute. Got same error as OP. Looked at /var/log/mongodb, noticed no mongod.log had been created so I created mongod.log file under /var/log/mongodb, then changed the owner to mongodb for mongod.log, restarted the service for mongod and it worked.

sudo touch /var/log/mongodb/mongod.log
sudo chown mongodb:mongodb /var/log/mongodb/mongod.log
sudo systemctl restart mongod.service
sudo systemctl status mongod.service

目前,您可以按照 20.04 的安装指南进行操作,除了第 1 步 - 导入公钥之外,请改用以下内容:

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo tee /etc/apt/trusted.gpg.d/mongodb.asc > /dev/null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM