---
title: How to Install MongoDB on Rocky Linux 9
url: https://docs.vultr.com/how-to-install-mongodb-on-rocky-linux-9
description: Learn how to install MongoDB on Rocky Linux 9 with step-by-step instructions. This guide covers repository setup, installation, and basic configuration.
publish_date: 2025-01-31T05:55:36.342768Z
last_updated: 2026-09-11T16:40:55.371215Z
author: Oluwadamilola Oshungboye
header_image: https://docs.vultr.com/public/doc-assets/2042/cc43fdfd-c8eb-4235-bb79-cac42c0cbec5.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

MongoDB is an open-source NoSQL document database that stores data in a JSON-like format. To install MongoDB on Rocky Linux 9, you can take advantage of its flexible data model, which allows you to store unstructured data and create documents with different schema while providing full indexing support. It also supports ad-hoc queries, indexing, and database replication for high availability using [replica sets](https://docs.vultr.com/how-to-create-a-mongodb-replica-set).

This guide explains how to install MongoDB on a Rocky Linux 9 server. You will secure the database server and create sample documents to verify the installation.

## Prerequisites

Before you begin, you need to:

* [Have an existing Rocky Linux 9 server](https://www.vultr.com/servers/rocky-linux).
* [Access your server using SSH](https://docs.vultr.com/how-to-use-ssh-with-vultr-servers#connecting-with-ssh-keys) as a non-root user with sudo privileges.
* [Update the server](https://docs.vultr.com/how-to-update-a-vultr-cloud-server).

## Install MongoDB on Rocky Linux 9

MongoDB is not available in the default Rocky Linux 9 repositories. Follow the steps below to add the MongoDB repository to your DNF package manager sources and install MongoDB on your server.

1. Visit the [MongoDB releases page](https://www.mongodb.com/try/download/community-edition/releases) and verify the latest version to install on your server. For example, `MongoDB 8.0`.
1. Create a new `mongodb-org-8.0.repo` MongoDB repository configuration file.
  
    ```console
    $ sudo nano /etc/yum.repos.d/mongodb-org-8.0.repo
    ```

1. Add the following configurations to the file.

    ```ini
    [mongodb-org-8.0]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/8.0/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=https://pgp.mongodb.com/server-8.0.asc
    ```

    Save and close the file.

1. Update the server's package index to apply the repository changes.

    ```console
    $ sudo dnf update
    ```

1. Install MongoDB.

    ```console
    $ sudo dnf -y install mongodb-org
    ```

1. Swap the default `mongodb-mongosh` shell package with the `mongodb-mongosh-shared-openssl3` package.

    ```console
    $ sudo dnf -y swap mongodb-mongosh mongodb-mongosh-shared-openssl3
    ```

    OpenSSL 3 is the default OpenSSL version on Rocky Linux 9, and the default `mongodb-mongosh` MongoDB shell package is not compatible with the version. Installing the `mongodb-mongosh-shared-openssl3` package enables MongoDB to use OpenSSL 3 on your server.

## Manage the MongoDB System Service

MongoDB uses the `mongod` system service to manage the database server runtime and processes. Follow the steps below to enable the MongoDB service to start at boot and run it on your server.

1. Enable MongoDB to start automatically at system boot.

    ```console
    $ sudo systemctl enable mongod
    ```

1. Start the MongoDB service.

    ```console
    $ sudo systemctl start mongod
    ```

1. View the MongoDB service status and verify that it's running.

    ```console
    $ sudo systemctl status mongod
    ```

    Output:

    ```
    ● mongod.service - MongoDB Database Server
      Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
      Active: active (running)
        Docs: https://docs.mongodb.org/manual
     Main PID: 6919 (mongod)
      Memory: 149.8M
      CGroup: /system.slice/mongod.service
              └─6919 /usr/bin/mongod --config /etc/mongod.conf
    ```

## Secure MongoDB

MongoDB uses plain authentication by default and does not require password usage to perform administrative tasks on the server. Follow the steps below to enable secure password authentication to access the MongoDB shell.

1. Access the MongoDB shell.

    ```console
    $ mongosh
    ```

1. Switch to the `admin` database.

    ```
    > use admin
    ```

1. Create a new `mongodbadmin` administrative user with full privileges to any database. Then, enter a strong password when prompted.

    ```
    > db.createUser( 
     {
       user: "mongodbadmin",
       pwd: passwordPrompt(),
       roles: [ 
        { role: "userAdminAnyDatabase", db: "admin" },
        { role: "readWriteAnyDatabase", db: "admin" },
        { role: "dbAdminAnyDatabase", db: "admin" }
       ]    
     }
    )
    ```

    Output:

    ```
    Enter password
    ***{ ok: 1 }
    ```

1. View all MongoDB users and verify that the `mongodbadmin` user is available.

    ```
    > db.getUsers()
    ```

    Output:

    ```
    {
      users: [
        {
          _id: 'admin.mongodbadmin',
          userId: UUID('93f37099-85f9-4b6e-a072-09c2b1045462'),
          user: 'mongodbadmin',
          db: 'admin',
          roles: [
            { role: 'dbAdminAnyDatabase', db: 'admin' },
            { role: 'userAdminAnyDatabase', db: 'admin' },
            { role: 'readWriteAnyDatabase', db: 'admin' }
          ],
          mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
        }
      ],
      ok: 1
    }
    ```

1. Exit the MongoDB shell.

    ```
    > exit
    ```

1. Open the main `mongod.conf` MongoDB configuration file.

    ```console
    $ sudo nano /etc/mongod.conf
    ```

1. Add the following security configuration at the end of the file.

    ```yaml
    security:
        authorization: enabled
    ```

    Save and close the file.

1. Restart the MongoDB service to apply the changes.

    ```console
    $ sudo systemctl restart mongod
    ```

## Access MongoDB

Follow the steps below to access the MongoDB shell to create new users, databases, and insert documents to a database.

1. Access the MongoDB shell using the `mongodbadmin` administrative user you created.

    ```console
    $ mongosh -u mongodbadmin -p --authenticationDatabase admin
    ```

    Enter the administrator password you created earlier when prompted.

1. Create a new `vultr_test` database.

    ```
    > use vultr_test
    ```

1. Create a new user such as `testuser` with full privileges to the `vultr_test` database.

    ```
    > db.createUser(
      {
       user: "testuser",
       pwd: passwordPrompt(),
       roles: [ { role: "readWrite", db: "vultr_test" } ]
      }
    )
    ```

    Enter a new strong user password when prompted.

    Output:

    ```
    Enter password:
    ********{ ok: 1 }
    ```

1. Exit the MongoDB shell.

    ```
    > exit
    ```

1. Access the MongoDB shell as `testuser` and enter the user password when prompted.

    ```console
    $ mongosh -u testuser -p --authenticationDatabase vultr_test
    ```

1. Switch to the `vultr_test` database.

    ```
    > use vultr_test
    ```

1. Insert a new document into the database with the message `Greetings from Vultr` to create a new `messages` collection.

    ```
    > db.messages.insertOne({message: "Greetings from Vultr" })
    ```

   Output:

    ```
    {
      acknowledged: true,
      insertedId: ObjectId('67750a2667bb6ae4a4fad9e0')
    }
    ```

1. View all records in the `messages` collection and verify that the new document is available.

    ```
    > db.messages.find()
    ```

    Output:

    ```
    [
      {
        _id: ObjectId('67750a2667bb6ae4a4fad9e0'),
        message: 'Greetings from Vultr'
      }
    ]
    ```

1. Exit the MongoDB shell.

    ```
    > exit
    ```

## Conclusion

You have installed MongoDB on Rocky Linux 9 and created a new database to verify the installation. You can use MongoDB to create databases, manage users, and store documents to match your application needs. For more information and configuration options, visit the [MongoDB documentation](https://docs.mongodb.com/).
