In this article, we will have explained the necessary steps to install MongoDB on Ubuntu 22.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges. All the commands in this tutorial should be run as a non-root user.
MongoDB is a high-performance document-oriented database that is powered by a NoSQL structure. It should note that MongoDB is a type of NoSQL database system used to store large amounts of data. MongoDB supports different types of data. The MongoDB database is a tool that can manage document-based information as well as extract and store information.
- Operating System with Ubuntu 22.04
- Server IPv4 Address with Superuser Privileges (Root Access)
- Gnome Terminal for Linux Desktop
- PuTTy SSH client for Windows or macOS
- Powershell for Windows 10/11
- Familiar with APT Commands
Install MongoDB on Ubuntu 22.04 LTS
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade sudo apt install software-properties-common dirmngr apt-transport-https gnupg
Step 2. Installing Libssl1.
Before installing MongoDB, you need to install libssl1 to your system:
echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list sudo apt update sudo apt- install libssl1.1
Step 3. Install MongoDB on Ubuntu Linux.
Installing the MongoDB on your Ubuntu 22.04 Jammy Jellyfish system is straightforward, Now import the MongoDB GPG key to verify the authenticity of the installation:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Then, add the MongoDB repository use this command:
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
After that, install the latest version of MongoDB using the below command:
sudo apt update sudo apt install mongodb-org
Once the installation is successful, MongoDB will be started. Use this command to check the service status:
sudo systemctl enable mongod sudo systemctl status mongod
Step 4. Configure MongoDB.
Now we can secure MongoDB, configure MongoDB to accept remote connections, and also create a new database:
sudo nano /etc/mongod.conf
security: authorization: enabled
authorization the option enables Role-Based Access Control (RBAC) which regulates users’ access to database resources and operations. If this option is disabled each user will have access to all databases and perform any action.
After editing the MongoDB configuration file, restart the MongoDB service for changes to take effect:
sudo systemctl restart mongod
Step 5. Create Admin User
By default, MongoDB doesn’t authenticate users to read and modify data, and it is the biggest security concern. To enable authentication, first, create a database administrative user.
Step 6 Access MongoDB.
Finally, connect to the MongoDB shell by using the following command:
$ mongo OR $ mongo <DBHOST_IP_ADDRESS>
That’s all you need to do to install MongoDB on Ubuntu 22.04 LTS Jammy Jellyfish. I hope you find this quick tip helpful. For further reading on the installation of the MongoDB database server, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.