1. Installing MongoDB
First step: Import the public key used by the package management system
Ubuntu package management tools (i.e. dpkg
, and apt
) ensure package consistency and authenticity by requiring the reseller to sign the package with GPG key. Issue the following command to import the MongoDB public GPG key:sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Step Two: Create a list file for MongoDB
First, to determine the version of the Ubuntu system you are using, to view the current kernel version, open the terminal and type the uname -r
command to view the kernel version:
View kernel version commands as follows:
[Email protected]:~$ uname-r
4.10.0-33-generic
Check whether the operating system is 32-bit or 64-bit:
[Email protected]:~$ sudo uname--m
x86_64
View Ubuntu version
[Email protected]:~$ sudo lsb_release-a
No LSB modules is available.
Distributor Id:ubuntu
Description:ubuntu 16.04.3 LTS
release:16.04
Codename:xenial
Create a list file using the commands that are appropriate for your Ubuntu version /etc/apt/sources.list.d/mongodb-org-3.4.list
:
Ubuntu 14.04:
$ echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
Ubuntu 16.04:
$ 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
Step three: Reload the local package database
Issue the following command to reload the local package database:
sudo apt-get update
Fourth Step: Install MongoDB Package
Install the latest stable version of MongoDB. Issue the following command:
sudo apt-get install -y mongodb-org
2. Running MongoDB
The MongoDB instance defaults to storing its data file in /var/lib/mongodb
its log file and /var/log/mongodb
running with the MongoDB user account. You can /etc/mongod.conf
specify the alternate log and data file directories in. For additional information, see Systemlog.path and Storage.dbpath.
If you change the user running the MongoDB process, you can modify /var/lib/mongodb
and /var/log/mongodb
access control permissions on the directory so that the user can access the directories.
Start MongoDB
Issue the following command to start MongoDB:
$ sudo service mongod start
Shell
Verify that MongoDB has started successfully
By checking /var/log/mongodb/mongod.log
the contents of the log file in to verify that the Mongod process started successfully, there should be a line content similar to the following in the journal file-
Test with MongoDB command-
Stop MongoDB
Depending on your needs, you can stop the Mongod process by issuing the following command:
sudo service mongod stop
Restart MongoDB
Issue the following command to restart Mongod:
sudo service mongod restart
Installing MongoDB under Ubuntu16.04lts