Appendix A. Installing MongoDB
MongoDB binaries are available for Linux, Mac OS X, Windows, and Solaris. This means that, on most platforms, you can download an archive from http://www.mongodb.org/downloads, inflate it, and run the binary.
The MongoDB server requires a directory it can write database files to and a port it can listen for connections on. This section covers the entire install on the two variants of system: Windows and everything else (Linux, Max, Solaris).
When we speak of installing MongoDB, generally what we are talking about is setting up mongod
, the core database server. mongod
can be used as a standalone server or as a member of a replica set. Most of the time, this will be the MongoDB process you are using.
Choosing a Version
MongoDB uses a fairly simple versioning scheme: even-point releases are stable, and odd-point releases are development versions. For example, anything starting with 2.4 is a stable release, such as 2.4.0, 2.4.1, and 2.4.15. Anything starting with 2.5 is a development release, such as 2.5.0, 2.5.2, or 2.5.10. Lets take the 2.4/2.5 release as a sample case to demonstrate how the versioning timeline works:
MongoDB 2.4.0 is released. This is a major release and will have an extensive changelog.
After the developers start working on the milestones for 2.6 (the next major stable release), they release 2.5.0. This is the new development branch that is fairly similar to 2.4.0 but probably with an extra feature or two and maybe some bugs.
As the developers continue to add features, they will release 2.5.1, 2.5.2, and so on. These releases should not be used in production.
Some minor bug fixes may be backported to the 2.4 branch, which will cause releases of 2.4.1, 2.4.2, and so on. Developers are conservative about what is backported; few new features are ever added to a stable release. Generally, only bug fixes are ported.
After all of the major milestones have been reached for 2.6.0, 2.5.7 (or whatever the latest development release is) will be turned into 2.6.0-rc0.
After extensive testing of 2.6.0-rc0, usually there are a couple minor bugs that need to be fixed. Developers fix these bugs and release 2.6.0-rc1.
Developers repeat step 6 until no new bugs are apparent, and then 2.6.0-rc2 (or whatever the latest release ended up being) is renamed 2.6.0.
Start over from step 1, incrementing all versions by 0.2.
You can see how close a production release is by browsing the core server roadmap on the MongoDB bug tracker.
If you are running in production, you should use a stable release. If you are planning to use a development release in production, ask about it first on the mailing list or IRC to get the developers advice.
If you are just starting development on a project, using a development release may be a better choice. By the time you deploy to production, there will probably be a stable release with the features youre using (MongoDB attempts to stick to a regular cycle of stable releases every six months). However, you must balance this against the possibility that you would run into server bugs, which can be discouraging to a new user.
Windows Install
To install MongoDB on Windows, download the Windows zip from the MongoDB downloads page. Use the advice in the previous section to choose the correct version of MongoDB. There are 32-bit and 64-bit releases for Windows, so select whichever version youre running. When you click the link, it will download the .zip. Use your favorite extraction tool to unzip the archive.
Now you need to make a directory in which MongoDB can write database files. By default, MongoDB tries to use the \data\db directory on the current drive as its data directory (for example, if youre running mongod on C:, itll use C:\data\db). You can create this directory or any other empty directory anywhere on the filesystem. If you chose to use a directory other than \data\db, youll need to specify the path when you start MongoDB, which is covered in a moment.
Now that you have a data directory, open the command prompt (cmd.exe). Navigate to the directory where you unzipped the MongoDB binaries and run the following:
$ bin\mongod.exe
If you chose a directory other than C:\data\db, youll have to specify it here, with the --dbpath
argument:
$ bin\mongod.exe --dbpath C:\Documents and Settings\Username\My Documents\db
See for more common options, or run mongod.exe
--help
to see all options.
Installing as a Service
MongoDB can also be installed as a service on Windows. To install, simply run with the full path, escape any spaces, and use the --install
option. For example:
$ C:\mongodb-windows-32bit-1.6.0\bin\mongod.exe --dbpath "\"C:\Documents and Settings\Username\My Documents\db\"" --install
It can then be started and stopped from the Control Panel.
POSIX (Linux, Mac OS X, and Solaris) Install
Choose a version of MongoDB, based on the advice in the section
Tip
If you are using a Mac, check whether youre running 32-bit or 64-bit. Macs are especially picky that you choose the correct build and will refuse to start MongoDB and give confusing error messages if you choose the wrong build. You can check what youre running by clicking the apple in the upper-left corner and selecting the About This Mac option.
You must create a directory for the database to put its files. By default, the database will use /data/db, although you can specify any other directory. If you create the default directory, make sure it has the correct write permissions. You can create the directory and set the permissions by running the following:
$
mkdir
-
p
/
data
/
db
$
chown
-
R
$USER
:
$USER
/
data
/
db
mkdir -p
creates the directory and all its parents, if necessary (i.e., if the /data directory didnt exist, it will create the /data
directory and then the /data/db directory). chown
changes the ownership of /data/db so that your user can write to it. Of course, you can also just create a directory in your home folder and specify that MongoDB should use that when you start the database, to avoid any permissions issues.
Decompress the .tar.gz file you downloaded from http://www.mongodb.org:
$
tar
zxf
mongodb
-
linux
-
i686
-
1.6
.
0
.
tar
.
gz
$
cd
mongodb
-
linux
-
i686
-
1.6
.
0
Now you can start the database:
$
bin
/
mongod
Or if youd like to use an alternate database path, specify it with the --dbpath
option:
$
bin
/
mongod
--
dbpath
~
/db
See section TODO for a summary of the most common options, or run mongod
with --help
to see all the possible options.
Installing from a Package Manager
On these systems, there are many package managers that can also be used to install MongoDB. If you prefer using one of these, there are official packages for RedHat, Debian, and Ubuntu as well as unofficial packages for many other systems. If you use an unofficial version, make sure it installs a relatively recent version.