# MongoDB - Installation on RedHat 9

#### Step 1: Configure the MongoDB Repository

<div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cb="" data-sfc-cp="" data-sfc-root="c" id="bkmrk-create-a-new-reposit" jsaction="" jscontroller="a7qCn" jsuid="Olf00e_17" role="heading">Create a new repository file named `/etc/yum.repos.d/mongodb-org-7.0.repo` using your preferred text editor (like `vi` or `nano`), or by using the `cat` command as shown below. This example uses version 7.0; you can check the <span class="T286Pc" data-processed="true" data-sfc-cb="" data-sfc-cp="" data-sfc-root="c">MongoDB repositories</span> for the latest version.</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cb="" data-sfc-cp="" data-sfc-root="c" id="bkmrk-" jsaction="" jscontroller="a7qCn" jsuid="Olf00e_17" role="heading"></div>```bash
cat <<EOF | sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-7.0.asc
EOF
```

Step 2: Install MongoDB Packages

Install the latest stable version of MongoDB:

```bash
sudo dnf install -y mongodb-org
```

Step 3: Start and Enable the MongoDB Service

Start the service and enable it to run on boot:

```bash
sudo systemctl start mongod
sudo systemctl enable mongod
# Verify status:
sudo systemctl status mongod
```

Step 4: Configure the Firewall (Optional)

If needed, open port `27017` to allow remote access:

```bash
sudo firewall-cmd --permanent --add-port=27017/tcp
sudo firewall-cmd --reload
```

Step 5: Begin Using MongoDB

Launch the shell to connect to your local instance:

```bash
mongosh
```