Zsh: Command Not found : mongo After trying to install mongodb 4.2 using brew - database

I have tried the following steps to install and setup mongodb in my mac from here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ but I got the following error when running the final "mongo" command in my terminal:
Error Message - Zsh: Command Not found : mongo
This error msg occurred after trying to install mongodb 4.2 using brew
sudo chown -R $(whoami) $(brew --prefix)/*
then
brew tap mongodb/brew
then
brew install mongodb-community#4.2
and
brew services start mongodb-community#4.2
or
mongod --config /usr/local/etc/mongod.conf
then
ps aux | grep -v grep | grep mongod
and
mongo
running brew services start mongodb-community#4.2 returns:
Successfully started `mongodb-community#4.2` (label: homebrew.mxcl.mongodb-community#4.2)
running ps aux | grep -v grep | grep mongod returns:
9081 0.2 0.5 5528024 41856 ?? S 3:01pm 0:01.48 /usr/local/opt/mongodb-community#4.2/bin/mongod --config /usr/local/etc/mongod.conf
7613 0.0 0.1 4298832 5600 s000 T 2:47pm 0:00.08 vim /usr/local/etc/mongod.conf
running mongod --config /usr/local/etc/mongod.conf returns:
zsh: command not found: mongod
There are also no mongo files in my /usr/local/bin directory after using these commands
I created a data/db folder in my /usr/local/bin directory using the following commands:
sudo mkdir -p /usr/local/bin/data/db
sudo chown -R `id -un` /usr/local/bin/data/db
Running "brew update" returns:
brew update
Updated 1 tap (homebrew/cask).
==> Updated Casks
brave-browser

brew install mongodb-community-shell
Fixed the problem for me.

Solved it by manually installing the mongodb community files and db tools using the website instead. Then copying them into /usr/local/bin. Then ignoring the app permissions whenever calling mongo or related commands in the terminal through System Preferences > Security & Privacy > General.
After googling I found out that mongoimport and the other features have to be installed separately: https://www.mongodb.com/try/download/database-tools
Followed by copying those bin files after extracting them into the same /usr/local/bin directory
Not sure why its' not working through homebrew though

This worked for me, I was having same issue on mongodb-community#4.4
brew reinstall mongodb-community#4.4
On terminal something like this will appear during reinstallation.
copy highlighted path with echo
echo 'export PATH="/opt/homebrew/opt/mongodb-community#4.4/bin:$PATH"' >> ~/.zshrc
Now open another terminal and start mongodb services
brew services restart mongodb/brew/mongodb-community#4.4
write mongo on terminal and here we fly

If you installed the mongodb via Homebrew. Need to add the mongo path in your bash_profile.
Edit the bash_profile vi ~/.bash_profile
Add the below line in EOF export PATH=$PATH:/usr/local/opt/mongodb-community#4.2/bin
After the edit bash_profile. Close all terminals and open them again. mongo command start works.

In addition to #ramesh-babu-t-b 's answer, https://stackoverflow.com/a/68407530/1279516, the issue could also be that your MongoDB installation did add mongod to your path, but the installation happened within the current shell session, and so your shell doesn't have the updates to the PATH variable yet.
In this case, only his last step is still necessary - Open a new console window and retry the mongod command.

Related

I got an illegal instruction when installing mongoDB when trying to check the version

Hey so I tried installing mongoDB and I can't get it to install correctly. I am installing it on wsl on a windows computer and I keep getting illegal instruction when I try to check the version and it won't let me finish installing it. Here are the instructions I used to install MongoDB (version 5.0) on WSL (Ubuntu 20.04):
Open your WSL terminal (ie. Ubuntu) and go to your home directory: cd ~
Update your Ubuntu packages: sudo apt update
Import the public key used by the MongoDB package management system: wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Create a list file for MongoDB: echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Reload local package database: sudo apt-get update
Install MongoDB packages: sudo apt-get install -y mongodb-org
Confirm installation and get the version number: mongod --version
Make a directory to store data: mkdir -p ~/data/db
Run a Mongo instance: sudo mongod --dbpath ~/data/db
Check to see that your MongoDB instance is running with: ps -e | grep 'mongod'
To exit the MongoDB Shell, use the shortcut keys: Ctrl + C

MongoDB Catalina: connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017

I just updated my mac to Catalina 10.15.2 and I can't running MongoDB.
When I send the command mongo I receive this message
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
and the only way to make Mongo work is to restart the Mac.
If I check the process with the command ps I don't see the process already on and the port 27017 is available.
I already tried to run the follow command:
brew tap mongodb/brew
brew reinstall mongodb-community
brew services restart mongodb-community
and if I run the follow command:
ps aux | grep -v grep | grep mongod
no results.
I tried to run mongod before mongo as well and the result is:
2019-12-18T12:17:45.916+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] MongoDB starting : pid=9375 port=27017 dbpath=/data/db 64-bit host=Marcos-MacBook-Pro.local
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] db version v4.2.1
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] allocator: system
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] modules: none
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] build environment:
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] distarch: x86_64
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] target_arch: x86_64
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] options: {}
2019-12-18T12:17:45.920+0100 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied
2019-12-18T12:17:45.920+0100 F - [initandlisten] Fatal Assertion 40486 at src/mongo/transport/transport_layer_asio.cpp 693
2019-12-18T12:17:45.920+0100 F - [initandlisten]
***aborting after fassert() failure
Someone can help me please? I appreciate it
An alternative way to fix this Catalina Mac OS root & mongodb connection issue, do the following:
Install Homebrew, if you have it, reinstall it again
run the following commands in the terminal
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew untap mongodb/brew && brew tap mongodb/brew
brew install mongodb-community#4.2
The issue is mongo cannot find /db/data because there is no directory, so you have to create one:
cd ~ (this should take you to your Users folder)
from the Users folder make your own db/data folder by running the follow commands:
mkdir db & cd inside db folder
inside the db folder run: mkdir data & cd inside data folder
run this command: mongod --dbpath ~/data/db
(inside the Users/data/db/ folder you just created)
Now open a new terminal tab &
run: cd ~ (brings you back to Users) -> now run : cd .. & cd .. again (do this twice)
(now you should be in the folder before Users)
(now find tmp folder) cd into the /tmp folder
delete the sock file (this is giving you connection issues)
delete it by running: rm -rf mongodb-27017.sock
now run command: mongo (this should work now)
inside mongo shell run command: db.verion()
if you see a version, your connection works.
From now on to run mongodb database & connection you will have to have two separate tabs open at all times whenever you want to work on your projects
Example:
in one terminal tab run command -> mongod --dbpath ~/data/db
(this starts the connection)
in the other terminal tab run command: mongo
(this starts the shell)
These both have to be running..
Side Note:
you no longer need to start
the connection by running
brew services start mongo-community anymore.
remember mongod --dbpath ~/data/db is basically -> mongod command now.. The Mac OS Catalina Update created root permission problems, that is why mongod command alone never worked before.
Hope this helped you. Goodluck.
Faced a similar issue with macOS Big Sur. After trying all the approaches mentioned above including
updating homebrew
reinstalling MongoDB, MongoDB community and setting up a /System/Volumes/Data/data/dbfolder
This command worked for me mongod --dbpath=/System/Volumes/Data/data/db
reference: https://medium.com/codespace69/mongodb-troubleshooting-errors-for-beginners-and-macos-catalina-31befd99f6c8
This error is caused due to ownership issues.
Here we are changing the ownership to 'mongodb' user.
Command 1: deletes the /tmp/mongodb-27017.sock file
$sudo rm -rf /tmp/mongodb-27017.sock
Command 2: starts mongod service
$sudo service mongod start
Command 3: shows the file with its ownership details
ls -lsah /tmp/mongodb-27017.sock
output
0 srwx------ 1 mongodb mongodb 0 Aug 24 04:01 /tmp/mongodb-27017.sock
Got the same issue after upgrading to Catalina. Tried lots of ways to solve the issue, what eventually helped was reinstalling brew, and then following steps listed on official mongodb site.
So:
Uninstall brew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)
Install it again:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Follow steps to install and run monbo service:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

Oracle JDK 11 error occuring every time, I install anything in terminal

Below is the Error message I get every time I install anything in the terminal . Its kinda stuck there for a while.
I tried no. of solutions from StackOverflow but nothing worked.
Before installing this package,
please download the Oracle JDK 11 .tar.gz file
with the same version as this package (version 11.0.4),
and place it in /var/cache/oracle-jdk11-installer-local,
E.g.:
sudo mkdir -p /var/cache/oracle-jdk11-installer-local
sudo cp jdk-11.0.4_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/
sha256sum mismatch jdk-11.0.4_linux-x64_bin.tar.gz
Oracle JDK 11 is NOT installed.
dpkg: error processing package oracle-java11-installer-local (--configure):
installed oracle-java11-installer-local package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
oracle-java11-installer-local
E: Sub-process /usr/bin/dpkg returned an error code (1)
Doesn't show up again.
Remove the package oracle-java11-installer-local. You can do this in following way:
sudo apt remove oracle-java11-installer-local
found this solution:
sudo rm /var/lib/dpkg/info/oracle-java11-installer-local.postinst
at this site.
You need to download the folder of the Oracle JDK 11 on here https://www.oracle.com/java/technologies/javase-jdk11-downloads.html
After download the tar.gz file. Move to your folder location then copy the file by using this command
sudo cp jdk-11.0.6_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/
don't forget to check your file name! After that repeat again by typing
sudo apt-get install oracle-java11-installer-local
and you can check your java version after that by typing
java -version
Hello,
I've had the same issue.
When you try to run sudo apt update && sudo apt upgrade it will automatically try to update the Java if a newer version is available. In my case let's say from 11.0.4 -> 11.0.5.
If you add the JDK from Oracle (after download) to /var/cache/oracle-jdk11-installer-local/ it should work.
You don't have to uninstall it...(I mean the oracle-jdk11-installer-local, it works just fine).
Please let me know if you still have this issue.
I had the same issue. My solution was to download jdk-11.0.5_linux-x64_bin.tar.gz and copied it to /var/cache/oracle-jdk11-installer-local.
In console shell, type:
sudo apt update && sudo apt upgrade
After a long search: this solved it for me.
The checksum made the issues for me. Try:
sudo rm /var/lib/dpkg/info/oracle-java11-installer-local.postinst -f
Navigating to the directory var/cache and doing "sudo rmdir oracle-jdk11-installer-local/" worked for me.
sudo rmdir oracle-jdk11-installer-local/
I have managed to resolve the issue by doing this:
modify /var/lib/dpkg/info/oracle-java11-installer-local.postinst
Change the checkSum. take from oracle website check sum for 11.0.15.1
3. change the version in 2 places
4. save and update apt
5. then sudo apt install oracle-java11-installer-local
this worked for me

Install Adminer on Ubuntu 18.04 bionic

I'm trying to install Adminer from Ubuntu repository using:
sudo apt install adminer
Installation works fine but can't find the file /etc/adminer/apache.conf to use with Apache server. The folder /etc/adminer/ is empty and can't find it anywhere with find command.
Any help?
Thanks in advance.
In the next few steps, I'll show you how I installed adminer for Ubuntu 18.04.1 LTS .
After installation with apt package manager change into the adminer directory.
cd /usr/share/adminer
There you will find a file called compile.php.
Run the following command and the adminer-X.X.X.php (X.X.X for your version) file will be created.
sudo php compile.php
Create the apache adminer configuration file.
sudo echo "Alias /adminer.php /usr/share/adminer/adminer-X.X.X.php" | sudo tee /etc/apache2/conf-available/adminer.conf
Now you'll need to activate the configuration.
cd /etc/apache2/conf-available/
sudo a2enconf adminer.conf
Reload your apache webserver.
sudo systemctl reload apache2.
Test in your browser of choice (localhost/adminer.php)
This source was really helpful:
https://www.linuxhelp.com/how-to-install-adminer-on-ubuntu-16-04/
Install Apache:
sudo apt-get install apache2
Install PHP:
sudo apt-get install php libapache2-mod-php php-mysql
Install Adminer:
sudo wget "http://www.adminer.org/latest.php" -O /var/www/html/adminer.php
Once the installation completes, restart Apache.
sudo service apache2 restart
At this point, the setup is complete. You can access Adminer at the following address.
http://[SERVER_IP]/adminer.php

Uninstall MongoDB on Mac OS X

When I try to run mongod from the terminal, I get the following error:
2014-07-02T23:56:24.797-0700 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2014-07-02T23:56:24.797-0700 [initandlisten] ERROR: addr already in use
I recently realize that I have two versions of MongoDB on my Mac, and think this may be the source for the above error. (Plus, I do not need two version.) I tried Googling, but was not able to find clear directions on how I can uninstall. I have development version 2.7.0 AND 2.6.3.
Thanks so much in advance for the help!
Run the following commands to remove mongodb from the launch/startup and to uninstall it using Homebrew:
# See if mongo is in the launch/startup list
launchctl list | grep mongo
# Remove mongodb from the launch/startup
launchctl remove homebrew.mxcl.mongodb
# Kill the mongod process just in case it's running
pkill -f mongod
# Now you can safely remove mongodb using Homebrew
brew uninstall mongodb
Just double-check in /usr/local/bin/ to make sure that the mongodb commands are removed.
For uninstalling the community version, i found that the command brew uninstall mongodb-community worked for me
Nitin Jadhav version worked for me, brew uninstall mongodb kept given me Error: No such keg: /usr/local/Cellar/mongodb. I was removing a mongodb-community.
use cd /usr/local/Cellar then run ls -a and then run rm -rf mongodb-community to remove it
I would suggest navigating into your /usr/local/Cellar and run an ls -a, I had a community version of mongo installed that wasn't being picked up by the command given above. If you find any mongo versions there just rm -rf each instance
For those having this error in osx:
brew uninstall mongodb Error: No such keg: /usr/local/Cellar/mongodb
execute brew list | grep mongo
for example, it could show something like:
mongodb-community#4.2
mongodb-database-tools
mongosh
remove them with brew uninstall mongodb-community#4.2 mongodb-database-tools mongosh
Also execute launchctl remove homebrew.mxcl.mongodb as #anuvrat-tiku says in his answer.

Resources