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 (8)

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

Collapse
 
kastoestoramadus profile image
Waldemar Wosiński

On debian based Pengwin distro, made for WSL I got:

Adding user `mongodb' to group `mongodb' ...
Done.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Setting up mongodb-org-shell (6.0.12) ...
Enter fullscreen mode Exit fullscreen mode

Any idea how to proceed?

Collapse
 
kastoestoramadus profile image
Waldemar Wosiński

Solution: via pengwin-setup you may easily install systemd.

Collapse
 
arielro85 profile image
arielro85

What is your WSL Ubuntu Version?

Collapse
 
kastoestoramadus profile image
Waldemar Wosiński

It was Pengwin paid distro. I've solved it with built in setup app.
For now I've switched to Ubuntu fresh installation as it has fixed most reasons why the paid distro was made.
I find this now less troublesome to go through the instructions for Ubuntu.

Thread Thread
 
arielro85 profile image
arielro85

Glad that it helps. I forgot to mentions that I did this on Ubuntu 22.04