Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run the mongo shell on Ubuntu

Tags:

mongodb

ubuntu

I just installed MongoDB version 3.2.4 on Ubuntu 15.10 and I want to run the mongo shell. All docs are suggesting to execute first the command cd <mongodb installation dir>

My question is where is that mongodb installation dir? How I can find it?

Apparently it may be something wrong with the mongod. Could not find /usr/bin/mongod Details below.

root@levilinode:/usr/bin# service mongod status
● mongod.service - LSB: An object/document-oriented database
   Loaded: loaded (/etc/init.d/mongod)
   Active: active (exited) since Tue 2016-04-12 14:22:45 EDT; 1h 37min ago
     Docs: man:systemd-sysv-generator(8)

Apr 12 14:22:45 levilinode systemd[1]: Starting LSB: An object/document-oriented database...
Apr 12 14:22:45 levilinode mongod[16541]: Could not find /usr/bin/mongod
Apr 12 14:22:45 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 14:24:02 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 14:24:26 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 15:56:15 levilinode systemd[1]: Started LSB: An object/document-oriented database.

However that files seems to be there:

root@levilinode:/usr/bin# ls -la mong*
-rwxr-xr-x 1 root root 19816422 Mar  7 18:32 mongo
-rwxr-xr-x 1 root root 35865168 Mar  7 18:32 mongod
-rwxr-xr-x 1 root root 14661359 Mar  7 18:32 mongodump
-rwxr-xr-x 1 root root 10523458 Mar  7 18:32 mongoexport
-rwxr-xr-x 1 root root 10395740 Mar  7 18:32 mongofiles
-rwxr-xr-x 1 root root 10636848 Mar  7 18:32 mongoimport
-rwxr-xr-x 1 root root 10125973 Mar  7 18:32 mongooplog
-rwxr-xr-x 1 root root 35551461 Mar  7 18:32 mongoperf
-rwxr-xr-x 1 root root 17331345 Mar  7 18:32 mongorestore
-rwxr-xr-x 1 root root 16086077 Mar  7 18:32 mongos
-rwxr-xr-x 1 root root 10353518 Mar  7 18:32 mongostat
-rwxr-xr-x 1 root root 10213613 Mar  7 18:32 mongotop
like image 411
L.D Avatar asked Apr 12 '16 19:04

L.D


3 Answers

Multiple options:

  1. Using the system's files reference database:

$ sudo updatedb; locate mongo

  1. 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
  1. check manually in /var/lib or /usr/local or /usr/bin (must be a symlink though)
  2. 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

like image 75
DevLounge Avatar answered Sep 24 '22 07:09

DevLounge


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.

like image 44
L.D Avatar answered Sep 24 '22 07:09

L.D


It would be in where you decompressed the tar.gz file that you downloaded from the MongoDB website. Inside, there is a mongod executable that you need to run before you can open the shell and operate the database.

Alternatively, you can create symlinks for the executables that you want to use:

sudo ln -s /dir/to/your/mongodb/folder/mongo /usr/local/bin/mongo
sudo ln -s /dir/to/your/mongodb/folder/mongod /usr/local/bin/mongod

And you can simply type in these two commands anywhere in terminal.

like image 33
TPWang Avatar answered Sep 22 '22 07:09

TPWang