Install PostgreSQL and pgAdmin4 on Ubutu

  1. Update the System

Before Starting Installation Process , you have to update the System by executing the following command.

sudo apt-get update

2. Install Required packages

Three packages require to install before downloading pgAdmin which are python, pip and virtualenv. Run the following command to install these packages.

sudo apt-get install build-essential libssl-dev libffi-dev libgmp3-dev virtualenv python-pip libpq-dev python-dev

3. Create virtual environment

Run the following commands to create a new folder named pgAdmin4 in the current location, go to the newly created folder and create the virtual environment.

mkdir pgAdmin4
cd pgAdmin4
$ virtualenv pgAdmin4

4. Activate virtual environment

Go to pgAdmin4 folder under pgAdmin4 and run the following commands to activate the virtual environment.

cd pgAdmin4
source bin/activate

5.Download pgAdmin 4

Run the following command to download the latest version of pgAdmin 4.

$ wget

After completing the download of pgAdmin, the console will be look like the following image.

6. Install pgAdmin 4

Run the following command to complete the installation process of pgAdmin 4.

$ pip install pgadmin4-2.1-py2.py3-none-any.whl

7. Configure and run pgAdmin 4

After completing the installation steps, you have to create a configuration file to run this software. Create a new file named in lib/python2.7/site-packages/pgadmin4/ folder using nano editor.

$ nano lib/python2.7/site-packages/pgadmin4/

Add the following content in

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, use the following command to run pgAdmin.

$ python lib/python2.7/site-packages/pgadmin4/

Now, access http://localhost:5050 from any browser. If all the steps are completed properly then the browser will display the following page.

  • Using PostgreSQL pgAdmin4

Before using pgAdmin, you need to confirm that the latest version of PostgreSQL is installed on your operating system. Run the following command to install postgres package for PostgreSQL and contrib package for taking additional functionalities related to PostgreSQL.

$ sudo aptGET install postgresql postgresqlcontrib

Next, you have to create the username and password for PostgreSQL database. Type the following command in the terminal to add login credentials for the user, postgres.

$ sudo u postgres psql postgres

Setup the password for the username, ‘postgres’. It will ask to type the password two times for confirmation

# \password postgres

If you want to quit from the interactive session of postgres then type ‘\q’.  PostgreSQL is now ready to use.





Leave a Reply

Your email address will not be published. Required fields are marked *