Reference: http://blog.csdn.net/zhushh/article/details/52451441
1. Import the public key of the software source
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
2. Create a software source list file for MongoDB
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
3. Update the software source and install MongoDB
sudo apt-get updatesudo apt-get install -y mongodb-org
If you want to install a specific version, use the following command:
sudo apt-get Install-y mongodb-org=3.2.9 mongodb-org -server=3.2 .9 mongodb-org-shell=3.2.9 MongoDB -org-mongos= 3.2.9 mongodb-org-tools=3.2.9
4. Configure the boot file
If it is a ubuntu16.04 version, you need to create a new/lib/systemd/system/mongod.service file manually and write the following:
[Unit]Description=High-performance, schema-free document-oriented databaseAfter=network.targetDocumentation=https://docs.mongodb.org/manual[Service]User=mongodbGroup=mongodbExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf[Install]WantedBy=multi-user.target
5. Start, restart, and close commands
sudo service mongod startsudo service mongod restartsudo service mongod stop
Full Uninstall of 6.mongodb
Stop running MongoDB first
sudo service mongod stop
Uninstall the software again
sudo apt-get purge mongodb-org*
Delete database and log files
-r /var/log/mongodbsudo rm -r /var/lib/mongodb
7. Add the MongoDB extension of PHP
# pecl install mongodb# echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
Reference Links:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
http://mongodb.github.io/mongo-php-driver/
Ubuntu Install MongoDB