Install MongoDB
1
Import the public key used by the package management system.
The Ubuntu package management tools (i.e dpkg and apt) ensure package consistency and authenticity by requiring that Dist Ributors sign packages with GPG keys. Issue the following command to import the MongoDB public GPG Key:
sudo apt-key adv--keyserver hkp://keyserver.ubuntu.com:80--recv 7F0CEB10
2
Create a list file for MongoDB.
Create the/etc/apt/sources.list.d/mongodb-org-3.0.list list file using the following command:
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
3
Reload Local Package database.
Issue the following command to reload the local package database:
sudo apt-get update
4
Install the MongoDB packages.
You can install either the latest stable version of MongoDB or a specific version of MongoDB.
Install the latest stable version of MongoDB.
Issue the following command:
sudo apt-get install-y mongodb-org
Tip: If not successful, you can remove the command's-y. sudo apt-get install mongodb-org
Install a specific release of MongoDB.
Specify each component package individually and append the version number to the package name, as in the following example :
sudo apt-get install-y mongodb-org=3.0.0 mongodb-org-server=3.0.0 mongodb-org-shell=3.0.0 mongodb-org-mongos=3.0.0 mongodb-org-tools=3.0.0
Tip: If not successful, you can remove the command's-y.
sudo apt-get install mongodb-org=3.0.0 mongodb-org-server=3.0.0 mongodb-org-shell=3.0.0 mongodb-org-mongos=3.0.0 mongodb-org-tools=3.0.0
Pin a specific version of MongoDB.
Although can specify any available version of MongoDB, Apt-get would upgrade the packages when a newer version becomes Available. To prevent unintended upgrades, pin the package. To pin the version of MongoDB at the currently installed version, issue the following command sequence:
echo "Mongodb-org hold" | sudo dpkg--set-selections
echo "Mongodb-org-server hold" | sudo dpkg--set-selections
echo "Mongodb-org-shell hold" | sudo dpkg--set-selections
echo "Mongodb-org-mongos hold" | sudo dpkg--set-selections
echo "Mongodb-org-tools hold" | sudo dpkg--set-selections
Versions of the MongoDB packages before 2.6 use a different repo location. Refer to the version of the documentation appropriate for your MongoDB version.
Run MongoDB
The MongoDB instance stores its data files In/var/lib/mongodb and their log files In/var/log/mongodb by default, and runs Using the MongoDB user account. You can specify alternate log and data file directories in/etc/mongod.conf. See Systemlog.path and Storage.dbpath for additional information.
If you change the user of the runs the MongoDB process, you must modify the access control rights to The/var/lib/mongodb an D/var/log/mongodb directories to give this user access to these directories.
1
Start MongoDB.
Issue the following command to start Mongod:
sudo service Mongod start
2
Verify that MongoDB have started successfully
Verify that the Mongod process had started successfully by checking the contents of the log file At/var/log/mongodb/mongo D.log for a line reading
[Initandlisten] Waiting for connections on port <port>
Where <port> is the port configured in/etc/mongod.conf, 27017 by default.
3
Stop MongoDB.
As needed, you can stop the Mongod process by issuing the following command:
sudo service Mongod stop
4
Restart MongoDB.
Issue The following command to restart Mongod:
sudo service mongod restart
5
Begin using MongoDB.
To begin using MongoDB, see Getting Started with MongoDB. Also consider the Production Notes document before deploying MongoDB in a Production environment.
Later, to-stop MongoDB, press Control+c in the terminal where the Mongod instance is running.
Tips:
Open the MongoDB service Mongod and enter Mongod directly at the command terminal.
Open the MongoDB Client Command window MONGO and enter MONGO directly at the command terminal.
Installing MongoDB on Ubuntu