DEV Community

Kazi Abdur Rakib
Kazi Abdur Rakib

Posted on

How to Install MongoDB on Ubuntu 22.04 | Step-by-Step Guide to Using MongoDB [With Examples]

==> official blogs

1.

https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/#std-label-install-mdb-community-ubuntu

2.

Image description

=>
It looks like you have downloaded the MongoDB Compass Debian package (mongodb-compass_1.40.4_amd64.deb). To install MongoDB Compass on a Debian-based Linux system (such as Ubuntu), you can use the following steps:

  1. Open a terminal.

  2. Navigate to the directory where the downloaded .deb file is located. For example, if it's in the Downloads folder, you can use the following command:

   cd ~/Downloads
Enter fullscreen mode Exit fullscreen mode
  1. Install MongoDB Compass using the dpkg package manager. Replace mongodb-compass_1.40.4_amd64.deb with the actual filename if it's different:
   sudo dpkg -i mongodb-compass_1.40.4_amd64.deb
Enter fullscreen mode Exit fullscreen mode
  1. If there are any missing dependencies, you might see an error. To resolve dependencies, run the following command:
   sudo apt-get install -f
Enter fullscreen mode Exit fullscreen mode

This command will attempt to fix missing dependencies.

  1. After the installation is complete, you can launch MongoDB Compass from the terminal or find it in your application menu.
   mongodb-compass
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can launch it from the application menu or using the Dash.

Please note that you may need to have administrative privileges (sudo) to install packages. If you encounter any issues during the installation, the error messages should provide information about missing dependencies or other problems.

If you face any specific errors or issues during the installation, feel free to share the details, and I'll do my best to assist you.

3.

*The Smartest IDE for MongoDB
*

https://nosqlbooster.com/

best blogs==> https://www.cherryservers.com/blog/install-mongodb-ubuntu-22-04

https://www.youtube.com/watch?v=I2sjJqFTfWY

sudo apt-get install gnupg curl
Enter fullscreen mode Exit fullscreen mode

curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor
Enter fullscreen mode Exit fullscreen mode

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Enter fullscreen mode Exit fullscreen mode

ls -l /etc/apt/sources.list.d/
Enter fullscreen mode Exit fullscreen mode

sudo apt-get update

Enter fullscreen mode Exit fullscreen mode

sudo apt-get install -y mongodb-org
Enter fullscreen mode Exit fullscreen mode

Certainly! Here are the commands formatted in Markdown code blocks:

# 1. Start MongoDB.
# Start the mongod process
sudo systemctl start mongod

# If Unit not found error, run the following command:
sudo systemctl daemon-reload

# Retry the start command
sudo systemctl start mongod

# 2. Verify that MongoDB has started successfully.
sudo systemctl status mongod

# Optionally enable MongoDB to start on system reboot
sudo systemctl enable mongod

# 3. Stop MongoDB.
# Stop the mongod process
sudo systemctl stop mongod

# 4. Restart MongoDB.
# Restart the mongod process
sudo systemctl restart mongod

# Check process status and logs for errors
# 5. Begin using MongoDB.
# Start a mongosh session
mongosh

# For more connection options, refer to mongosh documentation
# MongoDB provides Getting Started Guides for different driver editions
# See the Start Developing with MongoDB documentation for driver-specific details
Enter fullscreen mode Exit fullscreen mode
mongod --version
Enter fullscreen mode Exit fullscreen mode
sudo systemctl status mongod
Enter fullscreen mode Exit fullscreen mode
sudo systemctl start mongod
Enter fullscreen mode Exit fullscreen mode
sudo systemctl status mongod
Enter fullscreen mode Exit fullscreen mode
sudo ss -pnltu | grep 27017
Enter fullscreen mode Exit fullscreen mode

sudo systemctl enable mongod
Enter fullscreen mode Exit fullscreen mode

Step 3: Create MongoDB database and user

mongosh
Enter fullscreen mode Exit fullscreen mode
With the Admin user in place, the next step is to enable authentication. For this, exit the MongoDB shell and open the mongod.conf file.

sudo nano /etc/mongod.conf
Scroll down and find the security section. Uncomment it, add the authorization directive, and set it to enabled.


security:
    authorization: enabled
Note that the authorization parameter is indented while security has no space at the beginning.


Enter fullscreen mode Exit fullscreen mode

Top comments (0)