Open Source Routing Machine (OSRM) is a routing engine designed for OpenStreetMap data. It allows you to calculate the shortest or fastest route between two or more points, and can also provide turn-by-turn directions for navigation. In this tutorial, we will show you how to install OSRM on Ubuntu Server.
Before starting, you will need the following:
To install OSRM on Ubuntu Server, you need to install several dependencies first. Open the console and type the following command:
sudo apt install build-essential git cmake pkg-config \
libbz2-dev libxml2-dev libzip-dev libboost-all-dev \
lua5.2 liblua5.2-dev libtbb-dev
This command installs build tools, libraries, and dependencies that are required by OSRM.
Next, you need to clone the OSRM repository using the following command:
git clone https://github.com/Project-OSRM/osrm-backend.git
This command fetches the source code from the OSRM backend repository.
Now you are ready to build OSRM. Navigate to the directory where you cloned the repository using the following command:
cd osrm-backend
Then, create a directory to store the build files:
mkdir -p build
cd build
Finally, run the following command to build OSRM:
cmake ..
cmake --build .
sudo cmake --build . --target install
This command runs the cmake build system, builds the OSRM backend and installs it on your system.
To use OSRM, you need OpenStreetMap data. You can download the data for a specific area from the OpenStreetMap website or use the following command to download the data for the entire planet:
wget http://planet.osm.org/pbf/planet-latest.osm.pbf
This command downloads the latest version of the planet.osm file in PBF format.
Now that you have downloaded the OSM data, you need to prepare it for use with OSRM. Run the following command to extract the data:
osrm-extract planet-latest.osm.pbf -p profile.lua
This command uses the profile.lua file to extract the routing data from the planet.osm.pbf file and create a .osrm file.
Next, you need to prepare the .osrm file for use with OSRM. Run the following command:
osrm-contract planet-latest.osrm
This command contracts the .osrm file and creates a .osrm.hsgr file that can be used by OSRM.
You are now ready to start OSRM with the following command:
osrm-routed planet-latest.osrm
This command starts the OSRM backend server and loads the planet-latest.osrm file. You should see a message similar to the following:
Listening on: http://0.0.0.0:5000
This indicates that the server is running and ready to receive requests.
To test OSRM, open a web browser and enter the following URL:
http://localhost:5000/route/v1/driving/<longitude>,<latitude>;<longitude>,<latitude>?steps=true
Replace <longitude>
and <latitude>
with the coordinates of two points. For example:
http://localhost:5000/route/v1/driving/13.388860,52.517037;13.397634,52.529407?steps=true
This URL should return a JSON response containing the shortest/fastest route between the two points.
You have successfully installed and tested OSRM on Ubuntu Server. Congratulations!
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!