Numerous modern web applications fancy the use of a document database to store data; a case exhibited by MongoDB. The no traditional table-based relational database structure classifies MongoDB as a NoSQL database. It instead embraces dynamic schemas through the use of JSON-like documents.
With MongoDB, there is no need for a predefined schema for data to be stored on a database. The MongoDB schema is open to altercations and updates making it unnecessary to set up a new database whenever new project specifications need implementation.
This article will walk us through the installation and configuration of MongoDB on Ubuntu 22.04 and Ubuntu 20.04. Before proceeding, make sure you have root user access or you are a Sudoer user on the system you are using.
Installing MongoDB in Ubuntu
Always ensure that your Ubuntu operating system is up-to-date.
$ sudo apt update
Since we are after the latest stable release of MongoDB, our APT sources need the inclusion of its dedicated package repository. The current stable release for MongoDB is 5.0.
We will import MongoDB’s public GPG key by pointing to its latest stable version release number (5.0) using the following curl command.
$ curl -fsSL https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Next, you need to configure MongoDB’s APT repository, which will query inside the sources.list.d directory for download and installation sources of targeted packages. We should be able to create a file called mongodb-org-5.0.list with the following single line entry.
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Update your Ubuntu system again so that the APT package manager knows where to fetch the MongoDB package for download and installation.
$ sudo apt update
Finally, you can now proceed to install MongoDB on Ubuntu with the following command.
$ sudo apt install mongodb-org -y
Once installed, you need to start the service responsible for MongoDB with the following command:
$ sudo systemctl start mongod
Afterward, check on its status with the following command to be sure that it is running:
$ sudo systemctl status mongod
If you need the MongoDB database to keep running even after a successful system reboot, execute the following command:
$ sudo systemctl enable mongod
To test the connection to the MongoDB database, we will run the following command:
$ mongo --eval 'db.runCommand({connectionStatus: 1})'
The output of the above command should reveal its port, address, version, and whether the database is active.
To access MongoDB shell, run:
$ mongo
You will be greeted with the following interface:
From here, you are free to accomplish any database-related objective that brought you to this article.
MongoDB is an exciting addition to any database project. With this article, you should be able to put a lid on the first of many projects MongoDB will help you accomplish.
A little clarification:
After
"sudo systemctl enable mongod"
you have to run"sudo systemctl start mongod"
or reboot the system.@Veni,
Thanks for the tip…
I am unsure of the consequences of installing libssl1.1 alongside libssl3. As a workaround, I am using mongodb from a docker container instead. I hope that the official support for 22.04 is not so far away though.
Dude, I don’t think it actually works on Ubuntu 22.04…
Sample Output:
Same here, they’ll need to create an explicit “jammy” build I think.
Just run the above commands to fix the error…
This worked like a charm, Thank you bro…
I got also same error:/
That worked for me…
MongoDB still does not have support for 22.04, as you can see the official response on this forum,
https://www.mongodb.com/community/forums/t/installing-mongodb-over-ubuntu-22-04/159931/1
@Yoandry,
Just install libssl1.1 using the following commands to fix the issue…