This doc will guide you through installing Mongo DB using WSL through the Command Line.
Most of the steps are listed out here, but this guide will trim them down and make it more straight forward for our needs. There is also 1 step that is not in the link above as well, which will be noted when we come across it.
- Open a Windows PowerShell and type wsl.
- Type
cd ~
to go to the root of the Ubuntu File System. - Paste
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.
- Paste
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
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.
- 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 WSL window 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 File System.
- 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 test some commands in your new mongo database.
- 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. Feel free to grab a TA or Instructor to help you with any debugging, or send me an email at [email protected] if you are still stuck and I'll help you out