frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

[For Ubuntu/Debian] How to Install MongoDB

LawrenceLawrence Member
edited April 2016 in Linux Applications
Introduction

MongoDB is a free and open-source NoSQL document database used commonly in modern web applications. This tutorial will help you set up MongoDB on your server for a production application environment.


To follow this tutorial, you will need

A sudo non-root user, which you can set up by following this:

Create new user:

adduser name_of_new_user

To add "sudo" privileges to our new user, we need to add the new user to the "sudo" group. By default, on Ubuntu/Debian, users who belong to the "sudo" group are allowed to use the sudo command. Run this command to add your new user to the sudo group:

gpasswd -a name_of_new_user sudo

Then login as new user, just execute:

su name_of_new_user


Importing the Public Key

In this step, we will import the MongoDB GPG public key.

MongoDB is already included in Ubuntu package repositories, but the official MongoDB repository provides most up-to-date version and is the recommended way of installing the software. Ubuntu ensures the authenticity of software packages by verifying that they are signed with GPG keys, so we first have to import they key for the official MongoDB repository.

To do so, execute:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10


Creating a List File

Next, we have to add the MongoDB repository details so APT will know where to download the packages from.

Issue the following command to create a list file for MongoDB:

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

After adding the repository details, we need to update the packages list.

sudo apt-get update


Installing and Verifying MongoDB

Now we can install the MongoDB package itself.

sudo apt-get install -y mongodb-org

This command will install several packages containing latest stable version of MongoDB along with helpful management tools for the MongoDB server.

After package installation MongoDB will be automatically started. You can check this by running the following command.

sudo service mongod status

If MongoDB is running, you'll see an output like this (with a different process ID).
Output

mongod start/running, process 16791

You can also stop, start, and restart MongoDB using the service command (e.g. service mongod stop, service mongod start).
Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch