Install Newer Versions of MongoDB on Debian 7

MongoDB is a fast and powerful NoSQL database. However, Debian repositories update slowly and often contain very old versions of packages. This tutorial explains how to install the latest version of MongoDB from the official MongoDB repository.

At the time of writing, 3.0 was the current version of MongoDB.

All commands below must be performed from the root user.

1. Add MongoDB public key

The following command adds the MongoDB public GPG Key to the system key ring:

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

Debian package management tools need this key to ensure package consistency and authenticity.

2. Add MongoDB repository

Create a mongodb.list file to add the MongoDB repository to the system. The following command will create this file:

echo "deb http://repo.mongodb.org/apt/debian "$(lsb_release -sc)"/mongodb-org/3.0 main" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list

3. Update packages

Use the following command to get info about the latest packages in repositories:

apt-get update

If you are familiar with Debian, you probably already know this command.

4. Install MongoDB packages

Now it’s time to install MongoDB. To install the latest stable version of MongoDB, use the following command:

apt-get install -y mongodb-org

mongodb-org is a “metapackage” that will automatically install the four component packages:

  • mongodb-org-server
  • mongodb-org-mongos
  • mongodb-org-shell
  • mongodb-org-tools

If you need a specific version of MongoDB, you can use the following command to choose the version of each component:

apt-get install -y mongodb-org=3.0.0 mongodb-org-server=3.0.0 mongodb-org-shell=3.0.0 mongodb-org-mongos=3.0.0 mongodb-org-tools=3.0.0

In this example, I have selected version 3.0.0.

5. Start MongoDB

After the installation finishes, MongoDB is automatically started. If you need to manually run the MongoDB server, then use the following command:

service mongod start

To stop the Mongod process, use this command:

service mongod stop

To restart Mongod, use the following:

service mongod restart

The MongoDB shell can be accessed by running the following command. This allows you to connect to the MongoDB server.

mongo

When the shell is launched, you will see output in this format:

MongoDB shell version: 3.0.0
connecting to: test
>

Now you can use MongoDB on your Debian server.

We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies

More