jwallace.us

tech, tunes, and other stuff

Installing MongoDB

On OSX do the following. Download the latest production release of MongoDB from here:

http://www.mongodb.org/downloads

Then install it in /usr/local using the following commands:

1
2
3
4
sudo tar xvfz /usr/local/mongodb-osx-x86_64-1.8.1.tgz
sudo ln -s /usr/local/mongodb-osx-x86_64-1.8.1 /usr/local/mongodb
sudo chown -R root /usr/local/mongodb
sudo mkdir /usr/local/mongodb_data

Next you’ll need to create the MongoDB configuration file.  First set up the storage location for the MongoDB database files:

echo "dbpath = /usr/local/mongodb_data" > /usr/local/mongodb/mongodb.conf

If you only want it to accept local connections, add this line to the config file:

echo "bind_ip = 127.0.0.1" >> /usr/local/mongodb/mongodb.conf

To get MongoDB to startup & shutdown automagically with OSX, you’ll want to create a launchd entry: /Library/LaunchDaemons/org.mongodb.mongod.plist

/Library/LaunchDaemons/org.mongodb.mongod.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>org.mongodb.mongod</string>
   <key>ProgramArguments</key>
   <array>
      <string>/usr/local/mongodb/bin/mongod</string>
      <string>run</string>
      <string>--config</string>
      <string>/usr/local/mongodb/mongod.conf</string>
   </array>
   <key>WorkingDirectory</key>
   <string>/usr/local/mongodb</string>
   <key>StandardOutPath</key>
   <string>/var/log/mongodb/output.log</string>
   <key>StandardErrorPath</key>
   <string>/var/log/mongodb/output.log</string>
   <key>RunAtLoad</key>  <true/>
   <key>KeepAlive</key>  <true/>
</dict>
</plist>

Thats about it.  To manually start & stop MongoDB type:

/Library/LaunchDaemons/org.mongodb.mongod.plist
1
2
sudo launchctl load /Library/LaunchDaemons/org.mongodb.mongod.plist
sudo launchctl unload /Library/LaunchDaemons/org.mongodb.mongod.plist

On Ubuntu Linux the installation instructions are similar, with a few differences:

Download the latest production release of MongoDB from here: http://www.mongodb.org/downloads

Then install it in /usr/local using the following commands:

1
2
3
4
sudo tar xvfz /usr/local/mongodb-linux-i686-1.8.1.tgz
sudo ln -s /usr/local/mongodb-linux-i686-1.8.1 /usr/local/mongodb
sudo chown -R root /usr/local/mongodb
sudo mkdir /usr/local/mongodb_data

Next you’’ll need to create the MongoDB configuration file.  First set up the storage location for the MongoDB database files:

echo "dbpath = /usr/local/mongodb_data" &gt; /usr/local/mongodb/mongodb.conf

If you only want it to accept local connections, add this line to the config file:

echo "bind_ip = 127.0.0.1" &gt;&gt; /usr/local/mongodb/mongodb.conf

Next you’ll want to put an entry into /etc/init.d so that it will startup & shutdown with Ubuntu.  Download this file, gunzip it,  & place it in /etc/init.d.  Make sure it has executable permissions:  MongoDB.gz

With both OSX and Ubuntu, if you did everything correctly, your MongoDB process can be found running here: http://localhost:28017