-
Notifications
You must be signed in to change notification settings - Fork 342
Installing MongoDB with MacPorts on OS X
Morten Hekkvang edited this page Oct 20, 2016
·
8 revisions
-
Install mongodb with
sudo port install mongodb
-
Make a data directory with
sudo mkdir -p /opt/local/var/db/mongodb_data
-
Make a logs directory with
sudo mkdir -p /opt/local/var/log/mongodb/
-
Make a mongodb directory with
sudo mkdir -p /opt/local/etc/mongodb
-
Create configuration file with
sudo pico /opt/local/etc/mongodb/mongod.conf
Enter the following if the file is blank and hit ctrl+x and save the file.
# configuration file /opt/local/etc/mongodb/mongod.conf
# Store data alongside MongoDB instead of the default, /data/db/
dbpath = /opt/local/var/db/mongodb_data
# Only accept local connections
bind_ip = 127.0.0.1
# Running as daemon
fork = true
# Take log
logpath = /opt/local/var/log/mongodb/mongodb.log
logappend = true
-
Create startup alias for your terminal profile so that you can run
mongostart
andmongostop
to manually start and stop the mongodb instance.
At the Terminal, enter pico ~/.profile
and add the following to the end of the file. When done hit ctrl+x and save the file:
alias mongostart="sudo mongod -f /opt/local/etc/mongodb/mongod.conf --httpinterface"
mongostop_func () {
local mongopid=`less /opt/local/var/db/mongodb_data/mongod.lock`;
if [[ $mongopid =~ [[:digit:]] ]]; then
sudo kill -15 $mongopid;
echo mongod process $mongopid terminated;
else
echo mongo process $mongopid not exist;
fi
}
alias mongostop="mongostop_func"
-
Start MongoDB by typing
mongostart
at the Terminal and hitting return (to stop, typemongostop
and hit return). -
Test that MongoDB is running by visiting
http://localhost:28017/
in a web browser. You should see a dashboard summarizing the running instance. Note: this is turned off by default, but we've enabled it in our shell profile with the --httpinterface flag in step 5. This should be disabled for production environments.