Written by , Updated on April 9, 2021

pgAdmin is an more advance alternative to phppgadmin. It is the most popular and feature rich Open Source administration platform for the PostgreSQL database server. Which is available for Linux, Unix, macOS and Windows operating systems.

pgAdmin 4 is the enhanced version and is a complete rewrite of pgAdmin. Which includes a desktop version written in NWjs as well as a web application can be directly deployed on a web server. The desktop version helps you to access it from local machine, while the web server enables you access from remote system.

In this tutorial, you will learn to install pgAdmin 4 on Ubuntu systems. Also include the steps to add PostgreSQL server to pgAdmin.

Prerequisites

A running Ubuntu 20.04 LTS system.

Assuming you have a pre-installed PostgreSQL server on your system. Otherwise refer to other tutorial which covers both installation of PostgreSQL and pgAdmin on Ubuntu system.

Step 1 – Install pgAdmin4 on Ubuntu

An official PPA is available for pgAdmin4 to install latest version on Ubuntu systems.

First, import the repository signing GPG key and add the pgAdmin4 PPA to your system using the following commands.

curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add -
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list' 

After adding the PPA, update the Apt cache and install pgAdmin4 package on your system.

sudo apt update
sudo apt install pgadmin4 

The pgadmin4 package contains both pgadmin4-web and pgadmin4-desktop versions, Here:

  • pgadmin4-web – Provides the web interface accessible in a web browser
  • pgadmin4-desktop – Provides desktop application for Ubuntu system, which required Ubuntu Desktop system.
  • To install on a remote server (or no desktop available) use “pgadmin4-web” package only. For local system with Desktop installed, can use both versions.

    Step 2 – Configure pgAdmin4-Web

    The users has installed pgadmin4-web or both editions, needs , run the below command to configure it. This will add a login screen to pgAdmin4 web dashboard.

sudo /usr/pgadmin4/bin/setup-web.sh 

The above script will prompt you to create user to access web interface. Input an email address and password when prompted. Say “y” for other confirmation asked by the script.

How to Install pgAdmin4 on Ubuntu 20.04 General Articles pgadmin4 PostgreSQL

Once the script finished, you are good to access pgAdmin web dashboard. It will be available at below address:

Step 3 – Access pgAdmin4 Web

The above commands will also configure pgAdmin4 with Apache web server. You can access pgAdmin4 in a web browser with the following url: http://server_ip/pgadmin4

Make sure to change server_ip with localhost, domain name pointed the system or system ip address.

How to Install pgAdmin4 on Ubuntu 20.04 General Articles pgadmin4 PostgreSQL

In any case the above page is not loading, restart the Apache server using “sudo systemctl restart apache2“. Again try to load above url

Now login with the email address and password configured with /usr/pgadmin4/bin/setup-web.sh script. After successful login to pgAdmin4, you will see the below screen.

How to Install pgAdmin4 on Ubuntu 20.04 General Articles pgadmin4 PostgreSQL

Here you need to add your Postgres server to pgAdmin4. Click on “Add New Server” button. This will open a popup, Enter a friendly name here:

How to Install pgAdmin4 on Ubuntu 20.04 General Articles pgadmin4 PostgreSQL

Switch to connection tab. Enter hostname of the PostgreSQL server. Use “localhost” for running database on same instance. Then input the authentication details.

How to Install pgAdmin4 on Ubuntu 20.04 General Articles pgadmin4 PostgreSQL

Click “Save” to complete the connection.

On successful authentication, you will see the databases in sidebar as shown in below screenshot.

How to Install pgAdmin4 on Ubuntu 20.04 General Articles pgadmin4 PostgreSQL

All done. You have successfully added Postgres database server to pgAdmin4. You can also add more databse instances to single pgAdmin4 server.

Conclusion

This tutorial helped you to install and configure pgAdmin4 on a Ubuntu 20.04 Linux system. Also added a database server running on same host.

Next, you can learn about backup and restore Postgres databases via command line.