This guide will assist you in installing MongoDB using the Windows Subsystem for Linux (WSL) via the Command Line.
- Launch a terminal (the Ubuntu app) and navigate to the root of the Ubuntu File System by typing
cd ~
. - Copy and paste the following command into the terminal to import the MongoDB public GPG Key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
- Next, add the MongoDB package to your sources list by pasting this line into the terminal:
Note: Ensure you are on Ubuntu Xenial. We'll update this for Zesty LTS when available.
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
- Refresh your local package database with the command:
sudo apt-get update
- Install MongoDB by running the following command:
This will install the latest stable version (MongoDB 3.6 at the time of writing). Refer to the provided link if you wish to install a different version.
sudo apt-get install -y mongodb-org
If you encounter an error regarding unmet dependencies, execute the following steps:
-
Download
libssl1.1_1.1.1f-1ubuntu2_amd64.deb
:wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
-
Install the downloaded package using
dpkg
:sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
- Ensure you are still in the root of the Ubuntu FS by typing
cd ~
. Confirm withpwd
, which should display/home/<user>/
. - Create the necessary directories by typing:
This command creates a
sudo mkdir -p data/db
data
directory with adb
subdirectory. The-p
flag ensures the parent directory is created if it doesn't exist.
-
Open a new terminal window and run the following command to start the MongoDB server:
sudo mongod --dbpath ~/data/db
You should see status messages, with the last line indicating that the server is waiting for connections on port 27017.
-
In another WSL window, type
mongo
to launch the MongoDB shell. You'll see a connection notification in the first terminal window and the prompt in the new window should change to>
indicating you're in the mongo shell. -
Refer to this cheat sheet for guidance on using the mongo shell.
-
To exit the shell, press
Ctrl + C
. You'll receive a confirmation message before returning to the command line.
For further assistance, consult the MongoDB Install Docs or feel free to reach out directly via message or email.