1. 导入MongoDB的包公钥
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
2. 创建源列表文件
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
3. 更新软件源
sudo apt-get update
4. 安装MongoDB
sudo apt-get install -y mongodb-org
5. 查询版本号.
mongo --version
*********
如安装过程出现类似:
dpkg: error processing /var/cache/apt/archives/mongodb-org-server_4.2.1_amd64.deb
sudo dpkg -i --force-overwrite /var/cache/apt/archives/mongodb-org-server_4.2.1_amd64.deb sudo dpkg -i --force-overwrite /var/cache/apt/archives/mongodb-org-mongos_4.2.1_amd64.deb sudo dpkg -i --force-overwrite /var/cache/apt/archives/mongodb-org-tools_4.2.1_amd64.
然后重新修复安装即可
sudo apt-get -f install