sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Install MongoDB Community Edition on Ubuntu
On this page
Overview
Use this tutorial to install MongoDB Community Edition on LTS Ubuntu Linux systems from.deb
packages. While Ubuntu includes its own MongoDB packages,the official MongoDB Community Edition packages are generally more up-to-date.
PLATFORM SUPPORT
MongoDB only provides packages for 64-bit LTS (long-term support) Ubuntu releases. For example,12.04 LTS (precise),14.04 LTS (trusty),16.04 LTS (xenial),and so on. These packages may work with other Ubuntu releases,however,they are not supported.
PACKAGE UPDATES required ON UBUNTU 16.04 FOR IBM POWER SYSTEMS
Due to a lock elision bug present in older versions of theglibc
package on Ubuntu 16.04 for POWER,you must upgrade theglibc
package to at leastglibc2.23-0ubuntu5
before running MongoDB. Systems with older versions of theglibc
package will experience database server crashes and misbehavior due to random memory corruption,and are unsuitable for production deployments of MongoDB
MongoDB provides officially supported packages in their own repository. This repository contains the following packages:
Package Name | Description |
---|---|
mongodb-org |
AMetapackage that will automatically install the four component packages listed below. |
mongodb-org-server | Contains themongod daemon and associated configuration and init scripts. |
mongodb-org-mongos | Contains themongosdaemon. |
mongodb-org-shell | Contains themongoshell. |
mongodb-org-tools | Contains the following MongoDB tools:mongoimportbsondump,mongodump,mongoexport,mongofiles,mongooplog,mongoperf,mongorestore,mongostat,andmongotop. |
Themongodb-org-server
package provides an initialization script that startsmongodwith the/etc/mongod.conf
configuration file.
SeeRun MongoDB Community Editionfor details on using this initialization script.
These packages conflict with themongodb
,mongodb-server
,andmongodb-clients
packages provided by Ubuntu.
The default/etc/mongod.conf
configuration file supplied by the packages havebind_ip
set to127.0.0.1
by default. Modify this setting as needed for your environment before initializing areplica set.
To install a different version of MongoDB,please refer to that version’s documentation. For example,see version3.2.
MongoDB only provides packages for 64-bit LTS (long-term support) Ubuntu releases. For example,they are not supported.
Import the public key used by the package management system.
The Ubuntu package management tools (i.e.dpkg
andapt
) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import theMongoDB public GPG Key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Create a list file for MongoDB.
Create the/etc/apt/sources.list.d/mongodb-org-3.4.list
list file using the command appropriate for your version of Ubuntu:
- Ubuntu 12.04
-
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
- Ubuntu 14.04
-
- Ubuntu 16.04
3Reload local package database.
Issue the following command to reload the local package database:
sudo apt-get update
4Install the MongoDB packages.
Install the latest stable version of MongoDB.
Issue the following command:
sudo apt-get install -y mongodb-org
Most Unix-like operating systems limit the system resources that a session may use. These limits may negatively impact MongoDB operation. SeeUNIX ulimit Settingsfor more information.
The MongoDB instance stores its data files in/var/lib/mongodb
and its log files in/var/log/mongodb
by default,and runs using themongodb
user account. You can specify alternate log and data file directories in/etc/mongod.conf
. SeesystemLog.path
andstorage.dbPathfor additional information.
If you change the user that runs the MongoDB process,youmustmodify the access control rights to the/var/lib/mongodb
and/var/log/mongodb
directories to give this user access to these directories.
Verify that MongoDB has started successfully
Verify that themongodprocess has started successfully by checking the contents of the log file at/var/log/mongodb/mongod.log
for a line reading
[initandlisten] waiting for connections on port <port>
where<port>
is the port configured in/etc/mongod.conf
,0)">27017by default.
Stop MongoDB.
As needed,you can stop themongodprocess by issuing the following command:
sudo service mongod stop
Restart MongoDB.
Issue the following command to restartsudo service mongod restart
Begin using MongoDB.
To help you start using MongoDB,MongoDB providesGetting Started Guidesin varIoUs driver editions. SeeGetting Startedfor the available editions.
Before deploying MongoDB in a production environment,consider theProduction Notesdocument.
Later,to stop MongoDB,pressControl+C
in the terminal where themongodinstance is running.
To completely remove MongoDB from a system,you must remove the MongoDB applications themselves,the configuration files,and any directories containing data and logs. The following section guides you through the necessary steps.
This process willcompletelyremove MongoDB,its configuration,andalldatabases. This process is not reversible,so ensure that all of your configuration and data is backed up before proceeding.
Stop MongoDB.
Stop the 2
Remove Packages.
Remove any MongoDB packages that you had prevIoUsly installed.
sudo apt-get purge mongodb-org*
Remove Data Directories.
Remove MongoDB databases and log files.
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb