@mose
To install MongoDB on Ubuntu, follow these steps:
- Import the MongoDB public GPG key:
1
|
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
|
- Create a list file for MongoDB:
1
|
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
|
- Reload the local package database:
- Install the MongoDB packages:
1
|
sudo apt-get install -y mongodb-org
|
This will install the latest stable version of MongoDB. To install a specific version, you can use the version number in place of 4.4
in the echo
command above. For example, to install version 4.2, you would use 4.2
instead.
After installation, the MongoDB service will start automatically. You can check the status of the service using the following command:
1
|
systemctl status mongod
|
To stop, start, or restart the MongoDB service, you can use the following commands:
1
2
3
|
sudo systemctl stop mongod
sudo systemctl start mongod
sudo systemctl restart mongod
|
You can also use the mongod
command to manually start and stop the MongoDB daemon.
This will display a list of options for starting and stopping the daemon.
I hope this helps! Let me know if you have any questions.