Search This Blog

Monday, May 13, 2013

Adding an executable to PATH on Ubuntu


I needed to run the shp2pgsql command on my machine, for loading certain shape files I had downloaded from NYC GIS data clearing house, into a PostGIS instance. As I ran the shp2pgsql file to remind myself of the input parameters, I got the following error, essentially saying that PostGIS was not installed. This was incorrect, as I had recently installed PostGIS as documented in my previous posts here and fixed some environment issues here.

$shp2pgsql
The program 'shp2pgsql' is currently not installed. You can install it by typing:
sudo apt-get install postgis



Clearly, an issue with my path. I issued a find command to look for the actual installation folder.

$ find -name shp2pgsql

This located the file in its correct location.


Now, I checked my path.

$ echo $PATH

This showed that the shp2pgsql folder was definitely not in my path.



To add shp2pgsql to my path, I had to edit the .bashrc on my machine with the following command.

$ gedit ~/.bashrc



In the file, I added the an entry for appending the path to the executable to the existing system path variable.

PATH=$PATH:~/Work/Servers/PostGIS/postgis-2.0.2/loader
export PATH



Now I saved the file and closed it, and issued the following command on the terminal window, to reload the updated bashrc file into the environment.

$ source ~/.bashrc


Issuing the echo PATH command displayed the updated path, as shown below.


Now entering the shp2pgsql command displays the options for the tool.



Now we can go back to running the shp2pgsql command. This post walks through an example of loading some GIS data into PostGIS using the given command.


No comments: