Skip to content

Build from source code

This document guides you though the steps how to build Percona Server for MongoDB from source code.

Available builds

  • [Pro builds](. These builds include features that are typically demanded by large enterprises. They are included into packages built by Percona and are available to Percona Customers. Learn how to become a Customer.
  • Basic builds. These include all Percona Server for MongoDB functionality except the solutions in Pro builds. The packages built by Percona are available to anyone.

Build options

Manual build

To build Percona Server for MongoDB manually, you need the following:

  • A modern C++ compiler capable of compiling C++17 like GCC 8.2 or newer
  • Amazon AWS Software Development Kit for C++ library
  • Python 3.7.x and Pip modules.
  • The set of dependencies for your operating system. The following table lists dependencies for Ubuntu 22.04 and Red Hat Enterprise 9 and compatible derivatives:
Linux Distribution Dependencies
Debian/Ubuntu gcc g++ cmake curl libssl-dev libldap2-dev libkrb5-dev libcurl4-openssl-dev libsasl2-dev liblz4-dev libbz2-dev libsnappy-dev zlib1g-dev libzlcore-dev liblzma-dev e2fslibs-dev
RedHat Enterprise Linux/CentOS 9 gcc gcc-c++ cmake curl openssl-devel openldap-devel krb5-devel libcurl-devel cyrus-sasl-devel bzip2-devel zlib-devel lz4-devel xz-devel e2fsprogs-devel
  • About 13 GB of disk space for the core binaries (mongod, mongos, and mongo) and about 600 GB for the install-all target.

Build steps

Install Python and Python modules

  1. Make sure the python3, python3-dev, python3-pip Python packages are installed on your machine. Otherwise, install them using the package manager of your operating system.

  2. Clone Percona Server for MongoDB repository

    $ git clone https://github.com/percona/percona-server-mongodb.git
    
  3. Switch to the Percona Server for MongoDB branch that you are building and install Python3 modules

    $ cd percona-server-mongodb && git checkout v6.0
    $ python3 -m pip install --user -r etc/pip/dev-requirements.txt
    
  4. Define Percona Server for MongoDB version (6.0.6 for the time of writing this document)

    $ echo '{"version": "6.0.6"}' > version.json
    

Install operating system dependencies

The following command installs the dependencies for Ubuntu 22.04:

$ sudo apt install -y gcc g++ cmake curl libssl-dev libldap2-dev libkrb5-dev libcurl4-openssl-dev libsasl2-dev liblz4-dev libbz2-dev libsnappy-dev zlib1g-dev libzlcore-dev liblzma-dev e2fslibs-dev

The following command installs the dependencies for CentOS 9:

$ sudo yum -y install gcc gcc-c++ cmake curl openssl-devel openldap-devel krb5-devel libcurl-devel cyrus-sasl-devel bzip2-devel zlib-devel lz4-devel xz-devel e2fsprogs-devel

Build AWS Software Development Kit for C++ library

  1. Clone the AWS Software Development Kit for C++ repository

    $ git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp.git
    
  2. Create a directory to store the AWS library

    $ mkdir -p /tmp/lib/aws
    
  3. Declare an environment variable AWS_LIBS for this directory

    $ export AWS_LIBS=/tmp/lib/aws
    

  4. Percona Server for MongoDB is built with AWS SDK CPP 1.9.379 version. Switch to this version

    $ cd aws-sdk-cpp && git checkout 1.9.379
    
  5. It is recommended to keep build files outside the SDK directory. Create a build directory and navigate to it

    $ mkdir build && cd build
    
  6. Generate build files using cmake

    $ cmake .. -DCMAKE_BUILD_TYPE=Release '-DBUILD_ONLY=s3;transfer' -DBUILD_SHARED_LIBS=OFF -DMINIMIZE_SIZE=ON -DCMAKE_INSTALL_PREFIX="${AWS_LIBS}"
    
  7. Install the SDK

    $ make install
    

Build Percona Server for MongoDB

  1. Change directory to percona-server-mongodb

    $ cd percona-server-mongodb
    
  2. Build Percona Server for MongoDB from buildscripts/scons.py

    $ buildscripts/scons.py --disable-warnings-as-errors --release --ssl --opt=on -j$(nproc --all) --use-sasl-client --wiredtiger --audit --inmemory --hotbackup CPPPATH="${AWS_LIBS}/include" LIBPATH="${AWS_LIBS}/lib ${AWS_LIBS}/lib64" install-mongod install-mongos
    
    $ buildscripts/scons.py --disable-warnings-as-errors --release --ssl --opt=on -j$(nproc --all) --use-sasl-client --wiredtiger --audit --inmemory --hotbackup --full-featured CPPPATH="${AWS_LIBS}/include" LIBPATH="${AWS_LIBS}/lib ${AWS_LIBS}/lib64" install-mongod install-mongos
    

This command builds core components of the database. Other available targets for the scons command are:

  • install-mongod
  • install-mongos
  • install-servers (includes mongod and mongos)
  • install-core (includes mongod and mongos)
  • install-devcore (includes mongod, mongos, and jstestshell (formerly mongo shell))
  • install-all

The built binaries are in the percona-server-mongodb/bin directory.

Use the build script

To automate the build process, Percona provides the build script. With this script you can either build binary tarballs or DEB/RPM packages to install Percona Server for MongoDB from.

Prerequisites

To use the build script you need the following:

  • Docker up and running on your machine
  • About 200GB of disk space

Prepare the build environment

  1. Create the folder where all build actions take place. For the steps below we use the /tmp/psmdb/test folder.
  2. Navigate to the build folder and download the build script. Replace the <tag> placeholder with the required version of Percona Server for MongoDB:

    $ wget https://raw.githubusercontent.com/percona/percona-server-mongodb/psmdb-<tag>/percona-packaging/scripts/psmdb_builder.sh -O psmdb_builder.sh 
    

Build steps

Use the following instructions to build tarballs or packages:

Tarballs

Note

You can build only Percona Server for MongoDB basic tarballs with the build script. Percona Server for MongoDB Pro tarballs are not supported.

To build tarballs, the steps are the following:

  1. The following command builds tarballs of Percona Server for MongoDB 6.0.12-9 on CentOS 7. Change the Docker image and the values for --branch, --psm_ver, --psm_release flags to build tarballs of a different version and on a different operating system.

    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb centos:7 sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12 --psm_release=9 --mongo_tools_tag=100.7.0 --get_sources=1 --build_tarball=1
    '
    

    The command does the following:

    • runs Docker daemon as the root user using the CentOS 7 image
    • mounts the build directory into the container
    • establishes the shell session inside the container
    • inside the container, navigates to the build directory and runs the build script to install dependencies
    • runs the build script again to build the tarball for the Percona Server for MongoDB version 6.0.12-9
  2. Check that tarballs are built:

    $ ls -la /tmp/psmdb/test/tarball/
    
    Sample output
    total 88292
    -rw-r--r--. 1 root root 90398894 Jul  1 10:58 percona-server-mongodb-6.0.12-9-x86_64.glibc2.17.tar.gz
    

Packages

The steps are the following:

  1. Build the source tarball. It serves as the base for source packages. It is important to build source tarball using the oldest supported operating system, which is CentOS 7.

    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb centos:7 sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git --branch=release-6.0.12-9 --psm_ver=6.0.12 --psm_release=9 --mongo_tools_tag=100.7.0 --get_sources=1'
    
  2. Build source packages. These packages include the source code and patches and are used to build binary packages.

    Note that to build source packages you still have to use the oldest supported operating system: CentOS 7 for RPMs and Ubuntu 18.04 (Bionic Beaver) for DEB packages.

    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb ubuntu:bionic sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12--psm_release=9 --mongo_tools_tag=100.7.0 --build_src_deb=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/source_deb/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 11:45 percona-server-mongodb_6.0.12.orig.tar.gz
    
    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb centos:7 sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12--psm_release=9 --mongo_tools_tag=100.7.0 --build_src_rpm=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/srpm/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 11:45 percona-server-mongodb-6.0.12-9.generic.src.rpm
    
    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb ubuntu:bionic sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12--psm_release=9 --mongo_tools_tag=100.7.0 --full-featured=1 --build_src_deb=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/source_deb/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 11:45 percona-server-mongodb-pro_6.0.12.orig.tar.gz
    
    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb centos:7 sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12--psm_release=9 --mongo_tools_tag=100.7.0 --full-featured=1 --build_src_rpm=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/srpm/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 11:45 percona-server-mongodb-pro-6.0.12-9.generic.src.rpm
    
  3. Build Percona Server for MongoDB packages. Here you can use the operating system of your choice. In the commands below, we use Oracle Linux 9 for RPMs and Ubuntu 22.04 (Jammy Jellyfish) for DEB packages.

    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb ubuntu:jammy sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12 --psm_release=9 --mongo_tools_tag=100.7.0 --build_deb=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/deb/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-dbg_6.0.12-9.jammy_amd64.deb  
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-mongos-pro_6.0.12-9.jammy_amd64.deb 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-server_6.0.12-9.jammy_amd64.deb 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-tools_6.0.12-9.jammy_amd64.deb  
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb_6.0.12-9.jammy_amd64.deb
    
    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb oraclelinux:9 sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12 --psm_release=9 --mongo_tools_tag=100.7.0 --build_rpm=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/rpm/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-6.0.12-9.el8.x86_64.rpm  
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-debugsource-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-mongos-6.0.12-9.el8.x86_64.rpm    
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-mongos-debuginfo-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-server-6.0.12-9.el8.x86_64.rpm    
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-server-debuginfo-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-tools-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-tools-debuginfo-6.0.12-9.el8.x86_64.rpm
    
    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb ubuntu:jammy sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12 --psm_release=9 --mongo_tools_tag=100.7.0 --full-featured=1 --build_deb=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/deb/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-pro-dbg_6.0.12-9.jammy_amd64.deb  
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-mongos-pro_6.0.12-9.jammy_amd64.deb 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-server-pro_6.0.12-9.jammy_amd64.deb 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-tools-6.0.12-9.jammy_amd64.deb  
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-pro_6.0.12-9.jammy_amd64.deb
    
    $ docker run -ti -u root -v /tmp/psmdb:/tmp/psmdb oraclelinux:9 sh -c '
    set -o xtrace
    cd /tmp/psmdb
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --install_deps=1
    bash -x ./psmdb_builder.sh --builddir=/tmp/psmdb/test --repo=https://github.com/percona/percona-server-mongodb.git \
    --branch=release-6.0.12-9 --psm_ver=6.0.12 --psm_release=9 --mongo_tools_tag=100.7.0 --full-featured=1 --build_rpm=1
    '
    

    Check that source packages are created

    $ ls -la /tmp/psmdb/test/rpm/
    
    Sample output
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-pro-6.0.12-9.el8.x86_64.rpm  
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-pro-debugsource-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-mongos-pro-6.0.12-9.el8.x86_64.rpm    
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-mongos-pro-debuginfo-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-server-pro-6.0.12-9.el8.x86_64.rpm    
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-server-pro-debuginfo-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-tools-6.0.12-9.el8.x86_64.rpm 
    rw-r--r--. 1 root root 90398894 Jul  1 13:16 percona-server-mongodb-tools-debuginfo-6.0.12-9.el8.x86_64.rpm
    

Next steps

Connect to MongoDB

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services.