freeCodeCamp setup issue

I am doing setup on windows10 via wsl2. I’ve done everything from the guide uptill [Step 3: Start MongoDB and seed the database]. But after that when i type “mongod”, it shows error that command not found.

devbhuva@DESKTOP-UHU4NV9:~/freeCodeCamp$ mongod
mongod: command not found

Please help me out

Welcome there,

Trivial question, but have you followed the prerequisite to install Mongodb?

I tried to reconfirm what you asked and got to know that mongod --version isn’t working. I tried to reinstall mongo in linux following all the steps in documentation but then to I end up with this


After this i tried to install the missing dependencies but still it isn’t working. Thanks for your response.

I presume you are installing MongoDB using their Windows Installer.

One of the core requirements of installing freeCodeCamp is Linux (or Linux like) environment. This means all software you need should also be within the Linux-based environment.

Here is an explanation of how WSL2-based installation behaves:

When you launch a WSL2 terminal (like the Ubuntu terminal in your screenshot), you are running a different operating system - Ubuntu, in your case, on your machine. WSL2 acts like a middleman.

You are running an OS within an OS (I am oversimplifying to keep this easier to understand).

Anything you install on the Windows side is NOT automatically made available on the Ubuntu side. I hope that makes sense.

As a fix, you will need MongoDB to be installed on the Ubuntu side; here are two ways:

  • Difficult - Follow the MongoDB Guide for Linux (Although I think I could not get it working properly).
  • Easy - Use Docker Desktop for Windows and then run MongoDB as a container.
  • Super easy - Use a cloud service like MongoDB Atlas. This works on all operating systems because you would use the correct URI from their dashboard.

Using Docker Desktop (not just the docker agent) for Windows makes life a bit easier because your services (containers like MongoDB or others like Postgres and MySQL) are exposed on both the Ubuntu side and the Windows side.

Anyways, the choice is yours. If you are really-really interested, we linked an article to a generic setup for Node.js + MongoDB + Docker on WSL2 in our guide that you followed. It should be in the footnotes. Trust me, I know the person who wrote it :wink:

First of all Thanks a ton for your reply. I really got to learn many things. Really grateful. But actually, I had referred the doc you mentioned and also used Docker Desktop and I can also see MongoDB in Docker’s container.


But still when I run ‘mongod --version’ it shows command not found.

devbhuva@DESKTOP-UHU4NV9:~$ docker pull mongo:4.0
4.0: Pulling from library/mongo
Digest: sha256:4ca81c89ad08f4cfa9906005126112bffe8fb363800466ef5e50f6238f6f6af1
Status: Image is up to date for mongo:4.0
docker.io/library/mongo:4.0
devbhuva@DESKTOP-UHU4NV9:~$ docker run -it \
ngodata:>   -v mongodata:/data/db \
>   -p 27017:27017 \
>   --name mongodb \
estart u>   --restart unless-stopped \
>   -d mongo:4.0
a969b8cd8f370f6b309623431d6e09be8dc24bdbb07b76f120bec15c4b653fc2
ERRO[0001] error waiting for container: context canceled
devbhuva@DESKTOP-UHU4NV9:~$ node -v
v18.15.0
devbhuva@DESKTOP-UHU4NV9:~$ pnpm -v
8.1.1
devbhuva@DESKTOP-UHU4NV9:~$ mongod -v
mongod: command not found

It looks like you have 2 problems:

  1. You encountered an error when installing mongodb-org - you need to ensure all required packages are correctly installed, before trying to use mongod
  2. You cannot use mongod in the terminal, after starting mongodb in a container. This is expected, because your terminal session is not inside the container - you do not have direct (easy) access to anything in the container, and vice-a-versa.

If you want to continue with option 2 of using mongodb in a container, then you can work within the container context by using the docker exec command.

It looks like there is an error, when starting the container. I am not sure the steps you need to take to debug this, but getting more of the logs from the mongod instance would be helpful.

Hope this clarifies

Okay. Thank you so much. I’ll try this.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.