How to Install PgAdmin 4 in Debian 9 Stretch?

I have written how to install PostgreSQL 10.1 on debian 9 stretch in my last article. Read the attached link if you want to learn its step by step process. Here, I am going to install pgAdmin 4 on debian 9 stretch that is most popular and feature rich Open Source administration and development tool to manage PostgreSQL databases.

pgadmin4 installation

PostgreSQL is for many the best in its area, and it is not the aim of this article to defend or support that theory, what we can say with all certainty is that it is one of the most robust and secure database handlers that exist. As if this were not enough, it has one of the most popular and complete graphical tools to manage it, such as pgAdmin.

As the project website says: “pgAdmin is the most popular and feature rich Open Source administration and development platform for PostgreSQL, the most advanced Open Source database in the world.” And of course we can install it in our preferred GNU/LINUX distribution. In this case we are going to install it in our Debian 9 Stretch a large GNU/LINUX distribution widely used in the server and database area.

Install pgAdmin 4 on Debian 9 Stretch

Note: In this tutorial it is assumed that you have postgreSQL installed, otherwise, we must install it. You can find the way of doing it in below link.

Let’s get started. The first thing we have to do is add the postgreSQL apt repository. If you have installed postgreSQL with the tutorial we have attached above, you can skip these steps. Otherwise we must add it.

First we logged in as root user. Write su in your terminal screen along with its password and press enter to connect.

#Connect using root user
su

Connect using superuser

Now, use below command to create the pgdp.list file in the /etc/apt/source.list.d/ path.

nano /etc/apt/source.list.d/pgdg.list

Here, we will add the next line of code to the terminal screen that will come after executing above command.

deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main

Enter the given code lines

Press ctrl + x to exit and select yes to save the changes.

Now import the repository signing key by running below commands on your terminal screen.

#Import the repository signing key
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

And to refresh the repository cache, just run the following command.

#Refresh the repository.
apt update

Run apt update to refresh packages

You can see all packages have been updated in above screenshot. Now we are ready to start installing pgAdmin 4.

Installing Dependencies and Creating the Virtual Environment

We must install the necessary dependencies to handle the package. They are basically Python dependencies that needs to be resolved before installing pgadmin package. Execute below command in your terminal before going to install pgadmin.

#Install Python dependency.
apt install virtualenv python-pip libpq-dev python-dev

Install Dependencies

Type Y and press enter to install this dependency. The next step will be to create the virtual environment. In this case we will create it on /home/Your_user/. Run below commands to get this done.

#Go to your directory.
cd /home/your_user/

#Create Virtual Environment.
virtualenv pgadmin4

Run Virtualenv pgadmin4

This creates a folder called “pgadmin4“. We must enter it to get in to this folder.

cd pgadmin4

The next step will be to “activate” the virtual environment by running below statement.

#Activate virtual environment.
source bin/activate
Downloading and Installing pgAdmin

Now, we will install pgadmin on this machine. We can download latest version pgAdmin4-2.1 from this link. For this tutorial we will use the python package that is showing in below screenshot.

Download PgAdmin Package

And finally we will proceed to install pgadmin using pip command as given below.

#Replace <path-where-file-is-located> with your patch followed by file name.
pip install <path-where-file-is-located>

We will be running below command in our case.

#Run below command to install pgadmin.
pip install /home/angelo/Descargas/pgadmin4-2.1-py2.py3-none-any.whl

pip install

With this pgAdmin is already installed but we are not finished yet. You need to create a local configuration and run it. Run below command to do this.

#Go to pgadmin4 folder
cd lib/python2.7/site-packages/pgadmin4

#Create config file
touch config_local.py

The “touch” command creates an empty file from the linux terminal, if the file exists it will change the date and time of the modification. In that file we can place the settings we want, if the file is left empty it will take the global settings of python.

We can now execute below command to create the credentials. Once you run below command, it will ask you to enter your email address and password. Those credentials will be the ones we use to access the application from the browser.

python lib/python2.7/site-packages/pgadmin4/pgAdmin4.pyc

Python settings

Now we have created the credentials as well in above screenshot. At the end, we will be told that we must log in with our favorite browser to 127.0.0.1:5050 to log in and enter the main page of pgAdmin.

running pgadmin

Let’s go to our browser and type 127.0.0.1:5050

Launch pgadmin url

We put our email address and the password we have previously entered. We can also select the language. Once we will be logged in using given credentials, we can see the main pgAdmin panel that is also showing in below screenshot.

PgAdmin Portal

We can test the application by adding a server. In this case it will be a local server. We must click on the “Add new Server” link given in between Quick Link section. We will get below screen to enter details about the server that we want to add.

Add New Server

The name we want to give to the connection is placed in the window. I called it “local.” We’ll leave the rest the same, if we want to.

In the connection tab, we will enter the connection parameters Host name, port, database, username, and password to add the server. You can see this in beow screenshot.

Add Server Connection Details

And with this we already have an added server and we can start working with postgreSQL. You can see the server is added in left side pane of pgAdmin panel. You can expand the plus sign to see the details like databases etc.

Pgadmin panelpost adding server

Conclusion

We have installed pgadmin 4 in debian 9 stretch to manage PostgreSQL databases. Data management is vital to system administration and specialized programs are required to keep data secure and properly structured. Complementing PostgreSQL we have pgAdmin that helps us, with a friendly graphical interface, to manage our databases, to make sentences and to monitor the service.

Installing both is one of the best ways to have and view databases in a way that is appropriate for our applications.

I hope you like this article. Please Like, Share, Comment & Subscribe to this website to get all new articles directly in your inbox. You can also follow our Facebook page and Twitter handle to get latest updates.

Angelo Marquez

I have experience in various Venezuelan governmental and private projects related to Information Technology.Fanatic of free software and Linux in general. Contact me for any query or consulting work using contact us form given on this website.
Angelo Marquez
Summary
Article Name
How to Install pgAdmin in Debian 9 Stretch?
Description
Here, I am going to install pgAdmin 4 on debian 9 stretch that is most popular and feature rich Open Source administration and development tool to manage PostgreSQL databases.

You may also like...

1 Response

  1. vdegenne says:

    hmm.. Thanks but I think there is a million times easier way to install pgadmin4 on debian.

    1) Add `deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main` in /etc/apt/sources.list.d/pgdg.list
    2) `wget –quiet -O – https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -`
    3) `sudo apt-get update`
    4) `apt-get install pgadmin4`
    5) finish

    But I think it was not available as a package at the time this tutorial was written.

Leave a Reply

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