How to install IP2Location Geolocation Library in Alpine Linux

IP2Location Geolocation Library in Alpine Linux

This tutorial is going to guide you with the installation of the IP2Location Geolocation into Alpine Linux – a small and lightweight linux distro. In summary, to use IP2Location C Library, you will need to download the source from the github, https://github.com/chrislim2888/IP2Location-C-Library/, build and install into your Linux system.

Step 1: Download the IP2Location C Library

Before getting started, you will need to download IP2Location C library. There are 2 options for the download:

1. Alpine Linux repository

2. Github repository

Download IP2Location C library From Alpine Linux Testing Repository

Use the command below to download the IP2Location C library.

apk add ip2location --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/
Download and installation

Download IP2Location C library From Linux Github Repository

Use the git command to download the latest version of IP2Location C library source codes. If you do not have the git package in your system, run the below command to install it.

apk add git

Once completed, you can run the below command to download the IP2Location C library source codes.

git clone https://github.com/chrislim2888/IP2Location-C-Library/

You should see a new IP2Location-C-Library folder after the above execution. The next step would be to set up the C compiler and the development tools.

Step 2: Install C compiler and development tools

You need to execute the below command to install the essential C compiler and all the development packages for C compilation.

apk add build-base automake autoconf libtool

Step 3: Compile and build the IP2Location C Library

Now, you have all the environment and packages ready for compilation. You can now go to the source code by changing the directory into the IP2Location-C-Library folder.

cd IP2Location-C-Library
  

Inside the source codes directory, run the following command to set up the build environment and the configure script.

autoreconf -i -v --force

You should see the command completed without any errors.

Installation done

Next you can run the configure script, then followed by make install to complete the entire building process.

./configure
make && make install

You should see the below screen run successfully without an error.

Simple run

To test the installation process, you can run ip2location –version command, and it should return you the latest version number. If you see that, congratulations, you have gotten the IP2Location geolocation library installed successfully into the Alpine Linux.

How to use the IP2Location Library

The above steps will install a command tool, ip2location, and the associated C Libraries into your Alpine Linux. You can either invoke the ip2location to use it directly, or you can incorporate it into your C project by including the C Library header.

Please note that the IP2Location Library is just a library for reading the IP address information from a BIN data file. Hence, before you use the library, you have to download the IP2Location BIN data from https://lite.ip2location.com. If you are looking for comprehensive and higher accuracy database, you can consider to use the IP2Location commercial database. Learn more about the differences between LITE and commercial.

IP2Location LITE database

After you have downloaded the data file, you can invoke the below command to lookup geolocation for the specified IP address. Please note that the granularity of the data will be depending on the type of BIN data file you’ve downloaded. For example, for DB3, it will provide you with the country, region and city information only.

Ip2location -p 8.8.8.8 -d IP2LOCATION-LITE-DB3.BIN
Lookup result

Was this article helpful?

Related Articles