28 C
Jaipur
Wednesday, October 28, 2020

How to Install MongoDB Community Edition on Ubuntu

Must read

Vdx – An Intuitive Commandline Wrapper To FFmpeg

FFmpeg is a cross-platform, open source audio and video converter. It supports most industry standard codecs and can convert and transcode media files from...

Valorant Tier List: Best Agents In Valorant [Update 1.10]

Valorant, like Counter-Strike: Global Offensive, is a tactical five-person shooter game that has successfully grabbed millions of players worldwide. However, the feature that sets...

How To Fix Chromium-Based Web Browsers Not Working Properly After Resume From Suspend On Linux

This article explains how to fix Chromium-based web browsers (Google Chrome, Chromium, Vivaldi, Opera, etc.) not working properly after resuming from suspend on Linux. Those...

MongoDB is an open-source, document database based on the cutting edge technology of NoSQL. It supports the development of modern web applications, with features such as strong consistency, flexibility, expressive query languages, and secondary indexes plus a lot more. Additionally, it offers organizations great scalability and performance for building modern applications with powerful and mission-critical databases.

In this article, you will learn how to install and configure the latest version of MongoDB 4.4 Community Edition on Ubuntu LTS (long-term support) releases of Ubuntu Linux using the apt package manager.

Platform Support

MongoDB 4.4 Community Edition holds the following 64-bit Ubuntu LTS (long-term support) releases:

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

The default Ubuntu repositories offer an outdated MongoDB version, therefore we will install and configure the latest MongoDB from the official MongoDB repository on the Ubuntu server.

Step 1: Adding the MongoDB Repository on Ubuntu

1. To install the latest version of MongoDB Community Edition on your Ubuntu server, you need to install necessary dependencies as shown.

$ sudo apt update
$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
Install Software on Ubuntu

2. Next, import the MongoDB public GPG Key used by the package management system using the following wget command.

$ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
Add Mongodb Public Key
Add MongoDB Public Key

3. After that, create the list file /etc/apt/sources.list.d/mongodb-org-4.4.list that contains the MongoDB repository details under /etc/apt/sources.list.d/ directory for your version of Ubuntu.

Now run the following command as per your version of Ubuntu:

Ubuntu 20.04 (Focal)

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

Ubuntu 18.04 (Bionic)

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

Ubuntu 16.04 (Xenial)

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

Then save the file and close it.

4. Next, run the following command to reload the local package database.

$ sudo apt-get update
Update Ubuntu Package Database
Update Ubuntu Package Database

Step 2: Installing MongoDB Database on Ubuntu

5. Now that MongoDB repository is enabled, you can install the latest stable version by running the following command.

$ sudo apt-get install -y mongodb-org
Install Mongodb in Ubuntu
Install MongoDB in Ubuntu

During the MongoDB installation, it will create the configuration file /etc/mongod.conf, data directory /var/lib/mongodb and the log directory /var/log/mongodb.

By default, MongoDB runs using the mongodb user account. If you change the user, you must also change the permission to the data and log directories to assign access to these directories.

6. Then start and verify the mongod process by running the following command.

------------ systemd (systemctl) ------------ 
$ sudo systemctl start mongod 
$ sudo systemctl status mongod

------------ System V Init ------------
$ sudo service mongod start   
$ sudo service mongod status
Verify Mongodb Status
Verify Mongodb Status

7. Now start a mongo shell without any options to connect to a mongod that is running on your localhost with default port 27017.

$ mongo
Start Mongo Shell
Start Mongo Shell

Uninstall MongoDB Community Edition

To completely remove MongoDB including MongoDB applications, the configuration files, and any directories containing data and logs, issue the following commands.

$ sudo service mongod stop
$ sudo apt-get purge mongodb-org*
$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb

I hope you find this guide useful, for any questions or additional information, you can use the comment section below to air out your concerns.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Vdx – An Intuitive Commandline Wrapper To FFmpeg

FFmpeg is a cross-platform, open source audio and video converter. It supports most industry standard codecs and can convert and transcode media files from...

Valorant Tier List: Best Agents In Valorant [Update 1.10]

Valorant, like Counter-Strike: Global Offensive, is a tactical five-person shooter game that has successfully grabbed millions of players worldwide. However, the feature that sets...

How To Fix Chromium-Based Web Browsers Not Working Properly After Resume From Suspend On Linux

This article explains how to fix Chromium-based web browsers (Google Chrome, Chromium, Vivaldi, Opera, etc.) not working properly after resuming from suspend on Linux. Those...

Pixel 5 Users Report Issues When Phone is Docked on Pixel Stand

A number of Pixel 5 users are reporting a bizarre issue that apparently affects the device when left overnight on the Pixel Stand. According...