Install OSRM Server on Ubuntu 24.04 Locally

Install OSRM Server on Ubuntu 24.04 Locally

The Open Source Routing Machine (OSRM) is a high-performance routing engine used to calculate routes, distances, and travel times using OpenStreetMap data.

Step 1: Update your server

sudo apt update && sudo apt upgrade -y

Step 2: Install required dependencies

sudo apt install build-essential git cmake pkg-config \
libbz2-dev libstxxl-dev libstxxl1v5 libxml2-dev \
libzip-dev libboost-all-dev lua5.3 liblua5.3-dev -y

Step 3: Download OSRM backend

git clone https://github.com/Project-OSRM/osrm-backend.git
cd osrm-backend
mkdir build && cd build
cmake ..
make -j4

Step 4: Verify installation

./osrm-extract --help

Step 5: Download Germany Map Data, Go to Geofabrik

https://download.geofabrik.de/europe/germany-latest.osm.pbf

Step 6: Move file to OSRM folder

mv germany-latest.osm.pbf ~/osrm-backend/
cd ~/osrm-backend

Step 7: Extract routing data

./build/osrm-extract germany-latest.osm.pbf -p profiles/car.lua

Step 8: Partition data

./build/osrm-partition germany-latest.osrm

Step 9: Customize data

./build/osrm-customize germany-latest.osrm

Step 10: Start routing engine, Start OSRM Server

./build/osrm-routed germany-latest.osrm

Step 11: Server runs on port 5000

Open in browser:

http://localhost:5000

You can test API from address:

http://localhost:5000/route/v1/driving/13.388860,52.517037;13.397634,52.529407

You should get JSON response

Step 12: Prepare frontend or backend, Call from C# application

$url = "http://localhost:5000/route/v1/driving/$lon1,$lat1;$lon2,$lat2";
$json = file_get_contents($url);
$data = json_decode($json, true);
$distance = $data['routes'][0]['distance'];
$duration = $data['routes'][0]['duration'];
$km = $distance / 1000;
$minutes = $duration / 60;

HowCSharp © 2007 Sitemap, Privacy Policy, Contact