
MongoDB is a type of NoSQL (Not Only SQL) database that stores data in the form of a collection of documents in JSON format. Using this format, MongoDB can handle more complex and varied data. This allows developers to store and retrieve data more flexibly and quickly than relational databases like MySQL. MongoDB is designed to store and manage large-scale data, and can be processed in a flexible/scalable manner. MongoDB also includes built-in high-availability features, such as automatic failover and replica sets, making it an excellent option for anyone learning how to install MongoDB on Ubuntu 26.04. In this article, we will show you how to install MongoDB on Ubuntu 26.04.
Table of Contents
Prerequisites
- An Ubuntu 26.04 VPS
- SSH access with sudo privileges, or root access
Conventions
# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user
Step 1. Update the System
First of all, we need to log in to our Ubuntu 26.04 VPS through SSH:
ssh admin@IP_Address -p Port_number
Replace “admin” with a user that has sudo privileges or root if necessary. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on Ubuntu 26.04. You can verify it with this command:
$ lsb_release -a
You should get this as the output. As you follow these steps, you will be preparing your system for the process of installing MongoDB on Ubuntu 26.04.
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Resolute Raccoon
Release: 26.04
Codename: resolute
Then, run the following command to make sure that all installed packages on the server are updated to their latest available versions:
$ sudo apt update
That’s it, the system package information should be updated now.
Step 2. Install MongoDB
The MongoDB package is not available on the Ubuntu repository. To install MongoDB Community on Ubuntu, we’ll use the official mongodb-org package. Maintained directly by MongoDB Inc., this package ensures you get the latest version by pulling from their dedicated repository rather than the standard Ubuntu archives. Although the official package for Ubuntu 26.04 is not available at the moment, we can use the package for Ubuntu 26.04 (Noble). These instructions provide guidance for how to install MongoDB on Ubuntu 26.04 even if the repository isn’t available yet.
First, we need to install the GPG key.
$ sudo apt install gnupg curl
To import the MongoDB public GPG key, run the following command:
$ curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
--dearmor
Now, we can create the apt list file.
$ echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
After adding an APT list file, we need to reload the local package database. Let’s execute this command so that MongoDB installation on Ubuntu 26.04 goes smoothly.
$ sudo apt update
Finally, we can install the MongoDB server.
$ sudo apt install -y mongodb-org
The MongoDB server will not start automatically upon installation. Let’s start it now and make sure it starts when your server reboots.
$ sudo systemctl enable --now mongod
At this point, the MongoDB server is up and running. We can check with this command below.
$ sudo systemctl status mongod
The command will print a message like this:
master@ubuntu26:/var/www/html/MongoDB8$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: enabled)
Active: active (running) since Sat 2026-01-17 00:11:51 UTC; 8min ago
Invocation: cc8bd2f5fe70428b834f43dee6cd046b
Docs: https://docs.mongodb.org/manual
Main PID: 30418 (mongod)
Memory: 92.3M (peak: 94.4M)
CPU: 6.012s
CGroup: /system.slice/mongod.service
└─30418 /usr/bin/mongod --config /etc/mongod.conf
Jan 17 00:11:51 ubuntu26 systemd[1]: Started mongod.service - MongoDB Database Server.
Jan 17 00:11:51 ubuntu26 mongod[30418]: {"t":{"$date":"2026-01-17T00:11:51.527Z"},"s":"I", "c":"CONTROL", "id":7484500, "ctx":"main","msg":"Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1, overriding \"processManag>
MongoDB server is running and listening on port 27017. Now you know how to install MongoDB on Ubuntu 26.04 and verify the service status.
Step 3. Configure MongoDB
MongoDB uses the YAML format for its configuration file. Because YAML relies on strict indentation, even a single misplaced space can prevent the database from starting. To avoid configuration errors, keep these rules in mind when configuring MongoDB after installation on Ubuntu 26.04.
- Spaces Only: Never use the Tab key. YAML does not recognize tab characters and will throw an error.
- Consistency is Key: Use a consistent number of spaces (usually two) for each nesting level.
- Case Sensitivity: Ensure your keys and values match the expected casing exactly.
For example, let’s enable MongoDB authentication
$ sudo nano /etc/mongod.conf
Add these lines:
security:
authorization: enabled
Save the file, then exit. To apply the changes, we need to restart the MongoDB server and finish the process for how to install MongoDB on Ubuntu 26.04 with authentication enabled.
$ sudo systemctl restart mongod
Step 4. Create a MongoDB Administrator
$ mongosh
The command above will bring you to the MongoDB shell.
Current Mongosh Log ID: 696ad73edaf24453d98ce5af
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.6.0
Using MongoDB: 8.0.17
Using Mongosh: 2.6.0
For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/
To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.
------
The server generated these startup warnings when booting
2026-01-17T00:11:51.656+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2026-01-17T00:11:52.192+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2026-01-17T00:11:52.193+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2026-01-17T00:11:52.193+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2026-01-17T00:11:52.193+00:00: We suggest setting the contents of sysfsFile to 0.
2026-01-17T00:11:52.193+00:00: We suggest setting swappiness to 0 or 1, as swapping can cause performance problems.
------
test>
In this shell, we can run this command:
use admin
Then press enter, you will see this:
test> use admin
switched to db admin
admin>
Then, we can run the command below:
db.createUser({
user: "admin",
pwd: "m0d1fyth15",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
"readWriteAnyDatabase"
]
})
Make sure to replace m0d1fyth15 with a stronger password. You will see an OK message if everything is okay. Following these steps completes the creation of an administrator after installing MongoDB on Ubuntu 26.04.
{ ok: 1 }
Now, exit from the MongoDB shell
exit
You will be brought to your SSH shell again now. Let’s try the new password.
$ mongosh -u admin -p --authenticationDatabase admin
That’s it! You will be prompted to type the password.
Congratulations! You have successfully completed all steps on how to install MongoDB on Ubuntu 26.04.
Of course, you don’t have to install MongoDB on Ubuntu 26.04 if you use one of our MongoDB VPS Hosting services, in which case you can simply ask our expert Linux admins to install MongoDB on Ubuntu 26.04 for you. Our experienced system administrators are available 24×7 and will take care of your request immediately. Managing MongoDB instances is not just about the installation; we can help you optimize your MongoDB installation if you have an active service with us.
If you liked this post, on how to install MongoDB on Ubuntu 26.04, please share it with your friends or leave a comment below.