How To Install MongoDB on Ubuntu 18.04 LTS (Bionic Beaver)

0

MongoDB is a free and open source cross-platform, document-oriented database designed with both scalability and developer agility in mind. It is written in C++ and JavaScript. MongoDB uses JSON-like documents with dynamic schemas to store data.

MongoDB is available for Windows, Linux, OS X, and Solaris.

MongoDB is released under the GNU Affero General Public License. The language drivers are available under an Apache License.

Install MongoDB on Ubuntu 18.04 LTS

You can install MongoDB in two ways, using either Ubuntu repository or Official MongoDB repository.

  1. Install MongoDB from Ubuntu Repository
  2. Install MongoDB from Official MongoDB repository

1. Install MongoDB from Ubuntu Repository

Installing from MongoDB default repository is a straightforward way, but the version available in Ubuntu repository may be bit older than the one in official MongoDB repository.

MongoDB Inc does not maintain the MongoDB package provided by Ubuntu.
sudo apt update
sudo apt -y install mongodb mongodb-server mongo-tools

2. Install MongoDB from MongoDB Repository

MongoDB Inc releases stable packages for Ubuntu operating systems such as Ubuntu 16.04 and Ubuntu 14.04, and their packages are generally fresher than those in the Ubuntu repositories. You should always use the official mongodb-org packages

This package might conflict with the mongodb packages in Ubuntu (If you have it already installed).

At the time of writing this article, MongoDB Inc doesn’t offer MongoDB package for Ubuntu 18.04.

Controlling MongoDB Service

MongoDB has its controlling system, and it can be started/stopped by the easy known commands.

To start MongoDB server, run:

sudo systemctl start mongodb

To stop MongoDB service, run:

sudo systemctl stop mongodb

To restart MongoDB service, run:

sudo systemctl restart mongodb

To check the status of MongoDB service, run.

sudo systemctl status mongodb

Output:

 mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-07-03 10:18:58 IST; 21min ago
     Docs: man:mongod(1)
 Main PID: 20201 (mongod)
    Tasks: 23 (limit: 2323)
   CGroup: /system.slice/mongodb.service
           └─20201 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

Jul 03 10:18:58 desktop systemd[1]: Started An object/document-oriented database.

Confirm the version of MongoDB.

mongod --version

Output:

db version v3.6.3
git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
OpenSSL version: OpenSSL 1.1.0g  2 Nov 2017
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

Access MongoDB

Connect to MongoDB shell by using the following command.

mongo

Output:

MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings:
2018-07-04T03:16:37.615+0000 I STORAGE  [initandlisten]
2018-07-04T03:16:37.615+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-07-04T03:16:37.615+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-07-04T03:16:39.232+0000 I CONTROL  [initandlisten]
2018-07-04T03:16:39.232+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-07-04T03:16:39.232+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-07-04T03:16:39.233+0000 I CONTROL  [initandlisten]
>

Fix MongoDB errors

Error 1

2018-07-04T03:16:37.615+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-07-04T03:16:37.615+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem

To clear this issue, we recommend you to use XFS filesystem for MongoDB.

Error 2

2018-07-04T03:16:39.232+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-07-04T03:16:39.232+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.

To resolve this issue, follow the MongoDB security checklist.

That’s all.

Further Reading

You might also like

How To Install MongoDB on Ubuntu 18.04 LTS (Bionic Beaver)

0