Typing mongo on Ubuntu gives command not found after installing MongoDB
mongo: command not foundShort answer
The current MongoDB documentation connects with mongosh, and the old mongo shell is called legacy. So first run mongosh instead of mongo. If mongosh is also not found, it is simply not installed: it is a separate package, and a tgz install of the server does not include it. Add mongodb-mongosh.
Fix it fast
1Find out which cause you have
See which of the two shells exists on the machine.
command -v mongosh mongo mongosh --version2Match what you see, then jump to its fix
What does the error look like?
mongo: command not foundmongosh: command not found
Cause 1 of 2
You are typing the legacy command name
1Check
The MongoDB install guide connects to a deployment with mongosh, and the production notes call mongo the legacy shell.
command -v mongosh2Fix
Use mongosh. It connects to mongodb://localhost:27017 by default.
mongosh3Verify
The prompt opens and a server status command answers.
mongosh --eval 'db.runCommand({ ping: 1 })'Confirmed by mongodb.com
Cause 2 of 2
mongosh is not installed
1Check
mongosh ships separately from the server. The install guide says that with the tgz package you must install mongosh yourself. On Ubuntu, the mongosh page installs it from MongoDB's apt repository as mongodb-mongosh.
apt list --installed 2>/dev/null | grep -i mongosh2Fix
With MongoDB's repository already added, install the package. For a tgz install, follow the mongosh install page instead.
sudo apt-get update
sudo apt-get install -y mongodb-mongosh3Verify
Confirm the version and connect.
mongosh --version
mongoshConfirmed by mongodb.com
How do I stop it coming back?
- Use mongosh in scripts and notes from the start, not mongo.
- After a tgz install, install mongosh as its own step.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
mongod.service exits with an error on Ubuntu and the cause is hidden
Attempted to create lock file on a read-only directory: ...
When mongod.service exits straight away, the reason is in the mongod log, not in systemctl.
2 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix