Linux Tutorials, Guides & Latest Tech Stuffs

Installing pgAdmin4 on Ubuntu 16.04 Desktop mode

pgAdmin is open source administration platform for PostgreSQL. It provides number of functionalities to perform on the database from a browser. This post will describe step by step guide for installing pgAdmin4 on Ubuntu 16.04 and Ubuntu 17.04.


  1. Python 2.7
  2. Pip
  3. Virtualenv

Update ubuntu environment

sudo apt-get update

Install Requirements

Install python 2.7  pip and Virtualenv by running this command

sudo apt-get install python2.7-dev virtualenv python-pip libpq-dev

create a directory for your python environment

Let’s create directory for pgAdmin4 at your /home/ubuntu in a apps folder

mkdir -p ~/apps/pgadmin4

Go to apps directory and then make pgadmin4 directory to a virtual environment

cd ~/apps
virtualenv pgadmin4

sample output – Output like this will appear on your screen

Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/q/apps/pgadmin4/bin/python2
Also creating executable in /home/q/apps/pgadmin4/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.

Activate your virtual environment

cd pgadmin4
source bin/activate

* After successfully activating pgadmin4 will be start appearing in bracket like this (pgadmin4)


Download Latest python wheel file

Get Latest pgAdmin4 python wheel file from pgAdmin4 official download page

Run a wget request to download file, in my case v4.2.0 is latest in your case it may vary so please change download url as per version requirement.


After running this command something like this will appear on your screen this means download is complete

pgadmin4-2.0-py2.py3-none-any.whl 100%[==================================================================>] 59.18M 11.6MB/s in 6.0s


Install from python wheel file

Now run the python wheel file by running

pip install pgadmin4-2.0-py2.py3-none-any.whl

After successful installation, you need to run from installation path which is a copy of located at lib/python2.7/site-packages/pgadmin4/

create a file using command below

vim ~/apps/pgadmin4/lib/python2.7/site-packages/pgadmin4/

and paste following code

import os
DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
SQLITE_PATH = os.path.join(DATA_DIR, 'pgadmin4.db')
SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions')
STORAGE_DIR = os.path.join(DATA_DIR, 'storage')

Now run this final command for running pgAdmin4 in your local ubuntu computer

python ~/apps/pgadmin4/lib/python2.7/site-packages/pgadmin4/

you will see something like this in terminal

Starting pgAdmin 4. Please navigate to in your browser.

Now just navigate in browser to http://localhost:5050 to see your pgAdmin4 running

pgAdmin4 installation

pgAdmin4 Installation on Ubuntu 16.04 and 17.04

Create pgAdmin4 Shortcut on Desktop for easy starting pgAdmin4

Create a shell file on your desktop like this, as it would help to restart pgAdmin4 when you will restart your Ubuntu computer

cd ~/Desktop
touch pgadmin4
vim pgadmin4

and put the following command that we have used earlier in this blog. I have added source line after suggestion from LUQMAAN ( see comments below ), since this will help to start PgAdmin after computer restart.

source ~/apps/pgadmin4/bin/activate
python ~/apps/pgadmin4/lib/python2.7/site-packages/pgadmin4/

now make it executable by running

chmod +x ~/Desktop/pgadmin4

now you can run it from desktop too, Go to desktop by cd ~/Desktop and run


>> If you are looking to install PgAdmin4 in server mode check this blog post

Pranav K

Pranav K is a software engineer and all-round computer geek. His interests include AWS, Ubuntu and Wordpress


  1. Hi pranav,
    Thanks for your instructions, i was successfully installed and configured pgadmin4, after the restart my ubuntu pc computer, how to start and run the pgadmin4, please give me instructions with screen-shot.

  2. Hi Prabakaran,

    I have updated my post, you can follow instructions to create a pgAdmin4 shortcut on your desktop for easily starting pgAdmin4 after restarting your PC.

  3. Hello,
    Thank you for this very useful tutorial, it worked very well.

    However when I try to launch pgadmin4 after rebooting my PC I have the following error:

    File “/…/pgadmin4/lib/python2.7/site-packages/pgadmin4/”, line 34, in
    import config
    File “/…/pgadmin4/lib/python2.7/site-packages/pgadmin4/”, line 30, in
    from pgadmin.utils import env, IS_PY2, IS_WIN, fs_short_path
    File “/…/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgadmin/”, line 17, in
    from flask import Flask, abort, request, current_app, session, url_for
    ImportError: No module named flask

    I tried to install separately flask (even if the directory already existed) but then another module is missing.

    For the moment I did not find better solution than re-install everything each time. Do you have any suggestions?

    Thank you very much

    • Hi AURELIE,

      Thankyou for writing us, I have also faced this issue. Sometimes it comes in and you need to reinstall all the module even if it is already installed. Is your issue is solved after fresh installation ?. Please let me know if problem still persist

      • Hi,
        THank you for your answer. It worked several times and then even with a whole re-install it did not worked. I uninstall everything including python (and dependencies?), now I have a bigger issue that I am unable to solve (message below).
        I found on the web few suggestions to access a database called “alembic_version” table but I don’t have any table with this name in psql.
        I would really appreciate your insights on this matter. Thank you! 🙂

        Traceback (most recent call last):
        File “/home/user/pgadmin4-2.0/web/”, line 48, in
        app = create_app()
        File “/home/user/pgadmin4-2.0/web/pgadmin/”, line 300, in create_app
        File “/home/user/pgadmin4-2.0/web/pgadmin/setup/”, line 25, in db_upgrade
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/flask_migrate/”, line 244, in upgrade
        command.upgrade(config, revision, sql=sql, tag=tag)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/”, line 254, in upgrade
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 425, in run_env
        util.load_python_file(self.dir, ‘’)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/util/”, line 81, in load_python_file
        module = load_module_py(module_id, path)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/util/”, line 83, in load_module_py
        File “”, line 665, in exec_module
        File “”, line 222, in _call_with_frames_removed
        File “/home/user/pgadmin4-2.0/web/pgadmin/setup/../../migrations/”, line 94, in
        File “/home/user/pgadmin4-2.0/web/pgadmin/setup/../../migrations/”, line 87, in run_migrations_online
        File “”, line 8, in run_migrations
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/runtime/”, line 836, in run_migrations
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/runtime/”, line 321, in run_migrations
        for step in self._migrations_fn(heads, self):
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/”, line 243, in upgrade
        return script._upgrade_revs(revision, rev)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 338, in _upgrade_revs
        for script in reversed(list(revs))
        File “/usr/lib/python3.5/”, line 77, in __exit__
        self.gen.throw(type, value, traceback)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 174, in _catch_revision_errors
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/util/”, line 194, in raise_from_cause
        reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/util/”, line 187, in reraise
        raise value.with_traceback(tb)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 143, in _catch_revision_errors
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 334, in _upgrade_revs
        revs = list(revs)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 645, in _iterate_revisions
        requested_lowers = self.get_revisions(lower)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 299, in get_revisions
        return sum([self.get_revisions(id_elem) for id_elem in id_], ())
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 299, in
        return sum([self.get_revisions(id_elem) for id_elem in id_], ())
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 304, in get_revisions
        for rev_id in resolved_id)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 304, in
        for rev_id in resolved_id)
        File “/home/user/virtualenvs/pgadmin4/lib/python3.5/site-packages/alembic/script/”, line 362, in _revision_for_ident
        alembic.util.exc.CommandError: Can’t locate revision identified by ’02b9dccdcfcb’

        • Hi Aurelie,

          You seems to be using Python 3.5. Have you tried with Python 2.7 ?. Please use Python 2.7 and install all requirements and dependencies. Also change file locations defined in

  4. Thanks for the great tutorial..

    For anyone having issues with starting pgAdmin 4 after restart, it is merely because you are trying to start pgAdmin 4 outside of the virtual environment. The virtual environment contains all the necessary python libraries (including flask) to run pgAdmin 4.

    A simple fix is to add the following line to the beginning of pgadmin4 ‘shortcut’ file on the desktop:

    source ~/apps/pgadmin4/bin/activate
    python ~/apps/pgadmin4/lib/python2.7/site-packages/pgadmin4/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.