ubuntu 安装mongoDB
ubuntu安装mongoDB
安装
# 1. 导入 MongoDB GPG 密钥
curl -fsSL https://pgp.mongodb.com/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
--dearmor
# 2. 尝试使用 jammy 仓库
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
# 3. 更新并安装
sudo apt-get update
sudo apt-get install -y mongodb-org验证安装
# 检查服务状态
sudo systemctl status mongod
# 启动 MongoDB 服务
sudo systemctl start mongod
# 设置开机自启
sudo systemctl enable mongod
# 检查版本
mongod --version
# 连接测试
mongosh
# 在 MongoDB Shell 中
> show dbs
> db.version()