MongoDB Shell, commonly known as mongosh, is the modern command-line interface for interacting with MongoDB databases. It replaces the legacy mongo shell and provides improved usability, scripting support, and security features.
In this guide, you’ll learn how to install mongosh on Ubuntu (Noble and compatible versions) using MongoDB’s official APT repository. We’ll walk through each step in detail, explain what each command does, and help you verify a successful installation.
This step-by-step tutorial will help you Install MongoDB Shell on Ubuntu quickly and correctly using official and supported methods.
Import the MongoDB Public GPG Key
APT uses GPG keys to verify that the software packages you install come from a trusted source. MongoDB signs its packages with a public GPG key, which must be added to your system before installation.
wget -qO- https://www.mongodb.org/static/pgp/server-8.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-8.0.asc
- wget -qO- downloads the MongoDB GPG key silently
- The pipe (|) sends the key directly to the next command
- sudo tee writes the key to /etc/apt/trusted.gpg.d/
- The key is also displayed in the terminal (no need to copy or save it manually)
Once this command completes successfully, your system will trust MongoDB’s official packages.
If gnupg Not Installed
If you see an error indicating that gnupg is missing, install it first:
apt-get update
apt-get install gnupg -y
After installing gnupg, retry importing the MongoDB GPG key:
wget -qO- https://www.mongodb.org/static/pgp/server-8.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-8.0.asc
Add the MongoDB Repository to APT Sources
Ubuntu’s default repositories do not include MongoDB packages. By adding MongoDB’s official repository, APT can download and install the latest MongoDB tools, including mongosh.
Create the MongoDB list file:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
This command creates a new APT source file,
/etc/apt/sources.list.d/mongodb-org-8.0.list
Reload the Local Package Database
After adding a new repository, you must refresh APT’s package index so it recognizes the MongoDB packages.
apt-get update
This command fetches the latest package information from all configured repositories, including MongoDB’s
Install MongoDB Shell
- mongosh is MongoDB’s modern shell
- Supports JavaScript, Node.js APIs, and OpenSSL
Can use bundled OpenSSL or your system’s OpenSSL installation
apt-get install -y mongodb-mongosh
Verify the Installation
To confirm that mongosh installed correctly,
mongosh --version
This confirms that mongosh is installed and ready to use.
MongoDB Shell is a powerful tool that enhances productivity and security when working with MongoDB databases.
If you need expert help to Install MongoDB Shell on Ubuntu or face issues during setup, our Server Management Services and Linux Server Support Services team is here to help. Contact us today for secure, reliable, and hassle-free server support.