Use Brew to install MongoDB under Mac

Source: Internet
Author: User
Tags brew install mongodb install mongodb mongodb client mongodb server

Mac installed under the general two methods of MongoDB.

(1) Download the source code, unzip, compile, configure, start a more difficult mode.

(2) Brew Install MongoDB, then you can leisurely take a sip of tea, by the way a glance at NetEase news, this is a fool mode.

But the fool model also has human intervention when, roughly speaking, using brew to install MongoDB

[email protected]: ~ / code $ brew install mongodb
This figure shows that the installation has been successful, and the installation directory is /usr/local/Cellar/mongodb/2.4.9

The first time you start the server, you need to do some preparation here.

1.The default mongodb data file is placed in the root directory data / db folder, if you do not have this file, please create it yourself.

[email protected]: ~ / code $ mkdir -p / data / db
2.If your current environment variables have not been added to mongod, manually add the environment variables.

[email protected]: ~ / code $ nano ~ / .bash_profile
// Add mongodb installation directory to environment variables
export PATH = / usr / local / Cellar / mongodb / 2.4.9 / bin: $ (PATH)}
3. How to make environment variables take effect immediately? Execute the following shell

source ~ / .bash_profile
4.Modify the mongodb configuration file, the default configuration file is mongod.conf under / usr / local / etc

# Store data in / usr / local / var / mongodb instead of the default / data / db
dbpath = / data / db

# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true

# Only accept local connections
bind_ip =
The second line is modified to the database file write directory address.If you plan to connect to the mongodb database in a non-local environment, bind_ip = is sufficient.

5.try to start mongod

Well, everything is difficult at the beginning.The mongodb server has not started. Look at the error message on the last line and quit. After google, it is because the / data / db file does not have write permissions.

6.Grant permissions to the / data / db folder

sudo chown `id -u` / data / db
ok, this sentence is done, continue to try to start the server

OK, the mongodb server is finally started. Then start the mongodb client

[email protected]: / usr / local / etc $ mongo

Until now, the installation of mongodb is started on the server and the client is started.The next step is how to use it.

Install mongodb with brew on mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.