我们可以通过将以下代码放在shell脚本文件中来安装MongoDB
if [ ! -f /usr/bin/mongod ]; then<br>
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10<br>
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list<br>
sudo apt-get -y update
sudo apt-get install -y mongodb-org<br>
else
echo "mongo db already installed. Skipping..."
fi
答案 0 :(得分:0)
我只是做了一点改动,并在Ubuntu 18.04 LTS上进行了测试。
#!/bin/bash
if [ ! -f /usr/bin/mongod ]
then
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update -y
sudo apt-get install mongodb-org -y
sudo mkdir -p /data/db
sudo chown -R $USER /data/db
sudo chmod -R go+w /data/db
else
echo "mongo db already installed. Skipping..."
fi
mongod