Build for Linux

Binaries are available for most platforms. Most users do not need to compile MongoDB themselves. In addition, every prebuilt binary has been regression tested. See the Downloads page for prebuilt binaries.

Build MongoDB version 2.1.1 or Later

These build instructions apply to the MongoDB git master branch (https://github.com/mongodb/mongo) and to versions 2.1.1 and onward.

Prerequisites

You must have the following:

  • SCons
  • The gnu C++ toolchain
  • glibc-devel
  • git, in order to get the code from GitHub

To install the above on Fedora, issue the following:

sudo yum -y install git-core scons gcc-c++ glibc-devel

To install the above on Ubuntu, issue the following:

sudo apt-get install git-core build-essential scons

Building

  1. Install any needed prerequisites (see above).

  2. Get the source code:

    git clone git://github.com/mongodb/mongo.git
    cd mongo
    
  3. Pick a version to build (only use “master” if you are doing development work).

    1. List all tagged versions:

      git tag -l
      
    2. Check out a tagged release, e.g. 2.4.0:

      git checkout r2.4.0
      
    3. Compile:

      scons all
      
    4. Install. Use --prefix to specify where you want to install your binaries. The default is /usr/local.

      scons --prefix=/opt/mongo install
      

Troubleshooting

  • Link errors. If link errors occur, the -t gcc option is useful for troubleshooting. Try adding -t to the SConstruct file’s LINKFLAGS.
  • Static libraries. The --release scons option will build a binary using static libraries. You may need to install static boost libraries when using this option.