Navigation

Install using .tgz Tarball on Ubuntu

Overview

Although the recommended procedure to install is through the package manager, you can also install by directly downloading the .tgz file. The following tutorial downloads the .tgz tarball directly to install MongoDB 4.0 Community Edition on LTS Ubuntu Linux systems.

MongoDB Version

This tutorial installs MongoDB 4.0 Community Edition on LTS Ubuntu Linux systems. For other versions of MongoDB, refer to the corresponding version of the manual.

Platform Support

MongoDB only provides packages for the following 64-bit LTS (long-term support) Ubuntu releases:

  • 14.04 LTS (trusty)
  • 16.04 LTS (xenial)
  • 18.04 LTS (bionic)

See Supported Platforms for more information.

These packages may work with other Ubuntu releases; however, they are not supported.

Production Notes

Before deploying MongoDB in a production environment, consider the Production Notes document.

Prerequisites

Click on the tab for your version of Ubuntu

MongoDB .tar.gz tarballs require installing the following dependencies:

Install the dependencies for Ubuntu 14.04 (Trusty):

sudo apt-get install libcurl3 openssl

Package Updates required on Ubuntu 16.04 for IBM POWER Systems

Due to a lock elision bug present in older versions of the glibc package on Ubuntu 16.04 for POWER, you must upgrade the glibc package to at least glibc 2.23-0ubuntu5 before running MongoDB. Systems with older versions of the glibc package will experience database server crashes and misbehavior due to random memory corruption, and are unsuitable for production deployments of MongoDB

Install the dependencies for Ubuntu 16.04 (Xenial):

sudo apt-get install libcurl3 openssl

Install the dependencies for Ubuntu 18.04 (Bionic):

sudo apt-get install libcurl4 openssl

Install using the .tgz Tarball

1

Download the MongoDB .tgz tarball.

Download the tarball for your system from the MongoDB Download Center.

2

Extract the files from the downloaded archive.

Using an archive manager program or the tar command, extract the files.

For example, to extract from the terminal shell, you can use the following tar command:

Tip

If you downloaded a different MongoDB 4.0 point release, be sure to modify the command to reflect the correct .tgz file name.

tar -zxvf mongodb-linux-*-4.0.4.tgz
3

Optional. Ensure the binaries are in a directory listed in your PATH environment variable.

The MongoDB binaries are in the <mongodb-install-directory>/bin/ directory. To avoid having to specify the path to the MongoDB binaries, you can modify your user’s PATH environment variable to include this directory. For example, you can add the following line to your shell’s initialization script (e.g. ~/.bashrc):

export PATH=<mongodb-install-directory>/bin:$PATH

Replace <mongodb-install-directory> with the path to the extracted MongoDB archive.

Alternatively, you can:

  • Copy these binaries into a directory listed in your PATH variable such as /usr/local/bin, or
  • Create symbolic links to each of these binaries from a directory listed in your PATH variable.

Run MongoDB Community Edition

Production Notes
Before deploying MongoDB in a production environment, consider the Production Notes document.
ulimit Considerations
Most Unix-like operating systems limit the system resources that a session may use. These limits may negatively impact MongoDB operation. See UNIX ulimit Settings for more information.
Configuration
You can configure the MongoDB instance (such as the data directory and log directory specifications) using either the command-line options or a configuration file.

Note

Although the following procedure uses sudo to start the MongoDB instance as well as to create the directories used by the MongoDB instance, you may choose to perform the procedure as a different user.

1

Create the data and log directories.

Note

Depending on user permissions, you may need to sudo mkdir -p <directory> instead of mkdir -p <directory>. Use or omit sudo as appropriate. See your linux man pages for information on mkdir and sudo.

Create a directory where the MongoDB instance stores its data. For example:

sudo mkdir -p /data/db

Create a directory where the MongoDB instance stores its log. For example:

sudo mkdir -p /var/log/mongodb

The user that starts the MongoDB process must have read and write permission to the directories.

2

Run MongoDB.

To run MongoDB, run the mongod process at the system prompt.

sudo mongod --dbpath /data/db --logpath /var/log/mongodb/mongod.log --fork

For details on the command-line options --dbpath and --logpath, see Options.

3

Verify that MongoDB has started successfully.

Verify that MongoDB has started successfully by checking the process output for the following line in the log file /var/log/mongodb/mongod.log:

[initandlisten] waiting for connections on port 27017

You may see non-critical warnings in the process output. As long as you see the log line shown above, you can safely ignore these warnings during your initial evaluation of MongoDB.

4

Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. You can run the mongo shell without any command-line options to connect to a mongod that is running on your localhost with default port 27017:

mongo

For more information on connecting using the mongo shell, such as to connect to a mongod instance running on a different host and/or port, see The mongo Shell.

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See Getting Started for the available editions.