Table of Contents
Add MongoDB repository
Install and verify MongoDB
Home Database MongoDB How to install MongoDB on Ubuntu 16.04

How to install MongoDB on Ubuntu 16.04

Aug 27, 2023 pm 10:13 PM

如何在 Ubuntu 16.04 上安装 MongoDB

MongoDB is a cross-platform, document-oriented database that provides high performance, high availability, and easy scalability. MongoDB works on the concepts of collections and documents. MongoDB maintainers have not yet released official Ubuntu 16.04 MongoDB packages. This article explains "How to install Mongo DB on Ubuntu and start the MongoDB service at boot"

Add MongoDB repository

MongoDB is usually included in the Ubuntu package repository. However, legitimate MongoDB repositories provide the latest version changes in an approved manner.

To perform this process we first have to import the keys for a legitimate MongoDB repository using the following command -

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
Copy after login

The example output should look like this –

Executing: /tmp/tmp.Qe1RFZgUh2/gpg.1.sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv
EA312927
gpg: requesting key EA312927 from hkp server keyserver.ubuntu.com
gpg: key EA312927: public key "MongoDB 3.2 Release Signing Key <packaging@mongodb.com>" imported
gpg: Total number processed: 1
gpg:                imported: 1 (RSA: 1)
Copy after login

To add MongoDB repository, use the following command -

$ sudo echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
Copy after login

Now we need to update the package list using the following command -

$ sudo apt-get update
Copy after login

Install and verify MongoDB

To install MongoDB, use The following command –

$ sudo apt-get install -y --allow-unauthenticated mongodb-org
Copy after login

The sample output should look like this –

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
   apport-hooks-elementary contractor javascript-common libgda-5.0-4
   libgda-5.0-common libgranite-common libgranite3 libgsignon-glib1
   libindicate5 libjs-jquery libnoise-core0 libtagc0
Use &#39;sudo apt autoremove&#39; to remove them.
The following additional packages will be installed:
   mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed:
   mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell
   mongodb-org-tools
0 upgraded, 5 newly installed, 0 to remove and 168 not upgraded.
Need to get 47.4 MB of archives.
After this operation, 218 MB of additional disk space will be used.
Get:1 http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2/multiverse amd64 mongodb-org-shell amd64 3.2.6 [5,257 kB]
Get:2 http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2/multiverse amd64 mongodb-org-server amd64 3.2.6 [9,541 kB]
Get:3 http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2/multiverse amd64 mongodb-org-mongos amd64 3.2.6 [4,337 kB]
...................................................................................
Copy after login

In order to properly start MongoDB as a service on Ubuntu 16.04, we also need to create a unit file that describes the service. Unit files tell the system a way to manage resources. The most common unit type is a service, which determines how to start or stop the service.

Create a configuration file called mongodb.service to set up the unit file as shown below –

$ sudo nano /etc/systemd/system/mongodb.service
Copy after login

Paste the following code –

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target
Copy after login

Now use systemctl Start the newly created service as shown below -

$ sudo systemctl start mongodb
Copy after login

It usually returns no output. Now we need to check if the service has started normally. In order to perform this process, use the following command -

$ sudo systemctl status mongodb
Copy after login

The sample output should be like this –

mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset:
   Active: active (running) since Fri 2016-05-13 10:33:52 IST; 1min 48s ago
Main PID: 7078 (mongod)
   Tasks: 16 (limit: 512)
   CGroup: /system.slice/mongodb.service
            └─7078 /usr/bin/mongod --quiet --config /etc/mongod.conf

May 13 10:33:52 linux systemd[1]: Started High-performance, schema-free document
lines 1-9/9 (END)
Copy after login

To enable the process of automatically starting MongoDB when the system starts, use the following command -

$ sudo systemctl enable mongodb
Copy after login

The sample output should be like this –

Created symlink from /etc/systemd/system/multi-user.target.wants/mongodb.service to /etc/systemd/system/mongodb.service.
Copy after login

After reading this article, you will be able to understand – How to install MongoDB on Ubuntu 16.04. In the following articles, we will come up with more Linux-based tips and tricks. continue reading!

The above is the detailed content of How to install MongoDB on Ubuntu 16.04. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the different types of indexes in MongoDB (single, compound, multi-key, text, geospatial)? What are the different types of indexes in MongoDB (single, compound, multi-key, text, geospatial)? Mar 17, 2025 pm 06:17 PM

The article discusses various MongoDB index types (single, compound, multi-key, text, geospatial) and their impact on query performance. It also covers considerations for choosing the right index based on data structure and query needs.

How do I create users and roles in MongoDB? How do I create users and roles in MongoDB? Mar 17, 2025 pm 06:27 PM

The article discusses creating users and roles in MongoDB, managing permissions, ensuring security, and automating these processes. It emphasizes best practices like least privilege and role-based access control.

How do I use MongoDB Compass for GUI-based management and querying? How do I use MongoDB Compass for GUI-based management and querying? Mar 17, 2025 pm 06:30 PM

MongoDB Compass is a GUI tool for managing and querying MongoDB databases. It offers features for data exploration, complex query execution, and data visualization.

How do I choose a shard key in MongoDB? How do I choose a shard key in MongoDB? Mar 17, 2025 pm 06:24 PM

The article discusses selecting a shard key in MongoDB, emphasizing its impact on performance and scalability. Key considerations include high cardinality, query patterns, and avoiding monotonic growth.

How do I configure auditing in MongoDB for security compliance? How do I configure auditing in MongoDB for security compliance? Mar 17, 2025 pm 06:29 PM

The article discusses configuring MongoDB auditing for security compliance, detailing steps to enable auditing, set up audit filters, and ensure logs meet regulatory standards. Main issue: proper configuration and analysis of audit logs for security

What are the different components of a sharded MongoDB cluster (mongos, config servers, shards)? What are the different components of a sharded MongoDB cluster (mongos, config servers, shards)? Mar 17, 2025 pm 06:23 PM

The article discusses components of a sharded MongoDB cluster: mongos, config servers, and shards. It focuses on how these components enable efficient data management and scalability.

How do I implement authentication and authorization in MongoDB? How do I implement authentication and authorization in MongoDB? Mar 17, 2025 pm 06:25 PM

The article guides on implementing and securing MongoDB with authentication and authorization, discussing best practices, role-based access control, and troubleshooting common issues.

How do I use map-reduce in MongoDB for batch data processing? How do I use map-reduce in MongoDB for batch data processing? Mar 17, 2025 pm 06:20 PM

The article explains how to use map-reduce in MongoDB for batch data processing, its performance benefits for large datasets, optimization strategies, and clarifies its suitability for batch rather than real-time operations.

See all articles