How To install MongoDB on Ubuntu 22.04/22.10

MongoDB offers us a wide variety of features since it is a non-SQL database with which we have:

  • High performance
  • Security and integrity
  • Great availability
  • Automatic scaling which guarantees stability

When we mention that MongoDB is a non-SQL database it means that it can not use SQL to insert and work the data and this data will not be stored in tables as it happens with SQL since these are stored in a document structure as the language does. JSON, in MongoDB, is called BSON.

Next, we will see how to install MongoDB in Ubuntu Server 22.10.

Before Install MongoDB

MongoDB Repository

First of all, it will be necessary to install the MongoDB repository for compatibility and connection issues, for this we will use the following command:

sudo apt-key adv --keyserver hkp:// --recv EA312927

The next step is to create the MongoDB repository which will be stored in the route:


For this we execute the following command:

echo "deb xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

The next step is to update all the system packages:

sudo apt update

Install MongoDB

When the repository is updated we proceed to the installation of MongoDB in Ubuntu 22 using the following command:

sudo apt-get install -y mongodb-org

The next step is to create a MongoDB drive file to be run as a service on Ubuntu 22.

The unit type defines when a service must be executed automatically. We proceed to create a unit file for MongoDB in the path /etc/systemd/system, for this w, will execute the following command:

sudo nano /etc/systemd/system/mongodb.service

In the file we must enter the following:


Description=High-performance, schema-free document-oriented database



ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf


How To install MongoDB on Ubuntu 22.04/22.10

We save the changes using the key combination: Ctrl + O

And we left the editor using the combination: Ctrl + X

Then proceed to start the service using the following command:

systemctl daemon-reload

systemctl start mongod

systemctl enable mongod

We can see the status of the service using the following command:

sudo systemctl status mongodb

Configuring MongoDB in Ubuntu 22

We can see that his state is Active. Finally we will see that MongoDB will use port 27017 for its communication, for this we will use the command:

netstat -plntu

Configuring MongoDB in Ubuntu 22

Setting the username and password in MongoDB

To configure the user name and password in MongoDB it will be necessary to access the MongoDB Shell using the term:


The following message may be displayed:

Configuring MongoDB in Ubuntu 22

Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and / or LC_ * environment variables are set correctly

If this is the case, we must execute the following command:

export LC_ALL=C

In the MongoDB Shell window we will enter the following:

use admin

Next we will enter the following line to create the root user:

db.createUser({user:"admin", pwd:"admin123", roles:[{role:"root", db:"admin"}]})

Enable MongoDB Authentication

To enable the authentication of users in MongoDB we must access the following route:


To edit a specific line. We will use the nano editor to access that route:

sudo nano /lib/systemd/system/mongod.service

There we must go to the ExecStart line and add the line -auth

Configuring MongoDB in Ubuntu 22

In this way we enable authentication when logging into MongoDB . It will be necessary to restart the service using the following command:

systemd daemon -reload

Restart MongoDB and connectivity

Now we restart the database using the following command:

sudo service mongod restart

Now we will connect to the MongoDB Shell using the following syntax:

mongo -u admin -p admin123 --authenticationDatabase admin

We can see that the connection has been satisfactory. If we want to see the available capacity we can use show dbs

Configuring MongoDB in Ubuntu 22

Configuring MongoDB in Ubuntu 22 is simple and will be an important aid for the management of the necessary data in a safe, dynamic and fully scalable way.

It might be interesting

Intel unveiled NUC 12 Extreme compact gaming PCs powered by Alder Lake desktop chips

Intel has officially introduced the NUC 12 Extreme Compute Element (Eden Bay) platform and the NUC 12 Extreme (Dragon Canyon) compact modular gaming PC based on it. For the first time for the NUC series, the NUC 12 Extreme features desktop versions of Intel's 12th generation Core processors and offers support for full-size graphics cards up to 300mm long.

Dell’s INTEGRITY Global Security

The Dell’s new enhanced desktop is providing with more secured computing ever produced by a new Global Alliance.

Apple signs new deal to bring more HD TV content to iTunes

To bring high-definition television content to its iTunes Store, at last, Apple has signed a deal with all almost all the major television studios.

Details about Android 13: sweet new name, dynamic themes and more

After the release of Android 9 Pie, Google decided to stop using dessert names for different versions of Android This week, Google released the first developer preview version of Android 13, which contains many changes based on features introduced in Android 12.