在Debian上安装MongoDB,您可以按照以下步骤操作:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
对于MongoDB 4.4,请运行:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
对于MongoDB 4.2,请运行:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
请注意,您需要根据您的Debian版本替换focal
。例如,如果您使用的是Debian 11(Bullseye),则应将其替换为bullseye
。
sudo apt-get update
对于MongoDB 4.4,请运行:
sudo apt-get install -y mongodb-org
对于MongoDB 4.2,请运行:
sudo apt-get install -y mongodb-org=4.2.31 mongodb-org-server=4.2.31 mongodb-org-shell=4.2.31 mongodb-org-mongos=4.2.31 mongodb-org-tools=4.2.31
请注意,您需要根据您的需求选择正确的版本号。
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
现在,您已经在Debian上成功安装了MongoDB。您可以通过运行mongo
命令来启动MongoDB shell并开始使用MongoDB。