40

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!

jasenlew
  • 443
  • 1
  • 6
  • 7
  • 7
    if you installed them using `brew` you can `brew uninstall mongo`. To fix your socket issue, kill all mongodb process using `ps aux | grep mongo` to see the processes and `kill -9 process_number` to kill it. – Pierre-Louis Gottfrois Jul 03 '14 at 07:08
  • Thanks so much for the quick reply, Pierre-Louis. Unfortunately, still the same issue. Tried brew uninstall as well as the kill -9 with the number. Still get ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017. – jasenlew Jul 03 '14 at 07:23
  • After a little more pain, Pierre-Loiuse, pkill -mongod worked. MongoDB essentially always seems to be running even after terminal close and re-load. I need to either pkill -mongod on terminal load, OR control-C the running database before exiting terminal. Thanks again!! – jasenlew Jul 03 '14 at 15:39
  • FYI, if you have a running `mongod` there are more polite ways to shutdown than `kill -9` (which should only be used in extreme desperation). See: [How to stop mongo DB in one command](http://stackoverflow.com/questions/11774887/). – Stennie Jul 05 '14 at 13:46
  • @Pierre-LouisGottfrois your comment should have been an answer. –  Oct 26 '15 at 20:15
  • There is an official guide from MongoDB to uninstall MongoDB from any operating system https://www.mongodb.com/basics/uninstall-mongodb – ziishaned Jul 12 '22 at 11:30

5 Answers5

96

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.

Anuvrat Tiku
  • 1,616
  • 2
  • 17
  • 25
  • 10
    how should I uninstall it if it is not installed with brew? `Thu Nov 30 04:42:56 :~/CS460_660$ brew uninstall mongodb Error: No such keg: /usr/local/Cellar/mongodb` – Mona Jalal Nov 30 '17 at 09:43
  • 4
    https://medium.com/@rajanmaharjan/uninstall-mongodb-macos-completely-d2a6d6c163f9. I felt this was quite useful and comprehensive – smc Mar 08 '18 at 09:09
  • `brew uninstall --force mongodb` to remove all versions. – iniravpatel Jan 10 '19 at 15:48
  • What would you recommend doing if the MongoDB commands are still there after running the uninstall? – user2750362 Mar 01 '20 at 10:23
  • I agree with @smc in using https://medium.com/@rajanmaharjan/uninstall-mongodb-macos-completely-d2a6d6c163f9. I installed mongod differently based on MacOS Sierra. The guide above covered all aspects in removing it. – matoneski Mar 11 '20 at 02:28
  • 1
    Error: No installed keg or cask with the name "mongodb" – Vipul Sharma Aug 21 '20 at 18:49
  • @VipulSharma I had the same issue but I had installed `mongodb-community` rather than `mongodb`, e.g. like this answer https://stackoverflow.com/a/63490095/2037637 – Alex Shroyer Sep 15 '21 at 00:37
22

For uninstalling the community version, i found that the command brew uninstall mongodb-community worked for me

Shawn Lim
  • 261
  • 2
  • 5
11

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

marybngozi
  • 111
  • 2
  • 5
4

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

Nitin Jadhav
  • 6,495
  • 1
  • 46
  • 48
2

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.

LightMan
  • 3,517
  • 31
  • 31