How to Install MongoDB 4.2 on Ubuntu 18.04
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
- Load Balancing
- File Storage
- Capped collections
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
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
5. Check MongoDB Version
$ mongod --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.