For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Install MongoDB Community on Linux

Select your distribution to view installation instructions for MongoDB Community Edition.

Note

By default, MongoDB Community Edition does not include MongoDB Search. To use MongoDB Search with MongoDB Community, you must install MongoDB Search with Docker or Linux separately.

Use this tutorial to install MongoDB 9.0 Community Edition on Red Hat Enterprise Linux, CentOS Linux, or Oracle Linux [1] using the YUM package manager.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

MongoDB 9.0 Community Edition supports the following 64-bit versions of Red Hat Enterprise Linux (RHEL), CentOS Linux, Oracle Linux [1], Rocky Linux, and AlmaLinux [2] on x86_64 architecture:

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 10

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 9

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 8

MongoDB only supports the 64-bit versions of these platforms.

MongoDB 9.0 Community Edition on RHEL / CentOS / Oracle / Rocky / AlmaLinux also supports the ARM64 architecture on select platforms.

See Platform Support for more information.

[1](1, 2) MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK).

[2] MongoDB on-premises products released for RHEL version 8.0+ are compatible with and supported on Rocky Linux version 8.0+ and AlmaLinux version 8.0+, contingent upon those distributions meeting their obligation to deliver full RHEL compatibility.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Follow these steps to install MongoDB Community Edition using the YUM package manager.

1

Create a /etc/yum.repos.d/mongodb-org-9.0.repo file so that you can install MongoDB directly using yum:

[mongodb-org-9.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/10/mongodb-org/9.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-9.asc

You can also download the .rpm files directly from the MongoDB repository. Downloads are organized by Red Hat / CentOS version (e.g. 9), then MongoDB release version (e.g. 9.0), then architecture (e.g. x86_64).

2

To install the latest stable version of MongoDB, issue the following command:

sudo yum install -y mongodb-org

Alternatively, to 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 yum install -y mongodb-org-9.0.0 mongodb-org-database-9.0.0 mongodb-org-server-9.0.0 mongodb-mongosh mongodb-org-mongos-9.0.0 mongodb-org-tools-9.0.0

Note

yum automatically upgrades packages when newer versions become available. If you want to prevent MongoDB upgrades, pin the package by adding the following exclude directive to your /etc/yum.conf file:

exclude=mongodb-org,mongodb-org-database,mongodb-org-server,mongodb-mongosh,mongodb-org-mongos,mongodb-org-tools

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

For details on default directories, see Default Data and Log Directory Paths.

To use a data directory and/or log directory other than the default directories:

  1. Create the new directory or directories.

  2. Edit the configuration file /etc/mongod.conf and modify the following fields accordingly:

    • storage.dbPath to specify a new data directory path (e.g. /some/data/directory)

    • systemLog.path to specify a new log file path (e.g. /some/log/directory/mongod.log)

  3. Ensure that the user running MongoDB has access to the directory or directories:

    sudo chown -R mongod:mongod <directory>

    If you change the user that runs the MongoDB process, you must give the new user access to these directories.

  4. Configure SELinux if enforced. See Configure the MongoDB SELinux Policy.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

For a complete list of packages, see MongoDB Community Edition Packages.

Use this tutorial to manually install MongoDB 9.0 Community Edition on Red Hat Enterprise Linux, CentOS Linux, or Oracle Linux [1] using a downloaded .tgz tarball.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the yum package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.

➤ See Install MongoDB using the yum Package Manager for instructions.

When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.

MongoDB 9.0 Community Edition supports the following 64-bit versions of Red Hat Enterprise Linux (RHEL), CentOS Linux, Oracle Linux [1], Rocky Linux, and AlmaLinux [2] on x86_64 architecture:

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 10

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 9

  • RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 8

MongoDB only supports the 64-bit versions of these platforms.

MongoDB 9.0 Community Edition on RHEL / CentOS / Oracle / Rocky / AlmaLinux also supports the ARM64 architecture on select platforms.

See Platform Support for more information.

[1](1, 2, 3, 4) MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK).

[2](1, 2) MongoDB on-premises products released for RHEL version 8.0+ are compatible with and supported on Rocky Linux version 8.0+ and AlmaLinux version 8.0+, contingent upon those distributions meeting their obligation to deliver full RHEL compatibility.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:

sudo yum install libcurl openssl xz-libs

Follow these steps to manually install MongoDB Community Edition from the .tgz.

1

After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:

➤

MongoDB Download Center

  1. In the Version dropdown, select the version of MongoDB to download.

  2. In the Platform dropdown, select your operating system version and architecture.

  3. In the Package dropdown, select tgz.

  4. Click Download.

2

For example, from a system shell, you can extract using the tar command:

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

The MongoDB binaries are in the bin/ directory of the tarball. You can either:

  • Copy the binaries into a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/the/mongodb-directory/ with your installation directory as appropriate)

    sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
  • Create symbolic links to the binaries from a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/the/mongodb-directory/ with your installation directory as appropriate):

    sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
4

Install mongosh then use the MongoDB Shell to connect to your deployment.

Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

By default, MongoDB runs using the mongod user account and uses the following default directories:

  • /var/lib/mongo (the data directory)

  • /var/log/mongodb (the log directory)

Create the MongoDB data and log directories:

sudo mkdir -p /var/lib/mongo
sudo mkdir -p /var/log/mongodb

By default, MongoDB runs using the mongod user account. Create a mongod and a mongodb group. Ensure that the mongod belongs to the group then set the owner and group of these directories to mongod:

sudo chown -R mongod:mongod /var/lib/mongo
sudo chown -R mongod:mongod /var/log/mongodb

To use a data directory and/or log directory other than the default directories:

  1. Create the new directory or directories.

  2. Edit the configuration file /etc/mongod.conf and modify the following fields accordingly:

    • storage.dbPath to specify a new data directory path (e.g. /some/data/directory)

    • systemLog.path to specify a new log file path (e.g. /some/log/directory/mongod.log)

  3. Ensure that the user running MongoDB has access to the directory or directories:

    sudo chown -R mongod:mongod <directory>

    If you change the user that runs the MongoDB process, you must give the new user access to these directories.

  4. Configure SELinux if enforced. See Configure the MongoDB SELinux Policy.

Follow these steps to run MongoDB Community Edition on your system. These instructions assume that you are using the default settings.

1

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

sudo mkdir -p /var/lib/mongo

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 these directories. For example, if you intend to run MongoDB as yourself:

sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
2

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

mongod --dbpath /var/lib/mongo --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 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

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

Use this tutorial to install MongoDB 9.0 Community Edition on LTS (long-term support) releases of Ubuntu Linux using the APT package manager.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

MongoDB 9.0 Community Edition supports the following 64-bit Ubuntu LTS (long-term support) releases on x86_64 architecture:

  • 26.04 LTS ("Resolute")

  • 24.04 LTS ("Noble")

  • 22.04 LTS ("Jammy")

MongoDB only supports the 64-bit versions of these platforms. To determine which Ubuntu release your host is running, run the following command on the host's terminal:

cat /etc/lsb-release

MongoDB 9.0 Community Edition on Ubuntu also supports the ARM64 architecture on select platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

To install MongoDB Community on your Ubuntu system, these instructions will use the official mongodb-org package, which is maintained and supported by MongoDB Inc. The official mongodb-org package always contains the latest version of MongoDB and is available from its own dedicated repo.

Important

The mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.

See MongoDB Community Edition Packages for the complete list of official packages.

Follow these steps to install MongoDB Community Edition using the APT package manager.

1

From a terminal, install gnupg and curl if they are not already available:

sudo apt-get install gnupg curl

To import the MongoDB public GPG key, run the following command:

curl -fsSL https://pgp.mongodb.com/server-9.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-9.gpg \
--dearmor
2

Create the list file /etc/apt/sources.list.d/mongodb-org-9.0.list for your version of Ubuntu.

Create the list file for Ubuntu 26.04 (Resolute):

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-9.gpg ] https://repo.mongodb.org/apt/ubuntu resolute/mongodb-org/9.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-9.0.list
3

Issue the following command to reload the local package database:

sudo apt-get update
4

You can install either the latest stable version of MongoDB or a specific version of MongoDB.

To install the latest stable version, issue the following

sudo apt-get install -y mongodb-org

For help with troubleshooting errors encountered while installing MongoDB on Ubuntu, see our troubleshooting guide.

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

For details on default directories, see Default Data and Log Directory Paths.

Follow these steps to run MongoDB Community Edition on your system. These instructions assume that you are using the official mongodb-org package -- not the unofficial mongodb package provided by Ubuntu -- and are using the default settings.

Init System

To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.

If you are unsure which init system your platform uses, run the following command:

ps --no-headers -o comm 1

Then select the appropriate tab below based on the result:

  • systemd - select the systemd (systemctl) tab below.

  • init - select the System V Init (service) tab below.

1

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Then run the start command above again.

2
sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod
3

As needed, you can stop the mongod process by issuing the following command:

sudo systemctl stop mongod
4

You can restart the mongod process by issuing the following command:

sudo systemctl restart mongod

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

5

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

For a complete list of packages, see MongoDB Community Edition Packages.

Use this tutorial to manually install MongoDB 9.0 Community Edition on LTS (long-term support) releases of Ubuntu Linux using a downloaded .tgz tarball.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the apt package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.

➤ See Install MongoDB using the apt Package Manager for instructions.

When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.

MongoDB 9.0 Community Edition supports the following 64-bit Ubuntu LTS (long-term support) releases on x86_64 architecture:

  • 26.04 LTS ("Resolute")

  • 24.04 LTS ("Noble")

  • 22.04 LTS ("Jammy")

MongoDB only supports the 64-bit versions of these platforms. To determine which Ubuntu release your host is running, run the following command on the host's terminal:

cat /etc/lsb-release

MongoDB 9.0 Community Edition on Ubuntu also supports the ARM64 architecture on select platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:

sudo apt-get install libcurl4 libgssapi-krb5-2 libldap2 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5

Follow these steps to manually install MongoDB Community Edition from the .tgz.

1

After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:

➤

MongoDB Download Center

  1. In the Version dropdown, select the version of MongoDB to download.

  2. In the Platform dropdown, select your operating system version and architecture.

  3. In the Package dropdown, select tgz.

  4. Click Download.

2

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 9.0 point release, be sure to modify the command to reflect the correct .tgz file name.

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

The MongoDB binaries are in the <mongodb-install-directory>/bin/ directory.

To avoid having to specify the path to the MongoDB binaries, you can create symbolic links to the binaries from a directory listed in your PATH variable, such as /usr/local/bin. Update /path/to/the/mongodb-directory/ with your installation directory as appropriate.

sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/

Alternatively, you can copy these binaries into a directory listed in your PATH variable such as /usr/local/bin.

sudo cp <mongodb-install-directory>/bin/* /usr/local/bin/
4

Install mongosh then use the MongoDB Shell to connect to your deployment.

Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

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.

Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.

1

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

sudo mkdir -p /var/lib/mongo

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 these directories. For example, if you intend to run MongoDB as yourself:

sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
2

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

mongod --dbpath /var/lib/mongo --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 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

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

Note

MongoDB Atlas

MongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free cluster to get started.

Use this tutorial to install MongoDB 9.0 Community Edition using the APT package manager.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

MongoDB 9.0 Community Edition supports the following 64-bit Debian releases on x86_64 architecture:

  • Debian 13 "Trixie"

MongoDB only supports the 64-bit versions of these platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

To install MongoDB Community on your Debian system, these instructions will use the official mongodb-org package, which is maintained and supported by MongoDB Inc. The official mongodb-org package always contains the latest version of MongoDB and is available from its own dedicated repo.

Important

The mongodb package provided by Debian is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you already installed the mongodb package on your Debian system, you must first uninstall the mongodb package before proceeding with these instructions.

See MongoDB Community Edition Packages for the complete list of official packages.

Follow these steps to install MongoDB Community Edition using the APT package manager.

1

From a terminal, install gnupg and curl if they are not already available:

sudo apt-get install gnupg curl

To import the MongoDB public GPG key, run the following command:

curl -fsSL https://pgp.mongodb.com/server-9.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-9.gpg \
--dearmor
2

Create the list file for Debian 13 (Trixie):

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-9.gpg ] https://repo.mongodb.org/apt/debian trixie/mongodb-org/9.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-9.0.list
3

Issue the following command to reload the local package database:

sudo apt-get update
4

You can install either the latest stable version of MongoDB or a specific version of MongoDB.

To install the latest stable version, issue the following

sudo apt-get install -y mongodb-org

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

For details on default directories, see Default Data and Log Directory Paths.

Follow these steps to run MongoDB Community Edition on your system. These instructions assume that you are using the official mongodb-org package -- not the unofficial mongodb package provided by Debian -- and are using the default settings.

Init System

To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.

If you are unsure which init system your platform uses, run the following command:

ps --no-headers -o comm 1

Then select the appropriate tab below based on the result:

  • systemd - select the systemd (systemctl) tab below.

  • init - select the System V Init (service) tab below.

1

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Then run the start command above again.

2
sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod
3

As needed, you can stop the mongod process by issuing the following command:

sudo systemctl stop mongod
4

You can restart the mongod process by issuing the following command:

sudo systemctl restart mongod

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

5

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

For a complete list of packages, see MongoDB Community Edition Packages.

Use this tutorial to manually install MongoDB 9.0 Community Edition on Debian Linux using a downloaded .tgz tarball.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the apt package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.

➤ See Install MongoDB using the apt Package Manager for instructions.

When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.

MongoDB 9.0 Community Edition supports the following 64-bit Debian releases on x86_64 architecture:

  • Debian 13 "Trixie"

MongoDB only supports the 64-bit versions of these platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:

sudo apt-get install libcurl4 libgssapi-krb5-2 libldap-common libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5

Follow these steps to manually install MongoDB Community Edition from the .tgz.

1

After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:

➤

MongoDB Download Center

  1. In the Version dropdown, select the version of MongoDB to download.

  2. In the Platform dropdown, select your operating system version and architecture.

  3. In the Package dropdown, select tgz.

  4. Click Download.

2

For example, from a system shell, you can extract using the tar command:

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

The MongoDB binaries are in the bin/ directory of the tarball. You can either:

  • Copy the binaries into a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/the/mongodb-directory/ with your installation directory as appropriate)

    sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
  • Create symbolic links to the binaries from a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/the/mongodb-directory/ with your installation directory as appropriate):

    sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
4

Install mongosh then use the MongoDB Shell to connect to your deployment.

Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

By default, a MongoDB instance stores:

  • its data files in /var/lib/mongodb

  • its log files in /var/log/mongodb

If you installed using the package manager, these default directories are created during installation.

If you installed manually by downloading the tarballs, create the directories using mkdir -p <directory> or sudo mkdir -p <directory> depending on the user that will run MongoDB. See your linux man pages for information on mkdir and sudo.

By default, MongoDB runs using the mongodb user account. If you change the user that runs the MongoDB process, you must also modify the permission to the /var/lib/mongodb and /var/log/mongodb directories to give this user access to these directories.

To specify a different log file directory and data file directory, edit the systemLog.path and storage.dbPath settings in the /etc/mongod.conf. Ensure that the user running MongoDB has access to these directories.

Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.

1

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

sudo mkdir -p /var/lib/mongo

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 these directories. For example, if you intend to run MongoDB as yourself:

sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
2

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

mongod --dbpath /var/lib/mongo --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 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

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

Use this tutorial to install MongoDB 9.0 Community Edition on SUSE Linux Enterprise Server (SLES) using the ZYpp package manager.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

MongoDB 9.0 Community Edition supports the following 64-bit SUSE Linux Enterprise Server (SLES) releases on x86_64 architecture:

  • SLES 15

  • SLES 16

MongoDB only supports the 64-bit versions of these platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Follow these steps to install MongoDB Community Edition using the ZYpp package manager.

1
sudo rpm --import https://pgp.mongodb.com/server-9.asc
2

Select the tab for your version of SUSE:

To add the repository file for SUSE Enterprise Linux 16, run the following command:

sudo zypper addrepo --gpgcheck "https://repo.mongodb.org/zypper/suse/16/mongodb-org/9.0/x86_64/" mongodb
3

You can install either the latest stable release of MongoDB or a specific release of MongoDB.

To install the latest version of MongoDB, run the following command:

sudo zypper -n install mongodb-org

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

For details on default directories, see Default Data and Log Directory Paths.

Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.

Init System

To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.

If you are unsure which init system your platform uses, run the following command:

ps --no-headers -o comm 1

Then select the appropriate tab below based on the result:

  • systemd - select the systemd (systemctl) tab below.

  • init - select the System V Init (service) tab below.

1

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Then run the start command above again.

2

You can verify that the mongod process has started successfully by issuing the following command:

sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod
3

As needed, you can stop the mongod process by issuing the following command:

sudo systemctl stop mongod
4

You can restart the mongod process by issuing the following command:

sudo systemctl restart mongod

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

5

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

For a complete list of packages, see MongoDB Community Edition Packages.

Use this tutorial to manually install MongoDB 9.0 Community Edition on SUSE Linux Enterprise Server (SLES) using a downloaded .tgz tarball.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the zypper package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.

➤ See Install MongoDB using the zypper Package Manager for instructions.

When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.

MongoDB 9.0 Community Edition supports the following 64-bit SUSE Linux Enterprise Server (SLES) releases on x86_64 architecture:

  • SLES 15

  • SLES 16

MongoDB only supports the 64-bit versions of these platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:

sudo zypper install libcurl4 libopenssl1_1

Follow these steps to manually install MongoDB Community Edition from the .tgz.

1

After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:

➤

MongoDB Download Center

  1. In the Version dropdown, select the version of MongoDB to download.

  2. In the Platform dropdown, select your operating system version and architecture.

  3. In the Package dropdown, select tgz.

  4. Click Download.

2

For example, from a system shell, you can extract using the tar command:

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

The MongoDB binaries are in the bin/ directory of the tarball. You can either:

  • Copy the binaries into a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/the/mongodb-directory/ with your installation directory as appropriate)

    sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
  • Create symbolic links to the binaries from a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/the/mongodb-directory/ with your installation directory as appropriate):

    sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
4

Install mongosh then use the MongoDB Shell to connect to your deployment.

Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.

Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.

1

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

sudo mkdir -p /var/lib/mongo

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 these directories. For example, if you intend to run MongoDB as yourself:

sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
2

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

mongod --dbpath /var/lib/mongo --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 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

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

Use this tutorial to install MongoDB 9.0 Community Edition on Amazon Linux using the YUM package manager.

You can verify which Linux distribution you are running by running the following command on the command-line:

grep ^NAME /etc/*release

The result should be Amazon Linux or Amazon Linux AMI. If using a different Linux distribution, please see the install instructions for your platform.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

MongoDB 9.0 Community Edition supports the following 64-bit Amazon Linux release on x86_64 architecture:

  • Amazon Linux 2023

MongoDB only supports the 64-bit versions of this platform.

MongoDB 9.0 Community Edition on Amazon Linux also supports the ARM64 architecture on select platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Follow these steps to install MongoDB Community Edition using the YUM package manager. Select the tab for your version of Amazon Linux:

1

Create a /etc/yum.repos.d/mongodb-org-9.0.repo file so that you can install MongoDB directly using yum:

[mongodb-org-9.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/9.0/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-9.asc

You can also download the .rpm files directly from the MongoDB repository. Downloads are organized by Amazon Linux 2023 version (for example, 2023), then MongoDB version (9.0), then architecture (x86_64 or aarch64).

2

To install the latest stable version of MongoDB, run the following command:

sudo yum install -y mongodb-org

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

For details on default directories, see Default Data and Log Directory Paths.

Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.

Init System

To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.

If you are unsure which init system your platform uses, run the following command:

ps --no-headers -o comm 1

Then select the appropriate tab below based on the result:

  • systemd - select the systemd (systemctl) tab below.

  • init - select the System V Init (service) tab below.

1

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Then run the start command above again.

2

You can verify that the mongod process has started successfully by issuing the following command:

sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod
3

As needed, you can stop the mongod process by issuing the following command:

sudo systemctl stop mongod
4

You can restart the mongod process by issuing the following command:

sudo systemctl restart mongod

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

5

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

For a complete list of packages, see MongoDB Community Edition Packages.

Use this tutorial to manually install MongoDB 9.0 Community Edition on Amazon Linux using a downloaded .tgz tarball.

You can verify which Linux distribution you are running by running the following command on the command-line:

grep ^NAME /etc/*release

The result should be Amazon Linux or Amazon Linux AMI. If using a different Linux distribution, please see the install instructions for your platform.

This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the yum package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.

➤ See Install MongoDB using the yum Package Manager for instructions.

When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.

MongoDB 9.0 Community Edition supports the following 64-bit Amazon Linux release on x86_64 architecture:

  • Amazon Linux 2023

MongoDB only supports the 64-bit versions of this platform.

MongoDB 9.0 Community Edition on Amazon Linux also supports the ARM64 architecture on select platforms.

See Platform Support for more information.

Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.

Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:

sudo yum install libcurl openssl xz-libs

Follow these steps to manually install MongoDB Community Edition from the .tgz.

1

After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:

➤

MongoDB Download Center

  1. In the Version dropdown, select the version of MongoDB to download.

  2. In the Platform dropdown, select your operating system version and architecture.

  3. In the Package dropdown, select tgz.

  4. Click Download.

2

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 9.0 point release, be sure to modify the command to reflect the correct .tgz file name.

tar -zxvf mongodb-linux-x86_64-*-9.0.0.tgz
3

The MongoDB binaries are in the <mongodb-install-directory>/bin directory. To avoid having to specify the path to the MongoDB binaries, add the contents of the <mongodb-install-directory>/bin/ directory to a directory in the $PATH such as /usr/bin/. For example, you can either:

  • Copy the binaries into /usr/bin/.

    sudo cp <mongodb-install-directory>/bin/* /usr/bin/

    -OR-

  • Create symbolic links to each of these binaries to /usr/bin/:

    sudo ln -s /full/path/to/<mongodb-install-directory>/bin/* /usr/bin/

    Replace /full/path/to with the full path to the extracted directory contents.

4

Install mongosh then use the MongoDB Shell to connect to your deployment.

Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.

Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.

Note

If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.

By default, a MongoDB instance stores:

  • its data files in /var/lib/mongo

  • its log files in /var/log/mongodb

If you installed using the package manager, these default directories are created during installation.

If you installed manually by downloading the tarballs, create the directories using mkdir -p <directory> or sudo mkdir -p <directory> depending on the user that will run MongoDB. See your linux man pages for information on mkdir and sudo.

By default, MongoDB runs using the mongod user account. If you change the user that runs the MongoDB process, you must also modify the permission to the /var/lib/mongo and /var/log/mongodb directories to give this user access to these directories.

To specify a different log file directory and data file directory, edit the systemLog.path and storage.dbPath settings in the /etc/mongod.conf. Ensure that the user running MongoDB has access to these directories.

Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.

1

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

sudo mkdir -p /var/lib/mongo

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 these directories. For example, if you intend to run MongoDB as yourself:

sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
2

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

mongod --dbpath /var/lib/mongo --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 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

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

mongosh

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

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

After you install MongoDB Community Edition, you can:

Important

Do not use these instructions to upgrade to another release version.

For general guidance on MongoDB version numbering, release types, and upgrade paths, see MongoDB Versions and Upgrade Paths.

Earn a Skill Badge

Master "MongoDB Architecture Essentials" for free!

Learn more

Rate this page