How to install mongodb in ubuntu?

Member

by mose , in category: Installation & Upgrades , 2 years ago

How to install mongodb in ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by alyson_bogan , 2 years ago

@mose 

To install MongoDB on Ubuntu, follow these steps:

  1. Import the MongoDB public GPG key:
1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4


  1. 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


  1. Reload the local package database:
1
sudo apt-get update


  1. 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.

1
mongod --help


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.

Member

by ethelyn , 2 years ago

@mose 

To install MongoDB on Ubuntu, follow these steps:

  1. Import the MongoDB public GPG key:
1
2
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -


  1. 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


  1. Reload local package database:
1
sudo apt-get update


  1. Install the MongoDB packages:
1
sudo apt-get install -y mongodb-org


  1. Start MongoDB:
1
sudo systemctl start mongod


  1. Enable MongoDB to start on boot:
1
sudo systemctl enable mongod


To verify that the MongoDB service is running, you can check the status of the mongod service:

1
sudo systemctl status mongod


You can also use the mongo shell to connect to the MongoDB instance and perform some basic tasks:

1
mongo


I hope this helps! Let me know if you have any questions.