Build Memgraph from source
Follow this guide if you want to compile a Memgraph from a source. Here you will find all the necessary steps, including setting up the necessary toolchain, compiling the code, and running Memgraph.
Memgraph uses git for source version control. You will need to install git
on your machine before you can download the source code.
If you are using Mac M1 or above, please check our MacOS Lima Compilation Guide first.
Obtain the Source Code
After installing git, you are now ready to fetch your own copy of the Memgraph
source code. Run the following command:
git clone git@github.com:memgraph/memgraph.gitThe above will create a memgraph directory and put all source code there.
In your terminal, position yourself in the obtained memgraph directory.
cd memgraphChoose build method
There are three different methods for building Memgraph:
- Using the
build.shscript (Recommended) - Manually with
conanandcmake(Advanced) - Docker (ideal for unsupported systems)
Before using methods 1 or 2, you must download dependencies and install the toolchain.
Download dependencies (required for methods 1 & 2)
Before you can compile Memgraph, you first need to download its dependencies.
Building Memgraph depends on some system-wide packages. The installation scripts
can be found under environment/os/. The directory contains a dependencies
management script for each supported operating system.
sudo ./environment/os/install_deps.sh install TOOLCHAIN_RUN_DEPS
sudo ./environment/os/install_deps.sh install MEMGRAPH_BUILD_DEPS- The first command installs all the packages necessary for the Memgraph toolchain to work correctly.
- The second command installs the system-wide packages that are not necessary for the toolchain but are required by Memgraph.
Based on your OS, version and architecture, execute appropriate scripts (e.g., on Debian 12, NOTE: the following commands/scripts are located under memgraph repository:
sudo ./environment/os/debian-12.sh install TOOLCHAIN_RUN_DEPS
sudo ./environment/os/debian-12.sh install MEMGRAPH_BUILD_DEPSFor ARM look for -arm in the script name (e.g., on Ubuntu 24.04 with Apple M processor):
sudo ./environment/os/ubuntu-24.04-arm.sh install TOOLCHAIN_RUN_DEPS
sudo ./environment/os/ubuntu-24.04-arm.sh install MEMGRAPH_BUILD_DEPSOnce everything is installed, you can proceed to the compilation.
Toolchain installation (required for methods 1 & 2)
Memgraph is compiled using our own custom toolchain that can be obtained from
the toolchain repository. All our tools used in the development of Memgraph are
manually built for each OS and collected in an archive. Please refer to the
memgraph/environment
folder for all related code.
Keep in mind, cargo is also required to build Memgraph, follow the official
Rust installation
guide.
You should read the Toolchain to install the appropriate toolchain for your distribution.
Download the toolchain for your operating system from one of the following links:
- CentOS 9
- CentOS 10
- Debian 12 (x86_64)
- Debian 12 (arm64)
- Debian 13 (x86_64)
- Debian 13 (arm64)
- Fedora 42 (x86_64)
- Fedora 42 (arm64)
- Rocky Linux 10 (x86_64)
- Ubuntu 22.04 (x86_64)
- Ubuntu 24.04 (x86_64)
- Ubuntu 24.04 (arm64)
Extract the toolchain with the following command:
sudo tar xzvfm {{toolchain-archive}}.tar.gz -C /optAfter you have installed the toolchain, you should read the instructions for the
toolchain in the toolchain install directory (/opt/toolchain-v7/README.md)
and install dependencies that are necessary to run the toolchain.
If you have not already installed toolchain dependencies, please check and install required toolchain runtime dependencies as in the section above.
If you put the toolchain on some other path, it’s possible to say to the cmake
the root is there, that is done by setting MG_TOOLCHAIN_ROOT environment
variable.
That’s also useful where you have different versions of libraries under system compare to what the Memgraph build process needs.
Use build.sh script
This method is the easiest way to build Memgraph directly on a compatible host system.
Calling the script with no arguments will build everything, including tests, for
the Release build type:
./build.shOptionally you can specify target and build types, e.g.
./build.sh --target memgraph --build-type Debugwhere the build type can be Release (default), Debug or RelWithDebInfo.
Other cmake options can be passed as well, e.g. to disable testing:
./build.sh --target memgraph --build-type Release -DMG_ENABLE_TESTING=OFFThe resulting binary will be in the build/ directory.
Use conan and cmake
This approach offers greater flexibility and granular control over the build process.
While it performs the same operations as the build.sh script, it gives you direct access
to configure individual build parameters and dependencies.
To build Memgraph using this method, follow these steps:
Create a Python virtual environment and install conan
python3 -m venv env
source env/bin/activate
pip install conan
conan profile detectRun the init script to fetch other libs required for the build
./initInstall conan dependencies
export MG_TOOLCHAIN_ROOT=/opt/toolchain-v7
conan install . --build=missing -pr ./memgraph_template_profile -s build_type=Release
source build/generators/conanbuild.shConfigure the project with cmake
Note that the name of the preset depends on the build type set in the previous step.
cmake --preset conan-releaseBuild the project
The following command will build everything, including tests.
cmake --build --preset conan-release -j$(nproc)Or for a specific target (e.g. Memgraph binary)
cmake --build --preset conan-release --target memgraph -j$(nproc)Use Docker
Start by setting the environment variables for the desired OS, architecture, and build type:
export OS="ubuntu-24.04"
export ARCH="amd" # or arm
export BUILD_TYPE="Release"
export TOOLCHAIN="v7"Next, pull the appropriate Docker image for the build, e.g.:
docker pull memgraph/mgbuild:v7_ubuntu-24.04Available image tags can be found here.
Then spin up the container:
./release/package/mgbuild.sh \
--toolchain $TOOLCHAIN \
--os $OS \
--arch $ARCH \
--build-type $BUILD_TYPE \
runThen build Memgraph:
./release/package/mgbuild.sh \
--toolchain $TOOLCHAIN \
--os $OS \
--arch $ARCH \
--build-type $BUILD_TYPE \
build-memgraphRun Memgraph inside the container (the name of the container will look something like mgbuild_v7_ubuntu-24.04):
# find the name of the container
docker ps
# run Memgraph
docker exec -i mgbuild_v7_ubuntu-24.04 bash -c "cd /home/mg/memgraph && ./build/memgraph"Stop the container:
./release/package/mgbuild.sh \
--toolchain $TOOLCHAIN \
--os $OS \
--arch $ARCH \
stop --removeRun Memgraph
After the compilation, verify that Memgraph works:
./memgraph --versionThe unit tests can be run using:
ctest -R unit -j$(nproc)Or in Docker:
./release/package/mgbuild.sh \
--toolchain $TOOLCHAIN \
--os $OS \
--arch $ARCH \
--enterprise-license $MEMGRAPH_ENTERPRISE_LICENSE \
--organization-name $MEMGRAPH_ORGANIZATION_NAME \
test-memgraph unit