Skip to content
Latchkey

MongoDB "mongosh: command not found" in CI

The shell could not find mongosh. The modern MongoDB Shell is a standalone package, not bundled with a mongo service container or with the mongodb Node driver, so a runner without it fails any mongosh step.

What this error means

A step running mongosh ... fails with "mongosh: command not found" and exit code 127, even when a mongo service container is present.

bash
/home/runner/work/_temp/script.sh: line 1: mongosh: command not found
Error: Process completed with exit code 127.

Common causes

mongosh is not installed on the runner

The service container ships mongod, but the runner host has no mongosh binary on PATH.

Relying on the legacy mongo shell

The old mongo shell was removed in MongoDB 6+, so scripts that assume it also break; the replacement is mongosh.

How to fix it

Install mongosh in a step

  1. Add the MongoDB apt repository, or download the mongosh tarball.
  2. Install mongodb-mongosh so mongosh is on PATH.
  3. Run your shell steps after installation.
Terminal
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb.gpg
echo "deb [signed-by=/usr/share/keyrings/mongodb.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update && sudo apt-get install -y mongodb-mongosh

Run mongosh inside the mongo image

If a mongo container is running, exec mongosh inside it instead of on the host.

Terminal
docker exec <mongo-container> mongosh --eval 'db.adminCommand({ping:1})'

How to prevent it

  • Install mongosh explicitly; do not assume it exists on the runner.
  • Use mongosh, not the removed legacy mongo shell.
  • Pin the mongosh version for reproducible steps.

Frequently asked questions

What causes ""mongosh: command not found""?
The service container ships mongod, but the runner host has no mongosh binary on PATH.
How do I fix "mongosh: command not found"?
Install mongosh in a step

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card