15

I have been installed postgis following this guide. All is OK.

SELECT postgis_full_version();
"POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.10.1, released 2013/08/26" LIBXML="2.9.1" LIBJSON="UNKNOWN" TOPOLOGY RASTER"

But I have not the shp2pgsql in /usr/lib/postgresql/9.4/bin as you can see:

foo@bar:/usr/lib/postgresql/9.4/bin$ ls
clusterdb   initdb             pg_dump         pg_standby      psql
createdb    oid2name           pg_dumpall      pg_test_fsync   reindexdb
createlang  pg_archivecleanup  pg_isready      pg_test_timing  vacuumdb
createuser  pg_basebackup      pg_receivexlog  pg_upgrade      vacuumlo
dropdb      pgbench            pg_recvlogical  pg_xlogdump
droplang    pg_controldata     pg_resetxlog    postgres
dropuser    pg_ctl             pg_restore      postmaster

Why this happens? and how can I install it?

1
  • Not sure about linux but on Windows shp2pgsql is in with the PostGis\bin and not postgresql\bin.. Commented May 26, 2015 at 3:01

6 Answers 6

21

I was also following the OP's installation method of PostgreSQL and PostGIS, namely

sudo apt-get install postgresql-9.4-postgis-2.1 pgadmin3 postgresql-contrib-9.4

I enabled the PostGIS extension in a database but didn't get shp2pgsql to work until I did

sudo apt-get install postgis

as listed toward the bottom of the page. Why postgresql-9.4-postgis-2.1 doesn't include shp2pgsql and simply postgis does .... I'm not really sure. But PostgreSQL, PostGIS, and shp2pgsql are all working fine now.

1
  • Same goes for Fedora
    – TheSteve0
    Commented Sep 11, 2019 at 4:17
9

When installing postgis on Linux, be sure to install the client also, as postgis on its own will not install the shp2pgsql executable.

yum install postgis2_94
yum install postgis2_94-utils
yum install postgis2_94-client

Until you install the client, there is just a link in /usr/bin/ pointing to /etc/alternatives/postgis-shp2pgsql. This is just an empty link until the client install places the executables in /usr/pgsql-9.4/bin.

Hope this helps, appreciate the OP asked the question some months ago and I hope found a resolution sooner.

1
  • Updating in 2023... working with RHEL 9.2, postgresql15, and postgis 3.3.3. Installing the utils and client worked for me.
    – MKF
    Commented Jul 19, 2023 at 14:59
4

Normally, the shp2pgsql binary is in /usr/bin/shp2pgsql when you install with packages like in the method you mentioned.

Did you type shp2pgsql in command line? Normally, it works out of the box.

If not,

  • did you do an updatedb (command line to index files) followed with a locate shp2pgsql to find the real binary path?

  • did you echoed the output from the command line using echo $PATH? And what is the output?

3
  • Command sudo locate shp2pgsql is empty. Command echo $PAHT returns /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games Commented May 26, 2015 at 22:04
  • Because sudo locate shp2pgsql is empty, it seems you didn't installed shp2pgsql properly (or you forgot to do sudo updatedb). If the package name is the same for additional repo and the default, doing a sudo apt-get install postgis should install both shp2pgsql and shp2pgsql-gui. This answer is based on the fact I supposed you are using a Debian based distro (Debian, Mint or Ubuntu)
    – ThomasG77
    Commented May 27, 2015 at 0:51
  • I run sudo shp2pgsql and sudo apt-get install postgis but keeps the error foo@bar:/usr/lib/postgresql/9.4$ shp2pgsql bash: /usr/local/bin/shp2pgsql: No existe el archivo o el directorio Commented May 27, 2015 at 2:28
1

This is more difficult than expected when going against the grain of the latest releases, which is possible using the http://apt.postgresql.org/pub/repos/apt.

For example, when using postgresql-11 installations, simply adding postgis attempts to also add postgresql-12 !

$ dpkg -l | grep postg
ii  pgdg-keyring                               2018.2                                                     all          keyring for apt.postgresql.org
ii  postgis-doc                                2.4.3+dfsg-4                                               all          Geographic objects support for PostgreSQL -- documentation
ii  postgresql-11                              11.7-2.pgdg18.04+1                                         amd64        object-relational SQL database, version 11 server
ii  postgresql-11-pgrouting                    3.0.0~rc1-1.pgdg18.04+1                                    amd64        Routing functionality support for PostgreSQL/PostGIS
ii  postgresql-11-pgrouting-scripts            3.0.0~rc1-1.pgdg18.04+1                                    all          Routing functionality support for PostgreSQL/PostGIS - SQL scripts
ii  postgresql-11-postgis-2.5                  2.5.4+dfsg-1.pgdg18.04+1                                   amd64        Geographic objects support for PostgreSQL 11
ii  postgresql-11-postgis-2.5-scripts          2.5.4+dfsg-1.pgdg18.04+1                                   all          Geographic objects support for PostgreSQL 11 -- SQL scripts
ii  postgresql-client-11                       11.7-2.pgdg18.04+1                                         amd64        front-end programs for PostgreSQL 11
ii  postgresql-client-common                   213.pgdg18.04+1                                            all          manager for multiple PostgreSQL client versions
ii  postgresql-common                          213.pgdg18.04+1                                            all          PostgreSQL database-cluster manager
ii  postgresql-plpython-11                     11.7-2.pgdg18.04+1                                         amd64        PL/Python procedural language for PostgreSQL 11
ii  postgresql-plpython3-11                    11.7-2.pgdg18.04+1                                         amd64        PL/Python 3 procedural language for PostgreSQL 11
ii  postgresql-server-dev-11                   11.7-2.pgdg18.04+1                                         amd64        development files for PostgreSQL 11 server-side programming


$ sudo apt-get install  postgis
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  postgresql-12 postgresql-12-postgis-3 postgresql-12-postgis-3-scripts postgresql-client-12
Suggested packages:
  postgis-gui postgresql-doc-12
The following NEW packages will be installed:
  postgis postgresql-12 postgresql-12-postgis-3 postgresql-12-postgis-3-scripts postgresql-client-12
0 upgraded, 5 newly installed, 0 to remove and 21 not upgraded.
Need to get 336 kB/20.6 MB of archives.
After this operation, 90.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] n
Abort.

There is no option for a postgis-11 set of utils. If everything else is on the latest versions, it just-works.

Trying to install only the postgis package sorta works, but it installs a 3.x version rather than a matching 2.x version, e.g.

$ sudo apt-get install --no-install-recommends postgis
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  postgis-gui
Recommended packages:
  postgresql-12-postgis-3
The following NEW packages will be installed:
  postgis
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 336 kB of archives.
After this operation, 1,621 kB of additional disk space will be used.
Get:1 http://apt.postgresql.org/pub/repos/apt bionic-pgdg/main amd64 postgis amd64 3.0.1+dfsg-2.pgdg18.04+1 [336 kB]
Fetched 336 kB in 2s (215 kB/s)  
Selecting previously unselected package postgis.
(Reading database ... 374551 files and directories currently installed.)
Preparing to unpack .../postgis_3.0.1+dfsg-2.pgdg18.04+1_amd64.deb ...
Unpacking postgis (3.0.1+dfsg-2.pgdg18.04+1) ...
Setting up postgis (3.0.1+dfsg-2.pgdg18.04+1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
0

Try updating first, and then proceed from there:
sudo apt-get update.

Seems dumb, but I was having trouble with my installations of psql and postgis and it all cleared up once I updated.

0

Adding some news on it. With APT, PostgreSQL 13 and PostGIS 3 you will need to also install apt install postgis-gui.

Source: https://ubuntu.pkgs.org/20.04/ubuntu-universe-amd64/postgis-gui_3.0.0+dfsg-6ubuntu4_amd64.deb.html

Or p.570 of PostGIS in Action 3ed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.