This guide will assist you in installing MongoDB using the Windows Subsystem for Linux (WSL) via the Command Line.
Install MongoDB – Community Edition
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:
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.
Refresh your local package database with the command:
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.
Resolve Unmet Dependencies Error
If you encounter an error regarding unmet dependencies, execute the following steps:
Download libssl1.1_1.1.1f-1ubuntu2_amd64.deb:
Install the downloaded package using dpkg:
Create Data and DB Directories
Ensure you are still in the root of the Ubuntu FS by typing cd ~. Confirm with pwd, which should display /home/<user>/.
Create the necessary directories by typing:
This command creates a data directory with a db subdirectory. The -p flag ensures the parent directory is created if it doesn’t exist.
Start mongod Server and mongo Shell
Open a new terminal window and run the following command to start the MongoDB server:
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.
Troubleshooting
For further assistance, consult the MongoDB Install Docs or feel free to reach out directly via message or email.
credis –
github
stackoverflow