Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 23, 2023 05:17 pm GMT

Installing MongoDB on latest MacOS Intel and M1 base processors with Homebrew

Hey there, i'll take it you are here because you have had a hard time installing Mongodb on your macOS yes? Well i had the same issue and, below i will share the reason why and how you can fix this issue.

Why the issue?

Actually, Catalina 10.5 upwards has a surprise change: it won't allow changes to the root directory, this was discussed on the reddit here.

How to fix it?

Here is how you can get this fixed and have mongodb running locally on your macos.

  1. Make sure you have Homebrew installed properly, you can follow here on how to install brew.
  2. Now, for some reason you need to install xcode tools, you don't need to actually install xcode itself, but you need xcode tools to avoid it throwing an error. we can do this with the command:
xcode-select --install
  1. After successfully installing xcode tools, to install mongodb we need to first tap into mongodb, think of it like, brew doesn't know or has never heard of this package before, so we just saying "hey brew you can tap into any other resource" in our case we would say:
brew tap mongodb/brew

and here pretty much we have brew saying, "okay, i am now aware of one more resource which is mongodb"

  1. From here we can now install mongodb with brew by saying;
brew install [email protected]

Note: you can specify the version you wanna install

Now from here this won't give you immediate access to mongodb, you need to at least start the services, it's a server and it needs to be started. So, lets get started with the services of mongodb.

So we will run the command bellow which will say to brew "hey brew, you have services and from that i wanna start a spacial service called [email protected]" with the command below

brew services start [email protected]

After running this, you should get a successfull message saying:

==> Successfully started `[email protected]` (label: [email protected])

Note:Now similarly to stop this service you use the same command except you will pass the argument stop as seen below:

brew services stop [email protected]

Whenever you need to use mongodb you will have to run the command to start it. But obviously you don't wanna do this again and again, you wanna keep this up and running and for that all you have to do is link it.

Here things will look different depending on the processor you are running, if you are on M1 chip or intel.

  1. Intel based:
  1. M1 chip based:
mongod --config /opt/homebrew/etc/mongod.conf --fork

...and that's it!!!

From here you can just run:

mongosh

Hope that helps!

PS: You can also use MongoDB Compass to visually manage your mongodb databases.


Original Link: https://dev.to/fotiecodes/installing-mongodb-on-latest-macos-intel-and-m1-base-processors-with-homebrew-1ima

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To