Version 12 (modified by 10 years ago) ( diff ) | ,
---|
The PostgreSQL Apt Repository now hosts installs of PostGIS, in addition to Postgresql and PGAdmin3.
The following describes how to install Postgresql 9.4, PostGIS 2.1, PGAdmin 1.20 and shp2pgsql-gui on Ubuntu versions 12.04 and 14.04.1
Run these in terminal:
Verify what you are running
sudo lsb_release -a
Add Respository to sources.list
You'll need to replace the nickname below with what you are running So if you see you are running precise (12.04) do this
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list'
If trusty (14.04)
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt trusty-pgdg main" >> /etc/apt/sources.list'
Add Keys
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
Install
The following will install postgresql 9.4, PostGIS, PGAdmin3, and additional supplied modules including adminpack
sudo apt-get install postgresql-9.4 pgadmin3 postgresql-contrib
For 12.04 thru 13.02, this seems to work
sudo apt-get install postgresql-9.4-postgis pgadmin3 postgresql-contrib
If you are running 14.04 (Trusty) — you need to do this
sudo apt-get install postgresql-9.4-postgis-2.1 pgadmin3 postgresql-contrib
To get pgRouting
(instructions from http://workshop.pgrouting.org/chapters/installation.html seems to work fine with PostgreSQL Apt repo PostgreSQL 9.3 install)
sudo apt-add-repository -y ppa:georepublic/pgrouting sudo apt-get update # Install pgRouting package (for Ubuntu 14.04) sudo apt-get install postgresql-9.3-pgrouting
Enable Adminpack
While in terminal, log in to psql as postgres user:
sudo -u postgres psql
CREATE EXTENSION adminpack;
Quit psql:
\q
Create new PGSQL user
You can create a new database super user to use instead of the default postgres
user.
While in terminal, run:
sudo su - postgres
createuser -d -E -i -l -P -r -s yourUserName
(be sure to change the username to your desired username)
Enter your new password when prompted
Log out as postgres
user:
exit
Exit terminal:
exit
Use PGAdmin to log into database server
From the Ubuntu launcher, type in PGAdmin to reveal the application
Click the Add a connection to server
button on the menu in the top-left corner
Fill in the necessary credentials to log in:
- Name: nickname you want to give your connection - host: localhost (until you change the connection settings) - port: 5432 by default - maintenance DB: postgres by default - username: whatever you chose in the step above - password: whatever you chose in the step above
Enable postgis extensions on new database
Since you installed PostgreSQL and PostGIS from the PostgreSQL apt repository, you now have all the extensions for PostgreSQL, including PostGIS
Expand the database tree in PGAdmin, and reveal the extensions node
Right-click the extensions node, and click new extension
Enable the postgis extension, as well as postgis_topology, and postgis_tiger_geocoder
Alternatively from psql console you can do
CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology; CREATE EXTENSION postgis_tiger_geocoder;
Import SHP files using shp2pgsql-gui
Another handy piece of software shp2pgsql-gui
tool. This will allow you to quickly connect to your new PostGIS database and import a Shapefile.
Open terminal, and type:
shp2pgsql-gui
Follow the on-screen prompts to load your data.
For more information, visit the Boston GIS tutorial in the section "Load Towns Data"