This tutorial is part of our Valhalla tutorial series:
- Valhalla Docker: How to setup and run Valhalla on Ubuntu with Docker
- Valhalla local [Part1]: How to build and install Valhalla on Ubuntu
- Valhalla local [Part2]: How to configure and run Valhalla locally on Ubuntu
- Valhalla local [Part3]: How to build Valhalla with elevation support on Ubuntu
Learn how to build and install Valhalla from source on Ubuntu 20.04.
Valhalla is a high-performance open source routing software (MIT license) written in C++ and mainly designed to consume OpenStreetMap data. The core engineers work for Mapbox and one of the most prestigious companies using Valhalla is Tesla as their in-car navigation system.
For a comprehensive feature list and a more general overview of FOSS routing engines, read our article.
Validity only confirmed for Ubuntu 20.04 and Valhalla 3.0.9.
Build virtually: If you're new to building software, don't try this tutorial on a setup you depend on. Every system is unique and even if you follow each step correctly in this tutorial, building software from scratch is always bonded to system sensitive tasks and can easily mess around with your live system. Alternatively we recommend you to directly use our How to setup and run Valhalla on Ubuntu 20.04 in Docker or run this tutorial in a freshly installed Ubuntu 18.04 with Virtual Box.
After the tutorial: If you already have a running version of Valhalla and want to learn more, head over to our tutorial on How to configure and run Valhalla on Ubuntu.
In order to build Valhalla on Ubuntu 20.04 you will need to prepare your system with some vital packages.
First update your systems packages with:
sudo apt-get update
This will give you access to the latest available Ubuntu packages through
Then you need to install some basic packages. Those packages should be present on a freshly installed Ubuntu 20.04 but just in case they aren't, run the command:
sudo apt-get install -y git wget curl ca-certificates gnupg2
gitin order to clone repositories from GitHub.
curlare handy tools to download nearly anything from any source through the cli.
gnupg2gives you the tools needed to load and verify packages from third-party sources.
Now you need to install the C++ toolchain. This will give us the basic tools to successfully build and install software, written in C++:
sudo apt-get install -y cmake build-essential
cmakeis needed to configure C/C++ projects (supporting CMake like Valhalla) correctly
g++is the actual c++ compiler you'll use to build Valhalla.
build-essentialholds all the packages needed to build Debian/Ubuntu packages. It serves as the basic package to build from source in Ubuntu.
Then install the rest of the needed dependencies for building the
prime_server and Valhalla:
sudo apt-get install -y libsqlite3-mod-spatialite libsqlite3-dev libspatialite-dev \ autoconf libtool pkg-config libczmq-dev libzmq5 \ libcurl4-openssl-dev zlib1g-dev jq libgeos-dev liblz4-dev \ libgeos++-dev libprotobuf-dev protobuf-compiler \ libboost-all-dev libluajit-5.1-dev spatialite-bin unzip
libspatialite-devare needed for Valhallas spatial processes to work.
libtoolhold tools to configure source packages and is needed for Valhalla and
pkg-configmanages compile and link flags for libraries while building from source. If packages are missing, this one will give you extensive insight into what is missing.
libzmq5belong to ZeroMQ and are needed for the building process of the
libcurl4-openssl-devwill be needed to build Valhalla and
prime_servercorrectly with curl/ssl capabilities.
zlib1g-devis a compression library and is needed by Valhalla.
jqis a CLI tool to deal with JSON structures.
libgeos++-devbelong to a geometry engine for vector operations in C++.
libprotobuf-devbrings protocol buffer support for C++ and is used for high performance (de-)serialization.
protobuf-compileris the compiler for
protobuffunctions and works together with
libboost-all-devis a universal C++ library
libluajit-devis needed by the build setup to run script files written in Lua.
spatialite-binfor the spatialite support of Valhalla for building timezone and admin areas.
unzipfor unzipping files. It is used internally by Valhalla.
Valhalla, more precisely Kevin Kreiser and colleagues, developed a load-balancing web server to deal with the highly heterogeneous work loads of routing engine APIs, where classic load-balancing would fail.
First clone the repository and change inside the newly created directory. Then you should checkout all submodules in order to retrieve linked subgits:
git clone https://github.com/kevinkreiser/prime_server.git cd prime_server git submodule update --init --recursive
After that you will stay inside the directory and just run
autogen.sh and configure the build:
./autogen.sh ./configure --prefix=/usr LIBS="-lpthread"
autogen.shwill generate the source code to a compilable data source.
configurewill check if the ready-to-compile data set is suitable for the current system and if all dependencies are fulfilled.
LIBS="-lpthread"will make sure that the
prime_serveris installed to the user directory and that the dependency
lpthreadis correctly linked to the build files.
If the configure command finishes without any errors, you are ready to build the
prime_server. Again, you will stay inside the same directory and just call the following commands to finally build and install the
make all -j$(nproc) make -j$(nproc) -k test make install cd ../
make allcompiles everything that is inside the current folder.
make testruns the tests once the compilation is done, to check if everything compiled correctly.
make installinstalls the
-jswitch allows you to run the compilation and the tests with as many cores as desired.
-j$(nproc)uses the system variable to determine the amount of all available cores.
maketo keep going even if one (or more) target(s) failed
If everything worked without error until this point, you're good to go to finally build Valhalla.
Now you need to clone the Valhalla repository from GitHub and
cd into the newly created folder:
git clone https://github.com/valhalla/valhalla cd valhalla
After that, sync and update the submodules:
git submodule sync git submodule update --init --recursive
This will give us the up-to-date versions of all needed and included submodules. Those are all so-called header-only libraries. They don't need to be compiled, which makes them highly portable and can be included in projects for convenience (some libraries are harder to install on some OSes).
If you reached this point without errors, you're good to go to build Valhalla:
mkdir build cd $_ cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr \ -DENABLE_BENCHMARKS=OFF
cmake ..configures the build for
make(writes some config files)
-DCMAKE_BUILD_TYPE=Releasewill make the compiler compile the Release version.
-DCMAKE_INSTALL_PREFIX=/usrmakes sure Valhalla is installed to the
-DENABLE_XYconfigs tell CMake to skip some modules mostly required for Valhalla development/testing
If you made it to this point... Congratulations! You're ready to insert the last commands to build and install Valhalla:
cd build make -j$(nproc) # make -j$(nproc) check sudo make install
make -j$(nproc)compiles Valhalla with all available cores
make -j$(nproc) checkruns the Valhalla tests with all available cores. This is optional and takes a lot more time than the simple
makestep. If Valhalla configured and built without errors, you can assume the runtime is fine too, so you can skip this check.
sudo make installinstalls Valhalla to your system (
/usrdirectory you configured with CMake)
Now that Valhalla is successfully running in Ubuntu 20.04, head over to our Tutorial How to configure and run Valhalla on Ubuntu 20.04.