Installing and Running MongoDB on a Linux Server

Leave your reply

Introduction

MongoDB is a free, open-source document-oriented database which stores data in JSON-like documents with a flexible schema. This "NoSQL" database is a popular alternative to traditional relational databases like MySQL. Learn how to install MongoDB on a Cloud Server with CentOS 7, Ubuntu 14.04, or Ubuntu 16.04.

There are two options for installing MongoDB:

  • On a new server: MongoDB is available as a ready-to-use application which can be automatically installed on the server when it is built.
  • On an existing server: MongoDB can be manually installed and configured on an existing server.

Requirements

  • A Cloud Server with Linux (CentOS 7, Ubuntu 14.04, or Ubuntu 16.04).

Related articles:

Install MongoDB on a New Server

Log in to the Cloud Panel then go to Infrastructure > Servers.

Click + Create to create a new server.

Set a name for the server, and click the server configuration you wish to use.

Click the Applications tab.

Click the Search icon, and search for MongoDB.

Click MongoDB.

Click Create to build the server.

Install MongoDB on an Existing Server

CentOS 7

To add the repository, create a mongodb-org-3.6.repo file and open it for editing:

sudo nano /etc/yum.repos.d/mongodb-org-3.6.repo

Add the following content to this file:

[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

Save and exit the file.

Update the system:

sudo yum update

Install MongoDB with the command:

sudo yum install -y mongodb-org

Controlling the MongoDB Service

Start MongoDB:

sudo systemctl start mongod

Stop MongoDB:

sudo systemctl stop mongod

Restart MongoDB:

sudo systemctl restart mongod

Ubuntu 14.04

Import the MongoDB public GPG key:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

Create a mongodb-org-3.6.list file:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

Update the package database:

sudo apt-get update

Install MongoDB:

sudo apt-get install -y mongodb-org

Controlling the MongoDB Service

Start MongoDB:

sudo service mongod start

Stop MongoDB:

sudo service mongod stop

Restart MongoDB:

sudo service mongod restart

Ubuntu 16.04

Import the MongoDB public GPG key:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

Create a mongodb-org-3.6.list file:

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

Update the package database:

sudo apt-get update

Install MongoDB:

sudo apt-get install -y mongodb-org

Controlling the MongoDB Service

Start MongoDB:

sudo systemctl start mongod

Stop MongoDB:

sudo systemctl stop mongod

Restart MongoDB:

sudo systemctl restart mongod