gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
run mongodb on ubuntu
- User
run mongodb on ubuntu
- Assistant
Certainly! Here’s a step-by-step guide to install and run MongoDB on Ubuntu (works for Ubuntu 20.04, 22.04, and similar):
1. Import the MongoDB public GPG Key
wget -qO - https://pgp.mongodb.com/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
2. Create the MongoDB source list file
For Ubuntu 22.04 (Jammy):
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.listFor Ubuntu 20.04 (Focal):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
3. Update your package list
sudo apt update
4. Install MongoDB
sudo apt install -y mongodb-org
5. Start and Enable MongoDB
sudo systemctl start mongod sudo systemctl enable mongod
6. Check MongoDB Status
sudo systemctl status mongodYou should see that MongoDB is active (running).
7. Connect to MongoDB
mongoshThis opens the MongoDB shell.
8. (Optional) Allow Remote Connections
Edit the config file:
sudo nano /etc/mongod.confFind the
bindIpline and change it from:bindIp: 127.0.0.1to
bindIp: 0.0.0.0Then restart MongoDB:
sudo systemctl restart mongod
9. (Optional) Uninstall MongoDB
sudo systemctl stop mongod sudo apt purge mongodb-org* sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongodb
You now have MongoDB running on Ubuntu!
Let me know if you need help with a specific version or want to set up authentication.