sources:
- 24.04 LTS ("Noble")
- 22.04 LTS ("Jammy")
- 20.04 LTS ("Focal")
cat /etc/lsb-release
Output should be similar to:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.2 LTS"
- Import the public key
cd ~
sudo apt-get update
sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
--dearmor
- Create the list file for MongoDB
To create the list file for Ubuntu 24.04 (Noble) for example:
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
- Reload the package database
sudo apt-get update
- Install MongoDB Community Server
sudo apt-get install -y mongodb-org
- Create the data directory
sudo mkdir -p data/db
sudo chown -R `id -u`:`id -g` data/db
- Download the latest version of MongoDB Compass from the MongoDB Download Center.
- To install the downloaded package on Windows, you can use double-click the
.msi
file. - Follow the installation instructions in the installer.
- After installation, you can launch MongoDB Compass from the Start menu or by searching for "MongoDB Compass" in the Windows search bar.
- Start the MongoDB service
sudo systemctl start mongod
- Verify that MongoDB has started successfully
sudo systemctl status mongod
- Enable MongoDB to start on boot
sudo systemctl enable mongod
- Open MongoDB Compass.
Warning: When using MongoDB installed on WSL2, you need to connect to the MongoDB instance using the correct connection string. Since WSL2 runs a separate instance of Linux, you will typically connect to it using localhost
and the default port 27017
.
if the connection fails, you may need to ensure that the MongoDB service is running in WSL2 and that you are using the correct IP address or hostname.
-
In the "New Connection" dialog, enter the connection string:
mongodb://localhost:27017
-
Click "Connect" to establish the connection to your MongoDB instance running on WSL2.
-
You should now be able to view and manage your MongoDB databases and collections through MongoDB Compass.