Zsh: command not found: mongo

When you encounter the error message “zsh: command not found: mongo”, it indicates that the mongo command is not recognized by your shell.

This error commonly occurs when the MongoDB shell (mongo) is not installed or not properly configured. To resolve this issue, you can follow these steps:

  1. Check MongoDB Installation: Ensure that MongoDB is installed on your system. You can check this by running the following command in your terminal:

    mongod --version

    If this command shows the MongoDB version, it means MongoDB is installed.

  2. Add MongoDB to System’s PATH: If MongoDB is installed, but the mongo command is still not recognized, it might be because the MongoDB binaries directory is not included in the system’s PATH environment variable. You can add it by following these steps:

    1. Open the terminal and run the following command to edit the .zshrc file:

      vi ~/.zshrc
    2. Press the i key to enter the insert mode and add the following line to the file:

      export PATH="/usr/local/bin:$PATH"
    3. Press the Esc key, then type :wq and hit Enter to save and exit the file.
    4. Finally, to apply the changes to the current terminal session, run the following command:

      source ~/.zshrc
  3. Verify MongoDB Installation: After adding MongoDB to the system’s PATH, you can verify the installation by running the mongo command again:

    mongo --version

    If it displays the MongoDB version without any errors, MongoDB is now properly configured on your system.

By following these steps, you should be able to resolve the “zsh: command not found: mongo” error and use the mongo command successfully. Remember to adapt the steps to your specific operating system and MongoDB installation path.

Example Output:

$ mongod --version
db version v4.4.6
Build Info: {
    "version": "4.4.6",
    "gitVersion": "xxxx",
    "...."
}

$ mongo --version
MongoDB shell version v4.4.6
Build Info: {
    "version": "4.4.6",
    "gitVersion": "xxxx",
    "...."
}

Read more interesting post

Leave a comment