Installing MongoDB on the Linux Subsystem with Ubuntu 20.04 Made Easy

February 5, 2023 | By Gerald | Filed in: Linux Subsystem.

Step-by-step guide on installing MongoDB on the Linux Subsystem with Ubuntu 20.04. Get the latest tips and tricks to ensure a smooth installation process and start using MongoDB on Linux Subsystem.

Step 1. Open the Linux terminal on your Windows system.

Installing MongoDB on the Linux Subsystem with Ubuntu 20.04

Step 2. Import the MongoDB public key used to authenticate packages:

sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

Step 3. Add the MongoDB repository details:

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

Step 4. Update the local package database with the MongoDB packages:

sudo apt-get update

Step 5. Install the MongoDB package:

sudo apt-get install -y mongodb-org

Step 6. Start the MongoDB service:

sudo systemctl start mongod

Step 7. Enable MongoDB to automatically start at boot:

sudo systemctl enable mongod

Step 8. Verify the MongoDB service is running:

sudo systemctl status mongod

Step 9: Connect to MongoDB shell:

mongo

Step 10. Create a new database:

use database_name

Step 11. Insert a new document into a collection:

db.collection_name.insert({key: "value"})

Step 12. Find all documents in a collection:

db.collection_name.find()

Step 13. Update a document in a collection:

db.collection_name.update({query}, {$set: {key: "new_value"}})

Step 14. Delete a document in a collection:

db.collection_name.remove({query})

Step 15. List all databases:

show dbs

Step 16: Switch to a specific database:

use database_name

With this comprehensive guide, you can now easily install MongoDB on the Linux Subsystem with Ubuntu 20.04. Follow the step-by-step instructions and bring powerful database functionality to your Linux environment

I hope this blog has helped you. Feel free to leave a comment in the section below for further recommendations

SHARE THIS ARTICLE

Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *