OPTIONS

Install MongoDB on Linux Systems

Compiled versions of MongoDB for Linux provide a simple option for installing MongoDB for other Linux systems without supported packages.

Installation Process

MongoDB provides archives for both 64-bit and 32-bit Linux. Follow the installation procedure appropriate for your system.

Install for 64-bit Linux

None

Optional: Configure Search Path

To ensure that the downloaded binaries are in your PATH, you can modify your PATH and/or create symbolic links to the MongoDB binaries in your /usr/local/bin directory (/usr/local/bin is already in your PATH). You can find the MongoDB binaries in the bin/ directory within the archive.

1

Download the Latest Release

In a system shell, download the latest release for 64-bit Linux.

curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.4.14.tgz

You may optionally specify a different version to download.

2

Extract MongoDB From Archive

Extract the files from the downloaded archive.

tar -zxvf mongodb-linux-x86_64-2.4.14.tgz
3

Optional: Copy MongoDB to Target Directory

Copy the extracted folder into another location, such as mongodb.

mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-2.4.14/ mongodb

Install for 32-bit Linux

None

Optional: Configure Search Path

To ensure that the downloaded binaries are in your PATH, you can modify your PATH and/or create symbolic links to the MongoDB binaries in your /usr/local/bin directory (/usr/local/bin is already in your PATH). You can find the MongoDB binaries in the bin/ directory within the archive.

1

Download the Latest Release

In a system shell, download the latest release for 32-bit Linux.

curl -O http://downloads.mongodb.org/linux/mongodb-linux-i686-2.4.14.tgz

You may optionally specify a different version to download.

2

Extract MongoDB From Archive

Extract the files from the downloaded archive.

tar -zxvf mongodb-linux-i686-2.4.14.tgz
3

Optional: Copy MongoDB to Target Directory

Copy the extracted folder into another location, such as mongodb.

mkdir -p mongodb
cp -R -n mongodb-linux-i686-2.4.14/ mongodb

Run MongoDB

Set Up the Data Directory

Before you start mongod for the first time, you will need to create the data directory (i.e. dbpath). By default, mongod writes data to the /data/db directory.

1

Create dbpath

To create the default dbpath directory, use the following command:

mkdir -p /data/db
2

Set dbpath Permissions

Ensure that the user that runs the mongod process has read and write permissions to this directory. For example, if you will run the mongod process, change the owner of the /data/db directory:

chown mongodb /data/db

You must create the mongodb user separately.

You can specify an alternate path for data files using the --dbpath option to mongod. If you use an alternate location for your data directory, ensure that this user can write to the alternate data directory.

Start MongoDB

To start mongod, run the executable mongod at the system prompt.

For example, if your PATH includes the location of the mongod binary, enter mongod at the system prompt.

mongod

If your PATH does not include the location of the mongod binary, enter the full path to the mongod binary.

Starting mongod without any arguments starts a MongoDB instance that writes data to the /data/db directory. To specify an alternate data directory, start mongod with the --dbpath option:

mongod --dbpath <some alternate directory>

Whether using the default /data/db or an alternate directory, ensure that the user account running mongod has read and write permissions to the directory.

Stop MongoDB

To stop the mongod instance, press Control+C in the terminal where the mongod instance is running.