How to Install Nominatim on Elementary OS Latest

Nominatim is a tool used for geocoding which can be installed on Elementary OS. Geocoding is the process of transforming addresses or place names into geographic coordinates. In this tutorial, we will go through the steps on how to install Nominatim on Elementary OS.

Prerequisites

Before we start with the installation process, we need to make sure that our system is up to date and we have the necessary packages installed.

sudo apt update

sudo apt upgrade

Next, we need to install some prerequisite packages for Nominatim:

sudo apt install build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev libtool automake libproj-dev

Installing PostgreSQL

Nominatim requires PostgreSQL as its database. We need to install PostgreSQL and create a new database and user for Nominatim.

sudo apt install postgresql postgresql-contrib

Once PostgreSQL is installed, create a new database and user:

sudo -u postgres createuser -s nominatim
sudo -u postgres createdb nominatim

Downloading and Building Nominatim

Now it's time to download and build Nominatim.

sudo apt-get install git

Clone the Nominatim repository using the following commands:

mkdir ~/src && cd ~/src
git clone --recursive https://github.com/osm-search/Nominatim.git
cd Nominatim

Next, build Nominatim using the following command:

./autogen.sh
./configure
make

Setting up Nominatim

After building is complete, we need to set up Nominatim.

sudo mkdir /srv/nominatim
sudo chown $USER:$USER /srv/nominatim

Next, create a file "settings/local.php" and add the following content:

<?php
 @define('CONST_Database_DSN', 'pgsql://nominatim@localhost/nominatim');
 @define('CONST_Geoserver', 'http://127.0.0.1/osm_tiles/');
 @define('CONST_Mapnik_Font_Directory', '/usr/share/fonts/truetype');
?>

Configure Apache web server to serve the Nominatim tool by creating "nominatim.conf" file under Apache configuration directory:

sudo nano /etc/apache2/conf-available/nominatim.conf

Add the following content:

ServerName localhost
DocumentRoot /srv/nominatim/build
<Directory "/srv/nominatim/build">
 Options FollowSymLinks MultiViews
 AllowOverride All
 Require all granted
</Directory>

Save and close the file, then enable the configuration:

sudo a2enconf nominatim.conf

You also need to change the PHP configuration, edit the file "/etc/php/7.4/apache2/php.ini":

sudo nano /etc/php/7.4/apache2/php.ini

Set the following:

memory_limit = 2G
cgi.fix_pathinfo=0

Save and exit the file.

Importing Country Data

Finally, we will download and import OpenStreetMap data to our Nominatim database.

Download OpenStreetMap data for your desired location or area from https://download.geofabrik.de/.

Once downloaded, extract the data file, and rename it as "data.osm.pbf". Copy the file to the "/srv/nominatim" directory.

Now, import the data to the Nominatim database:

./utils/setup.php --osm-file /srv/nominatim/data.osm.pbf --all --threads 4

After the import is complete, generate tiles and restart Apache:

sudo ./utils/setup.php --create-functions --enable-diff-updates

sudo service apache2 restart

Conclusion

That's it! You have successfully installed and configured Nominatim on your Elementary OS. You can now run geocoding requests using Nominatim.

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!