IMPORTANT: The legacy mongo shell was deprecated in the MongoDB 5.0 release and removed in the 6.0 release packages. The modern replacement is the MongoDB Shell (mongosh) which is a more fully featured JavaScript and Node.js REPL environment that is also compatible with a broader range of MongoDB server versions. For example, as of Feb 2024 mongosh was supporting MongoDB Server v4.2 and greater.
(original answer from March 2019 below)
If you just want the mongo shell, you could install the mongodb-clients package mentioned in your question. However, note that this includes an older shell version (3.6.3).
The official MongoDB packages are updated with each minor release and you should ideally install a shell version matching your MongoDB server's major version (3.6, 4.0). Significant mismatches in shell versus server versions can result in some subtle errors as well as missing or outdated helpers. For example, the MongoDB 3.6.x shell doesn't have helpers for transactions (which were added in 4.0).
The MongoDB documentation includes information on Installing the official packages on Ubuntu. There is a mongodb-org-shell package which only includes the MongoDB shell, and you may also want to install mongodb-org-tools for other command-line tools (mongodump, mongorestore, ...).
It would be best to follow the instructions in the MongoDB documentation as some details may change in future (such as the signing key), but the general steps to follow for MongoDB 4.0 on Ubuntu 18.04 (Bionic) are:
Import the public key used to sign packages from MongoDB, Inc
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4Create a package list file for MongoDB
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.listUpdate your local package database
sudo apt-get updateInstall the desired MongoDB package(s)
sudo apt-get install -y mongodb-org-shell
NOTE: The legacy mongo shell was deprecated in the MongoDB 5.0 release and removed in the 6.0 release packages. The modern replacement is the MongoDB Shell (mongosh) which is a more fully feastured JavaScript and Node.js REPL environment.
IMPORTANT: The legacy mongo shell was deprecated in the MongoDB 5.0 release and removed in the 6.0 release packages. The modern replacement is the MongoDB Shell (mongosh) which is a more fully featured JavaScript and Node.js REPL environment that is also compatible with a broader range of MongoDB server versions. For example, as of Feb 2024 mongosh was supporting MongoDB Server v4.2 and greater.
(original answer from March 2019 below)
If you just want the mongo shell, you could install the mongodb-clients package mentioned in your question. However, note that this includes an older shell version (3.6.3).
The official MongoDB packages are updated with each minor release and you should ideally install a shell version matching your MongoDB server's major version (3.6, 4.0). Significant mismatches in shell versus server versions can result in some subtle errors as well as missing or outdated helpers. For example, the MongoDB 3.6.x shell doesn't have helpers for transactions (which were added in 4.0).
The MongoDB documentation includes information on Installing the official packages on Ubuntu. There is a mongodb-org-shell package which only includes the MongoDB shell, and you may also want to install mongodb-org-tools for other command-line tools (mongodump, mongorestore, ...).
It would be best to follow the instructions in the MongoDB documentation as some details may change in future (such as the signing key), but the general steps to follow for MongoDB 4.0 on Ubuntu 18.04 (Bionic) are:
Import the public key used to sign packages from MongoDB, Inc
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4Create a package list file for MongoDB
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.listUpdate your local package database
sudo apt-get updateInstall the desired MongoDB package(s)
sudo apt-get install -y mongodb-org-shell
NOTE: The legacy mongo shell was deprecated in the MongoDB 5.0 release and removed in the 6.0 release packages. The modern replacement is the MongoDB Shell (mongosh) which is a more fully feastured JavaScript and Node.js REPL environment.
You might want to install mongosh (MongoDB Shell) instead. The legacy mongo shell has been deprecated since MongoDB v5.0 and replaced by mongosh. From the official website:
The new MongoDB Shell,
mongosh, offers numerous advantages over the legacy mongo shell, such as:
- Improved syntax highlighting.
- Improved command history.
- Improved logging.
Currently mongosh supports a subset of the mongo shell methods. Achieving feature parity between mongosh and the mongo shell is an ongoing effort.
To maintain backwards compatibility, the methods that mongosh supports use the same syntax as the corresponding methods in the mongo shell. To see the complete list of methods supported by mongosh, see MongoDB Shell Methods.
Further reference: Compatibility Changes with Legacy mongo Shell
Videos
Multiple options:
- Using the system's files reference database:
$ sudo updatedb; locate mongo
- Restart your shell after install and try:
Both mongo and mongod commands are in the same dir, so if this dir has been added in your $PATH by the installer, this should tell you where they are.
$ which mongo
$ which mongod
- check manually in
/var/libor/usr/localor/usr/bin(must be a symlink though) - check the daemon process line which usually give a hint about the path as it show the path of the config file
$ ps -efa | grep mongo
I think I solved the connectivity problem based on this question:
Then I run as indicated in the link shown above the commands:
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
An now all seems to be working ok.
On Ubuntu 16.04 to get the 4.2 mongo client
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install mongodb-org-shell
Use official MongoDB Documents they already mentioned how to install a version of your choice. Steps for installation for Ubuntu 12.04 and 14.04
For Ubuntu 16.04 use this
NOTE:- Before that beware that you don't have any existing repository file for MongoDB. You can check using sudo apt-get update.While updating it will show if you have any. If you have then delete it using sudo rm /etc/apt/sources.list.d/mongodb*.list and then install MongoDB
You may want to try "mongosh" command.
As specified on documentation you provided.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
You need a client in order to interact with mongoDB deployment such as mongosh or Compass.
The MongoDB Shell, mongosh, is a fully functional JavaScript and Node.js 16.x REPL environment for interacting with MongoDB deployments. You can use the MongoDB Shell to test queries and operations directly with your database.
Hope It helps.
The mongodb-server and the mongodb-clients debian packages were for MongoDB 3.x, maintained by Ubuntu.
Since MongoDB 4.x, MongoDB provide their own debian packages, but they named them mongodb-org-server, mongodb-mongosh and mongodb-cli. The client command mongo is split into two different commands mongocli and mongosh.