sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Install MongoDB Community Edition on Ubuntu
On this page
- Overview
- Packages
- Install MongoDB Community Edition
- Run MongoDB Community Edition
- Uninstall MongoDB Community Edition
Overview
Use this tutorial to install MongoDB Community Edition on LTS Ubuntu Linux systems from.debpackages. 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 theglibcpackage on Ubuntu 16.04 for POWER,you must upgrade theglibcpackage to at leastglibc2.23-0ubuntu5before running MongoDB. Systems with older versions of theglibcpackage 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
|
AMetapackagethat will automatically install the four component packages listed below. |
| mongodb-org-server | Contains themongoddaemon 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-serverpackage provides an initialization script that startsmongodwith the/etc/mongod.confconfiguration file.
SeeRun MongoDB Community Editionfor details on using this initialization script.
These packages conflict with themongodb,mongodb-server,andmongodb-clientspackages provided by Ubuntu.
The default/etc/mongod.confconfiguration file supplied by the packages havebind_ipset to127.0.0.1by 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.dpkgandapt) 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.listlist 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/mongodband its log files in/var/log/mongodbby default,and runs using themongodbuser account. You can specify alternate log and data file directories in/etc/mongod.conf. SeesystemLog.pathandstorage.dbPathfor additional information.
If you change the user that runs the MongoDB process,youmustmodify the access control rights to the/var/lib/mongodband/var/log/mongodbdirectories to give this user access to these directories.
Start MongoDB.
Issue the following command to startmongod:
sudo service mongod start
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.logfor 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+Cin 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