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 = 127.0.0.1
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 = 0.0.0.0 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