# Install MongoDB on a Linux Server

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](https://www.ionos.ca/digitalguide/server/know-how/learn-mysql-in-simple-steps/ "Learn MySQL in simple steps"). 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).

## Install MongoDB on a New Server

Log in to the [Cloud Panel](https://cloudpanel.ionos.ca/login.php "IONOS Cloud Panel") then go to **Infrastructure &gt; 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:

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

Add the following content to this file:

```none
[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:

```none
sudo yum update
```

Install MongoDB with the command:

```none
sudo yum install -y mongodb-org
```

**Controlling the MongoDB Service**

Start MongoDB:

```none
sudo systemctl start mongod
```

Stop MongoDB:

```none
sudo systemctl stop mongod
```

Restart MongoDB:

```none
sudo systemctl restart mongod
```

### Ubuntu 14.04

Import the MongoDB public GPG key:

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

Create a mongodb-org-3.6.list file:

```none
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:

```none
sudo apt-get update
```

Install MongoDB:

```none
sudo apt-get install -y mongodb-org
```

**Controlling the MongoDB Service**

Start MongoDB:

```none
sudo service mongod start
```

Stop MongoDB:

```none
sudo service mongod stop
```

Restart MongoDB:

```none
sudo service mongod restart
```

### Ubuntu 16.04

Import the MongoDB public GPG key:

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

Create a mongodb-org-3.6.list file:

```none
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:

```none
sudo apt-get update
```

Install MongoDB:

```none
sudo apt-get install -y mongodb-org
```

**Controlling the MongoDB Service**

Start MongoDB:

```none
sudo systemctl start mongod
```

Stop MongoDB:

```none
sudo systemctl stop mongod
```

Restart MongoDB:

```none
sudo systemctl restart mongod
```


This is a markdown version of: [https://www.ionos.ca/digitalguide/hosting/technical-matters/installing-mongodb-on-a-linux-server/](https://www.ionos.ca/digitalguide/hosting/technical-matters/installing-mongodb-on-a-linux-server/) for AI/LLM consumption.