添加源
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
添加列表
ubuntu12.04
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
ubuntu14.04
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
ubuntu16.04
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
更新源
sudo apt-get update
安裝mongodb包
sudo apt-get install -y mongodb-org
安裝指定版本的mongodb
sudo apt-get install -y mongodb-org=3.2.8 mongodb-org-server=3.2.8 mongodb-org-shell=3.2.8 mongodb-org-mongos=3.2.8 mongodb-org-tools=3.2.8
命令
# 啟動(dòng)
sudo service mongod start
# 停止
sudo service mongod stop
# 重啟
sudo service mongod restart
確認(rèn)是否啟動(dòng)成功
# 查看日志
cat /var/log/mongodb/mongod.log
# 最后一行顯示
[initandlisten] waiting for connections on port 27017
卸載
# 停止mongodb
sudo service mongod stop
# 刪除包
sudo apt-get purge mongodb-org*
# 刪除數(shù)據(jù)庫(kù)
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb