Install MongoDB in Ubuntu 22.04 LTS using this simple command
Import the public key used by the package management system.
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
The operation should respond with an OK.
However, if you receive an error indicating that gnupg is not installed, you can:
Install gnupg and its required libraries using the following command:
sudo apt-get install gnupg
Once installed, retry importing the key:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
Create a list file for MongoDB
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
Reload local package database and install MongoDB
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl start mongod.service
If you receive an error similar to the following when starting mongod:
Failed to start mongod.service: Unit mongod.service not found.
Run the following command first:
sudo systemctl daemon-reload
sudo systemctl status mongod
sudo systemctl enable mongod.service
sudo systemctl restart mongod.service
Check it's running or not
mongosh