- Refresh your local package database with the command:
sudo apt-get update
- Install MongoDB by running the following command:
sudo apt-get install -y mongodb-org
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:
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
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:
sudo mkdir -p data/db
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:
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.
Troubleshooting
For further assistance, consult the MongoDB Install Docs or feel free to reach out directly via message or email.
credis -
github
stackoverflow