Installing PgAdmin4 on Ubuntu using specific port 5050

PgAdmin 4 Installation Steps

1. Update the system

Before starting the installation process, you have to update the system by executing the following command.

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

When the following prompt appears then press ‘y’ to complete the installation process of the required packages.

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 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v2.1/pip/pgadmin4-
2.1-py2.py3-none-any.whl

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

After installation, the following screen will appear.

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 config_local.py in lib/python2.7/site-packages/pgadmin4/ folder using nano editor.

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

Add the following content in config_local.py.

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’)
SERVER_MODE = False

Now, use the following command to run pgAdmin.

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

***Note: If any flask-htmlmin module error appears then run the following commands to install the module and then run the server.

$ pip install flask-htmlmin
$ python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py

The following message will appear if pgAdmin can run successfully.

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

Using pgAdmin 4

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

Type ‘y’ when the following message appear in the terminal to complete the installation process.

Source: Install PgAdmin4 on Ubuntu

Option: Installing PgAdmin4 with Apache2

https://computingforgeeks.com/how-to-install-pgadmin-4-on-ubuntu/