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

How To Install or Uninstall Software on Ubuntu

Are you new to Ubuntu and wondering how to access the Ubuntu Software Center? Look no further! In this comprehensive tutorial, we'll guide you through the steps needed to access the Software Center and show you how to install or uninstall software on your Ubuntu system.

$100K Granted By Mozilla To Boost Up An Open Video Format For The Web World

In an effort to create an open video format Mozilla Foundation is giving a grant. The said grant is of $100,000 to give weightage to the effort to create an open video format.

Unlocking the Potential of a Game Engines

Are you looking for a way to create the best gaming experience possible? Look no further than a game engine. A game engine is a toolset of technologies used to create interactive video games. It is the original software developed to provide an environment to create, run, and play games. A well-designed game engine combines three-dimensional graphics; calculation of collisions with objects; volumetric game world; sound component.

Intel's top-of-the-line Arc Alchemist graphics card on DG2-512EU GPU was faster than GeForce RTX 3070 Ti in benchmark

In SiSoftware Sandra there is a top-of-the-line 3D gas pedal from Intel's Arc Alchemist line based on DG2-512EU graphics processor.