How to install Qgis3.2 + Grass7 + PGAdmin4 + Postgres11 + Postgis2.5 in Ubuntu Bionic

To start the installation, you must to add the following lines to your /etc/apt/sources.list file:

# qgis
deb http://qgis.org/debian bionic main
deb-src http://qgis.org/debian bionic main

# pgadmin4
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main 11

Now, you need to get the repositories keys with the following sentences:

# qgis
gpg --keyserver keyserver.ubuntu.com --recv CAEB3DC3BDF7FB45
gpg --export --armor CAEB3DC3BDF7FB45 | sudo apt-key add -

# pgadmin4
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Now, proceed with installation:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install postgresql postgresql-contrib postgresql-11-postgis-2.5-scripts pgadmin4 qgis python-qgis qgis-plugin-grass -y

To configure postgres, we procced to create a database with a postgres user:

sudo -u postgres createdb testing
psql -d testing -c "create extension postgis"

Probably you will get the following issue:

psql: FATAL:  password authentication failed for user "postgres"
FATAL:  password authentication failed for user "postgres"

To create a password for postgres user you must do the following:

sudo -u postgres psql
postgres=# ALTER USER postgres PASSWORD 'postgres';
ALTER ROLE
postgres=# \q

If you had a password, probably you will get:

ERROR:  permission denied to create extension "postgis"

HINT:  Must be superuser to create this extension.

To fix it, you must access like postgres user.
You can create a ~/.pgpass file with the following content to avoid enter the password every time:

hostname:port:db_name:user:password

You must change the permissions with chmod 600 ~/.pgpass to avoid this warning:

WARNING: password file "~/.pgpass" has group or world access; permissions should be u=rw (0600) or less

Other option is use PGPASSWORD to avoid interactive password input.

PGPASSWORD=postgres psql 'host=localhost port=5432 dbname=testing user=postgres' 
testing=# CREATE EXTENSION postgis WITH SCHEMA public;
ERROR:  could not access file "$libdir/postgis-2.5": No such file or directory

Postgres can't find postgis-2.5 in $libdir. To check $libdir path execute this command in bash.

pg_config --pkglibdir
/usr/lib/postgresql/11/lib

In fact, no postgis file exists in this folder.
Other error that we can get when postgis is not installed is the following:

ERROR:  could not open extension control file "/usr/share/postgresql/11/extension/postgis.control": No such file or directory

To solve it, we need to install postgis:


sudo apt install postgresql-11-postgis-2.5

If you have problems to install libproj12 dependece like:

postgresql-11-postgis-2.5 : 
                  Depends: liblwgeom-2.5-0 (>= 2.5.0~beta1) but it is not going to be installed
                  Depends: libproj12 (>= 4.9.0) but it is not installable
E: Unable to correct problems, you have held broken packages.

You can download the .deb package and install manually:

wget http://archive.ubuntu.com/ubuntu/pool/universe/p/proj/libproj12_4.9.3-2_amd64.deb
sudo dpkg -i libproj12_4.9.3-2_amd64.deb

Now, proceed again to create postgis extension

testing=# CREATE EXTENSION postgis WITH SCHEMA public;

HINT: To check postgres service port, you can check with netstat

sudo netstat -plunt | grep postgres

Don't forget change your postgres user password:

sudo -u postgres psql   
postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=# \q

Enjoy!


Comments

Popular posts from this blog

How to fix Android when developer options are not available for this user

from: can't read /var/mail/ in Python scripts

How to fix VirtualBox error when you try to import an ova file