shp2pgsql command not found

In this troubleshooting guide we learn how to fix shp2pgsql command not found error message

Introduction

When you run more command in linux terminal / console, you get the following error message

shp2pgsql: command not found

or when using sudo you get the following error message

sudo: shp2pgsql: command not found

Solutions to shp2pgsql: command not found

How To Fix shp2pgsql: command not found in Ubuntu / Debian / Kali Linux / Raspbian

In Ubuntu shp2pgsql is provided by postgis package.

postgis is:

PostGIS adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS “spatially enables” the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS), much like ESRI’s SDE or Oracle’s Spatial extension. PostGIS follows the OpenGIS “Simple Features Specification for SQL”.

This package contains the PostGIS userland binaries for importing and exporting shape and raster files: pgsql2shp, raster2pgsql, and shp2pgsql.

To fix this problem, we can install more using the command below.

sudo apt-get -y install postgis

This command might take some time to finish depending on your machine internet connection.

You can also use apt command to install postgis.

sudo apt -y install postgis

Or if you have aptitude installed you can use the following command.

sudo aptitude install postgis

Summary

In this tutorial we learn how to fix shp2pgsql command not found error in Ubuntu / Debian / Kali Linux or Raspbian distribution.