How to Install PostgreSQL with pgAdmin4 on Linux Mint 21/20

pgAdmin is an open-source feature-rich, frontend management tool that allows you to easily administer and manage your PostgreSQL relational database from a web browser.

It provides an easy-to-use user interface that simplifies the creation and monitoring of databases and database objects. PgAdmin 4 is an improvement of the earlier pgAdmin tool and is available for Linux, Windows, macOS systems, and even a Docker container.

In this tutorial, you will learn how to install PostgreSQL with pgAdmin4 on Linux Mint 21 and Linux Mint 20.

Step 1: Install PostgreSQL Database on Linux Mint

1. To start off, launch your terminal and update your packages using the apt package manager as shown.

$ sudo apt update -y

Once the update is complete, proceed to the next step.

Since pgAdmin4 provides a frontend interface for the management of PostgreSQL database objects, it’s essential to have PostgreSQL installed first.

2. To do this, we are going to install the postgresql package and postgresql-contrib which offers extended features that extend the functionality of PostgreSQL.

$ sudo apt install postgresql postgresql-contrib
Install PostgreSQL on Linux Mint
Install PostgreSQL on Linux Mint

3. Usually, PostgreSQL starts automatically on boot up. You can confirm this using the command given below:

$ sudo systemctl status postgresql
Check PostgreSQL Status
Check PostgreSQL Status

4. To log in to your PostgreSQL instance, first switch to the postgres user. The Postgres user comes included by default with the installation of PostgreSQL. Then run the psql command as shown.

$ sudo -i -u postgres
$ psql
# \q
Connect to PostgreSQL Shell
Connect to PostgreSQL Shell

5. Additionally, you can check if the database server is accepting incoming connections as shown.

$ sudo pg_isready
Check PostgreSQL Accepting Incoming Connections
Check PostgreSQL Accepting Incoming Connections

Step 2: Install pgAdmin4 on Linux Mint

pgAdmin4 is available for Ubuntu 16.04 and later versions and can easily be installed using the APT package manager. The same cannot support Linux Mint and Pgadmi4 developers are yet to include support that allows users to easily install the frontend management tool using the APT package manager.

6. The only viable option is to install pgAdmin4 from a virtual environment. So first, we will install the prerequisite packages as shown.

$ sudo apt install libgmp3-dev build-essential libssl-dev
Install Prerequisite Packages
Install Prerequisite Packages

7. Next, install the Python virtual environment and associated dependencies.

$ sudo apt install python3-virtualenv python3-dev libpq-dev
Install Python Virtual Environment
Install Python Virtual Environment

8. Next, create a directory where you will create a virtual environment.

$ mkdir pgadmin4 && cd pgadmin4

9. Then create the virtual environment as shown. Here, pgadmin4env is the name of the virtual environment.

$ virtualenv pgadmin4env
Create Virtual Environment for pgAdmim4
Create Virtual Environment for pgAdmim4

10. Once the virtual environment is in place, activate it as shown.

$ source pgadmin4env/bin/activate

11. Then use the pip tool to install pgadmin4 as shown.

$ pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v7.5/pip/pgadmin4-7.5-py3-none-any.whl
Install PgAdmin4 in Linux Mint
Install PgAdmin4 in Linux Mint

12. Next, create a configuration file config_local.py.

-------- On Linux Mint 20 --------
$ sudo nano pgadmin4env/lib/python3.8/site-packages/pgadmin4/config_local.py

-------- On Linux Mint 21 --------
$ sudo nano pgadmin4env/lib/python3.10/site-packages/pgadmin4/config_local.py

and add the lines below.

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
AZURE_CREDENTIAL_CACHE_DIR = os.path.join(DATA_DIR, 'azurecredentialcache')
Create PgAdmin4 Configuration
Create PgAdmin4 Configuration

13. To start the pgAdmin4 management tool, invoke the command:

-------- On Linux Mint 20 -------- 
$ python pgadmin4env/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py

-------- On Linux Mint 21 --------
$ python pgadmin4env/lib/python3.10/site-packages/pgadmin4/pgAdmin4.py
Start PgAdmin4 Service
Start PgAdmin4 Service

14. Finally, head over to your browser and browse the address shown.

http://127.0.0.1:5050

You will be prompted to set the master password, so proceed and set a strong password and click the ‘Ok’ button.

Set PgAdmin4 Password
Set PgAdmin4 Password

15. To make things easier, you can create an alias in the ~/.bashrc file as shown.

-------- On Linux Mint 20 -------- 
$ echo "alias startPg='~/pgadmin4/pgadmin4env/bin/python pgadmin4env/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py'" >> ~/.bashrc

-------- On Linux Mint 21 -------- 
$ echo "alias startPg='~/pgadmin4/pgadmin4env/bin/python pgadmin4env/lib/python3.10/site-packages/pgadmin4/pgAdmin4.py'" >> ~/.bashrc

16. Next, update the bashrc file.

$ source ~/.bashrc

17. Finally, you can start the pgAdmin4 management tool by simply invoking the startPg command.

$ startPg &
Start PgAdmin4 Tool
Start PgAdmin4 Tool

Once again head over to your browser and log in to the PgAdmin4 interface. And this concludes the installation of PostgreSQL with pgAdmin4 on Linux Mint 21 and Linux Mint 20.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Winnie Ondara
My name is Winnie, a Linux enthusiast and passionate tech writer in Linux and DevOPs topics. I enjoy keeping abreast with the latest technologies in the Linux ecosystem and trying out new tools provided by the FOSS community.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

43 thoughts on “How to Install PostgreSQL with pgAdmin4 on Linux Mint 21/20”

  1. Step 11 seems like a dead link

    # pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4-6.15-py3-none-any.whl
    

    Please help…

    Reply
  2. Step 15 in Linux Mint 21 should be:

    $ echo "alias startPg='python pgadmin4env/lib/python3.10/site-packages/pgadmin4/pgAdmin4.py'" >> ~/.bashrc
    
    Reply
    • @Frank,

      Here are the instructions to uninstall PostgreSQL with pgAdmin4 on the Linux Mint system.

      $ sudo apt purge postgresql postgresql-contrib
      $ sudo apt purge libgmp3-dev build-essential libssl-dev
      $ sudo apt purge python3-virtualenv python3-dev libpq-dev
      $ rm -rf pgadmin4
      $ pip uninstall pgadmin4
      
      Reply
    • @Franco,

      To install PostgreSQL 15 on Linux Mint, then follow these instructions:

      $ sudo apt install curl ca-certificates gnupg
      $ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null
      $ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
      $ sudo apt update
      $ sudo apt install postgresql-15
      
      Reply
  3. Thank you very much brother, I was able to install it up to point 14, the rest was no longer necessary.

    Remember to check the paths of the requests so that pgadmin4 runs.

    Reply
  4. Hey!

    I’ve followed this guide, but step 13 does not work for some reason. I get this as an error message:

    FileNotFoundError: [Errno 2] No such file or directory: ‘/home/*myname*/pgadmin/*~/.pgadmin’

    What can I do?

    Reply
  5. FTP server not functioning:

    # pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4
    
    ERROR: HTTP error 404 while getting https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4
      ERROR: Could not install requirement https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4 
    because of error 404 Client Error: Not Found for url: https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4
    ERROR: Could not install requirement https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4 
    because of HTTP error 404 Client Error: Not Found for url: https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4 
    for URL https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/pip/pgadmin4
    
    Reply
  6. Hi,

    I’ve performed as described in this article. Start PgAdmin in the terminal first, then in the browser. And in the browser, I see the empty tree of Servers in the left tab.
    (Installed on Mint 21)

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.