This article notes the steps to install Mongodb on Ubuntu.
Setup in Ubuntu
install gnupg
Install gnupg using the following command.
sudo apt-get install gnupg |
GPG Key Import
Import public GPG Key.
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \ sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \ –dearmor |
Create a list file for MongoDB
The command to create a List File varies depending on the Ubuntu Version. Check the commands from your OS Version in the List below.
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/
Incidentally, Ubuntu 22.04 was used in this article, so from Tab, click Ubuntu 22.04 and Copy the command.
echo “deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list |
Get your Ubuntu Version
If you do not know your OS Version, use the following command to check the OS Version.
lsb_release –a |
update
Update the operating system.
sudo apt-get update |
Install mongodb
Install the latest version of Mongo DB using the following command.
sudo apt-get install -y mongodb-org |
Init System
The last step is to start, stop and check the status of MongoDB Process on the OS using the systemd command.
Start
You can start MongoDB with the following command.
sudo systemctl start mongod |
Stop
You can stop MongoDB with the following command.
sudo systemctl stop mongod |
Restart
You can restart MongoDB with the following command.
sudo systemctl restart mongod |
Result
Finally, you can use this command to check the status of the MongoDB.
sudo systemctl status mongod |
Done!The state of MongoDB is now Active (Running)!