How to Install MongoDB 4.2 on Ubuntu 18.04

Install MongoDB 4.2
Install MongoDB 4.2

Install MongoDB 4.2 on Ubuntu 18.04

MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.
It is an open-source database management system that is known as a high-performance NoSQL database program.

MongoDB uses two formats to stores the information i.e. “.json” and “.bson [binary json]”.

Main Features of MongoDB

  • Ad-hoc Queries
  • Indexing
  • Replication
  • Load Balancing
  • File Storage
  • Aggregation
  • Server-side JavaScript execution
  • Capped collections
  • Transactions

In this article, We are going to install the latest version of MongoDB 4.2.

The upcoming version is MongoDB 4.4 and we will share the information soon once the MongoDB 4.4 version is officially released.

MongoDB 4.2 Edition supports the following 64-bit Ubuntu releases on x86_64 architecture:

  • 18.04 LTS (“Bionic”)
  • 16.04 LTS (“Xenial”)

Note: MongoDB only supports 64-bit server architectures of these platforms.

Install MongoDB 4.2

1. Import MongoDB public GPG Key

Download the GPG Key with “wget command” and It will respond with output OK,

$ wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add - 

2. Create APT List file for MongoDB

Run the below command which will add repository URL directly to the APT list file,

$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Check the APT list file,

$ cat /etc/apt/sources.list.d/mongodb-org-4.2.list

3. Update the APT repository

To reflect the apt list repository, we need to run the below command,

$ apt-get update
apt-get update

4. Install MongoDB 4.2

Install MongoDB 4.2 package that installs multiple other packages along with MongoDB. To install MongoDB run below command,

$ apt-get install -y mongodb-org
Install MongoDB 4.2

5. Check MongoDB Version

$ mongod --version
mongodb version

6. Manage MongoDB Service

MongoDB service starts/stops with the systemctl command and its easily manageable with the standard systemd commands.

To Check Status of MongoDB Service, run the following command.

$ systemctl status mongod.service

To Stop the MongoDB Service, run the following command.

$ systemctl stop mongod.service

To Start the MongoDB Service, run the following command.

$ systemctl start mongod.service

To restart the MongoDB Service, run the following command.

$ systemctl restart mongod.service

To Enable/Disable MongoDB Service at boot time, run the following command.

$ systemctl enable mongodb.service
$ systemctl disable mongodb.service

That’s it. You have now installed MongoDB 4.2 successfully on Ubuntu 18.04 LTS server.

If you are new to MongoDB and want to learn further on MongoDB like to create a new database, create a user with privileges, backup, restore MongoDB.

Read: Create, Backup, Restore and Migrate MongoDB

Prashant

Welcome to Linuxgrow. I'm Prashant, a tech-blogger from Mumbai, India. I started Linuxgrow as a passion and to share my knowledge about technologies. Here at Linuxgrow, I write about Linux technologies, Aws Cloud, Wordpress blogging and scripting knowledge. You can read more about me at About us page. Thank You :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook