ubuntu16.04安装MongoDB Community Edition

方法1 . 下载安装包

适合网速较快的服务器,比如一些不限制带宽的服务器(例如一些国外的服务器)

1.下载安装包,并解压

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.4.5.tgz
tar -xzvf mongodb-linux-x86_64-ubuntu1604-3.4.5.tgz

2.把mongodb的bin目录添加到环境变量中

vi .bashrc
export PATH=$PATH:<mongodb-install-directory>/bin
source .bashrc

方法2 . 使用apt安装

官网说明:Ubuntu apt安装MongoDB官方文档

1.Import the public key used by the package management system

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

2.Create a list file for MongoDB

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

3.Reload local package database

sudo apt-get update

4.Install the MongoDB packages

sudo apt-get install -y mongodb-org

5.Using MongoDB

sudo service mongod start
sudo service mongod stop
sudo service mongod restart

6.Uninstall MongoDB

sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

方法3 . 使用清华大学开源软件镜像站

服务器上使用amd64架构安装包,可能会出错

1.下载deb文件:MongoDB Ubuntu Deb

wget https://mirrors.tuna.tsinghua.edu.cn/mongodb/apt/ubuntu/dists/xenial/mongodb-org/stable/multiverse/binary-amd64/mongodb-org-mongos_3.2.14_amd64.deb https://mirrors.tuna.tsinghua.edu.cn/mongodb/apt/ubuntu/dists/xenial/mongodb-org/stable/multiverse/binary-amd64/mongodb-org-server_3.2.14_amd64.deb https://mirrors.tuna.tsinghua.edu.cn/mongodb/apt/ubuntu/dists/xenial/mongodb-org/stable/multiverse/binary-amd64/mongodb-org-shell_3.2.14_amd64.deb https://mirrors.tuna.tsinghua.edu.cn/mongodb/apt/ubuntu/dists/xenial/mongodb-org/stable/multiverse/binary-amd64/mongodb-org-tools_3.2.14_amd64.deb https://mirrors.tuna.tsinghua.edu.cn/mongodb/apt/ubuntu/dists/xenial/mongodb-org/stable/multiverse/binary-amd64/mongodb-org_3.2.14_amd64.deb

2.命令行安装deb文件

sudo dpkg -i mongodb-org-mongos_3.2.14_amd64.deb mongodb-org-server_3.2.14_amd64.deb mongodb-org-shell_3.2.14_amd64.deb mongodb-org-tools_3.2.14_amd64.deb mongodb-org_3.2.14_amd64.deb

3.使用同方法二

    原文作者:七双叶
    原文地址: https://www.jianshu.com/p/1eff9b89189e
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞