DEV Community

arielro85
arielro85

Posted on

Installing MongoDB in WSL2 with Ubuntu-22.04

These last days I've been with no time to practice coding, and one thing stopping me was that I didn't have my dev environment as I would like to.
So this week I decided to write this article on how I did to install MongoDB (latest) on my WSL setup.

Head to root folder

cd /
Enter fullscreen mode Exit fullscreen mode

Install GNUPG

sudo apt-get install gnupg
Enter fullscreen mode Exit fullscreen mode

Issue following command to import GPG keys

curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
   --dearmor
Enter fullscreen mode Exit fullscreen mode

Create List file

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
Enter fullscreen mode Exit fullscreen mode

Reload Packages

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install Mongo db Packages

sudo apt-get install -y mongodb-org
Enter fullscreen mode Exit fullscreen mode

Create DB Folder

mkdir -p data/db
Enter fullscreen mode Exit fullscreen mode

Apply permissions

sudo chown -R `id -un` data/db
Enter fullscreen mode Exit fullscreen mode

Run MongoD

mongod
Enter fullscreen mode Exit fullscreen mode

Verify

You should be able to see something like Waiting for connections","attr":{"port":27017,"ssl":"off" on the terminal.

Hope it helps"

Top comments (3)

Collapse
 
thomasbnt profile image
Thomas Bnt

Hello great post!

Don't hesitate to put colors on your codeblock like this example for have to have a better understanding of your code 😎

console.log('Hello world!');
Enter fullscreen mode Exit fullscreen mode

Example of how to add colors and syntax in codeblocks

Collapse
 
arielro85 profile image
arielro85

Thanks Thomas! :D

Collapse
 
irionx profile image
Sebastián Andrés Kozak • Edited

awesome thank you this is very helpful. I'm so happy that I would kiss you... would you let me? WUW
Image description