1、环境更新
bash
sudo apt update
sudo apt upgrade
要执行curl命令,需先安装此包
bash
sudo apt-get install curl
2、生成MongoDB的gpg秘钥和向APT导入MongoDB7.0版软件包的资源链接
bash
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
3、下载MongoDB并安装
安装MongoDB前需要安装libssl1.1
bash
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
安装mongodb
bash
sudo apt-get install -y mongodb-org
4、启动MongoDB服务并设置开机启动和查询运行状态
bash
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod