This doc will guide you through installing MongoDB using WSL through the Command Line.
Most of the steps are listed here, but this guide will trim them down and make it a bit more straight forward for our needs.
- Open a terminal (the Ubuntu app) and type
cd ~
to go to the root of the Ubuntu File System. - Copy and paste this into the terminal
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
. This will import the MongoDB public GPG Key so we can use the official MongoDB supported pkg in apt. - Next, paste this one line into the terminal
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
. This will add the deb to your sources list. Note that you must be on Ubuntu Xenial. When Zesty gets LTS we will update this doc. - Reload your local pkg database by typing
sudo apt-get update
. - Run the install command by pasting this into the terminal
sudo apt-get install -y mongodb-org
. This will install the most stable version of mongod, 3.6 at time of writing. If you want to install a different version please refer to the link above.
- NOTE this step is not included in the link above.
- Make sure you are still on the root of the Ubuntu FS by typing
cd ~
. If you type pwd it should output/home/<user>/
- Type
sudo mkdir -p data/db
- This will make a data directory with a db sub directory.
- The
-p
flag means make the parent directory if it doesn't exist.
- Open a new terminal and type
sudo mongod --dbpath ~/data/db
.
- You should see a bunch of stuff pop up, but the last line should be something like
waiting for connections on port 27017
. - This will run your mongod service for you, allowing users to connect to it.
- The command
--dbpath
will change the path where mongo saves your databases and records. You can choose your own location if you want, but in the section above we just added it to the root of your Ubuntu user.
- Open a new WSL window and type
mongo
.
- You should see a connection notification on the first terminal window pop up.
- In the new window you should see some messages pop up and finally your command line should be changed to a
>
symbol which means that you are in the mongo shell.
- Follow this link to my Mongo Shell Cheat Sheet how to use your new mongo shell.
- To exit the shell, press
ctrl + c
. You should get a neat message, then you'll be returned to your command line!
Here is a link to the Install Docs for MongoDB. Also feel free to message or email me directly.