The 'quickstart' for OS X on the MongoDB site could be clearer. Here's a condensed version with more info.
Copy the download URL on the MongoDB site (don't click) for the latest download for your system:
www.mongodb.org/downloads
Open Terminal and go to where you keep source files (good to create a directory if you don't have it already with mkdir src
) e.g.:
cd ~/src
Type curl
, a space, the URL you've copied, then >
(between spaces) and the filename you'll save it as e.g. (for the 64-bit version of Mongo 1.8.1):
curl http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.8.1.tgz > mongo.tgz
Double-click the archive and (if you like) you can move it somewhere sensible in your path.
Make the default directory for MongoDB to store it's data - enter:
mkdir -p /data/db
(-p also creates the intermediate directory data
)
This directory must be writable by the user under which Mongo is running. If you get an error containing 'Unable to create / open lock file for lockfilepath' type:
sudo chown `id -u` /data/db
If you want see what's there after you've used MongoDB, type:
cd /data/db;ls -al
Either add the path to mongo, or a couple of aliases to your .bash_profile
, .bashrc
, .bash_login
file (or wherever you keep your custom bash stuff) e.g. for the above version of MongoDB downloaded to ~/src
:
alias mongod="/Users/yourusername/src/mongodb-osx-x86_64-1.8.1/bin/mongod"
alias mongo="/Users/yourusername/src/mongodb-osx-x86_64-1.8.1/bin/mongo"
To reload this new information onto the shell, either type source .bash_profile
(or whichever file you've used) or close the Terminal window and open a new one.
You can now start the MongoDB server with:
mongod
To try things out, open another Terminal window and launch the MongoDB shell by typing:
mongo
In the MongoDB shell that's now started up, create and retrieve a test document e.g. 'foo':
> db.foo.save( { a : 1 } )
> db.foo.find()
You'll see the result. Now you can start using MongoDB.
Mongodb docs: Quickstart+OS+X
Bashing up mongodb on mac os x 10-6