Building 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 (opens in a new tab) first.
ARM build instructions are located at Building Memgraph for ARM64 CPU (opens in a new tab) document.
Obtaining 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.git
The above will create a memgraph
directory and put all source code there.
Downloading the dependencies
Before you can compile Memgraph, you first need to download its dependencies
In your terminal, position yourself in the obtained memgraph directory.
cd memgraph
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 11, NOTE: the following commands/scripts are located under memgraph repository (opens in a new tab):
sudo ./environment/os/debian-11.sh install TOOLCHAIN_RUN_DEPS
sudo ./environment/os/debian-11.sh install MEMGRAPH_BUILD_DEPS
For ARM look for -arm
in the script name (e.g., on Ubuntu 22.04 with Apple M processor):
sudo ./environment/os/ubuntu-22.04-arm.sh install TOOLCHAIN_RUN_DEPS
sudo ./environment/os/ubuntu-22.04-arm.sh install MEMGRAPH_BUILD_DEPS
Once everything is installed, you can proceed to the compilation.
Compiling
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
(opens in a new tab)
folder for all related code.
Keep in mind, cargo
is also required to build Memgraph, follow the official
Rust installation
guide (opens in a new tab).
You should read the Toolchain (opens in a new tab) to install the appropriate toolchain for your distribution.
Toolchain installation procedure
Download the toolchain for your operating system from one of the following links:
- CentOS 7 (opens in a new tab)
- CentOS 9 (opens in a new tab)
- Fedora 39 (opens in a new tab)
- Debian 11 (x86_64) (opens in a new tab)
- Debian 11 (arm64) (opens in a new tab)
- Debian 12 (x86_64) (opens in a new tab)
- Debian 12 (arm64) (opens in a new tab)
- Ubuntu 20.04 (opens in a new tab)
- Ubuntu 22.04 (x86_64) (opens in a new tab)
- Ubuntu 22.04 (arm64) (opens in a new tab)
- Ubuntu 24.04 (x86_64) (opens in a new tab)
- Ubuntu 24.04 (arm64) (opens in a new tab)
Extract the toolchain with the following command:
sudo tar xzvfm {{toolchain-archive}}.tar.gz -C /opt
After you have installed the toolchain, you should read the instructions for the
toolchain in the toolchain install directory (/opt/toolchain-v5/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 by executing
sudo ./environment/os/install_deps.sh check TOOLCHAIN_RUN_DEPS
sudo ./environment/os/install_deps.sh install TOOLCHAIN_RUN_DEPS
Based on your OS, version and architecture, execute appropriate scripts (e.g., on Debian 11, NOTE: the following commands/scripts are located under memgraph repository (opens in a new tab)):
sudo ./environment/os/debian-11.sh check TOOLCHAIN_RUN_DEPS
sudo ./environment/os/debian-11.sh install TOOLCHAIN_RUN_DEPS
For ARM look for -arm
in script name (e.g. on Ubuntu 22.04 with Apple M processor):
sudo ./environment/os/ubuntu-22.04-arm.sh check TOOLCHAIN_RUN_DEPS
sudo ./environment/os/ubuntu-22.04-arm.sh install TOOLCHAIN_RUN_DEPS
When you want to compile Memgraph, you should activate the toolchain using the
prepared toolchain activation script that is also described in the toolchain
README
.
You must activate the toolchain every time you want to compile Memgraph:
source /opt/toolchain-v5/activate
In case you need to deactivate the toolchain, you can run:
deactivate
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 (opens in a new tab).
That’s also useful where you have different versions of libraries under system compare to what the Memgraph build process needs.
Installing Memgraph dependencies
In addition to the system-wide dependencies, Memgraph requires certain libraries
to be built locally. The proper setup of these libraries should be checked by
running the init
script:
./init
Make sure to activate the toolchain before the ./init
command.
With all of the dependencies installed and the build environment set-up, you need to configure the build system. To do that, execute the following:
mkdir -p build
cd build
cmake ..
If only Memgraph binary is required you can run build using:
make -j$(nproc) memgraph
If you need to compile the whole project (e.g., unit tests) run:
make -j$(nproc)
Running Memgraph
After the compilation, verify that Memgraph works:
./memgraph --version
The unit tests can be run using
ctest -R unit -j$(nproc)