You are on page 1of 26

 Menu

 Menu 

How to Install PostgreSQL with pgAdmin4 on


Linux Mint 20

Winnie Ondara Last Updated: February 8, 2021 Linux Mint, PostgreSQL 15


Comments

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 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


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

$ sudo systemctl status postgresql

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


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

$ sudo pg_isready

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 20
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

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

$ sudo apt install python3-virtualenv python3-dev libpq-dev

Install Python Virtual Environment

RedHat RHCSA and RHCE Certification Preparation Guide - Get This Book
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


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.

/ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.30/pip/pgadmin4-4.3

Install PgAdmin4 in Linux Mint

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

$ sudo nano pgadmin4env/lib/python3.8/site-packages/pgadmin4/

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


Create PgAdmin4 Configuration

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

$ python pgadmin4env/lib/python3.8/site-packages/pgadmin4/pga
Or
./pgadmin4env/bin/pgadmin4&

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

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

$ echo "alias startPg='~/pgAdmin4/venv/bin/python ~/pgAdmin4/

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

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

 Linux Mint Tips , PgAdmin , PostgreSQL Tips

 How to Install CouchDB on Debian 5 Most Notable Open Source Centralized


10 Log Management Tools 

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you
have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint,


You Should Consider:

TecMint is the fastest growing and most trusted community site


for any kind of Linux Articles, Guides and Books on the web.
Millions of people visit TecMint! to search or browse the
thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a
coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Related Posts


Useful GUI Tools to Free Up Space on Ubuntu and Linux Mint

7 Ways to Speed Up Firefox Browser in Linux Desktop


How to Burn CD/DVD in Linux Using Brasero


Best Tools to Install on Fresh Linux Mint Installation
How to Install KDE Plasma in Linux Desktop


How to Install ONLYOFFICE Desktop Editors in Linux

15 thoughts on “How to Install PostgreSQL


with pgAdmin4 on Linux Mint 20”

Thomas Tschoepke
December 2, 2021 at 12:23 am

This tutorial does not work anymore… Back to version 3 :-(

Reply

Thomas Tschoepke
December 2, 2021 at 12:32 am


$ sudo 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 && apt
update'
$ sudo apt update
$ sudo apt install pgadmin4-desktop #for desktop
OR
$ sudo apt install pgadmin4-web #for web

If web version:

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

Reply

Ami
February 27, 2022 at 7:29 am

With these steps I get:

E: The repository
'https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal
pgadmin4 Release' does not have a Release file.
E: The repository 'http://apt.postgresql.org/pub/repos/apt
ulyssa-pgdg Release' does not have a Release file.

Reply


Ravi Saive
December 2, 2021 at 11:26 am

@Thomas,

I have tried it on my Linux Mint 20, and it worked well. What error are you
getting on your side?

Reply

Thomas Tschoepke
December 3, 2021 at 4:35 pm

Can’t remember the error. But with the steps, I posted above one does
not need virtual environments and stuff…

The install is straight forward as any other package.

Reply

Jesus Reina
August 17, 2021 at 9:24 pm

pgadmin4env) root@usuario-Intel-powered-classmate-PC:~/pgadmin4#
python pgadmin4env/lib/python3.8/site-packages/pgadmin4/pgAdmin4.py
NOTE: Configuring authentication for DESKTOP mode.
Traceback (most recent call last):
File “/root/pgadmin4/pgadmin4env/lib/python3.8/site- 
packages/sqlalchemy/engine/base.py”, line 1771, in _execute_context
self.dialect.do_execute(
File “/root/pgadmin4/pgadmin4env/lib/python3.8/site-
packages/sqlalchemy/engine/default.py”, line 717, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: table version already exists

Reply

Aga
June 20, 2021 at 12:28 am

Got the same issue, does anyone know how to uninstall all of this?

Reply

Agung Setiawan
June 9, 2021 at 12:19 am

Same issue

Reply

Uğur Volkan Göl


June 7, 2021 at 4:46 pm

Same issue for me too 


Reply

sven
February 8, 2021 at 1:20 am

Step 11: The package is no longer available, currently you can use Version
4.30:
pip install
https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.30/pip/pgadmin4-4.30-
py3-none-any.whl

Step 13: Meanwhile in Version 4.30 there is a binary to start the server:
./pgadmin4env/bin/pgadmin4&

Reply

Ravi Saive
February 8, 2021 at 10:21 am

@Sven,

Thanks, corrected in the article as suggested by you…

Reply

LJ
April 6, 2021 at 9:35 am


Can I ask that want version of python you used, because I got error like
this:

(pgadmin4env) lj@lj-Aspire-V3-471G:~/pgadmin4$ ./pgadmin4env/bin/


[1] 38587
(pgadmin4env) lj@lj-Aspire-V3-471G:~/pgadmin4$ NOTE: Configuring
Traceback (most recent call last):
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
line 1705, in _execute_context
self.dialect.do_execute(
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
line 691, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: table version already exists

The above exception was the direct cause of the following exception:

Traceback (most recent call last):


File "./pgadmin4env/bin/pgadmin4", line 5, in
from pgadmin4.pgAdmin4 import main
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/pga
app = create_app()
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/pga
db_upgrade(app)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/pga
flask_migrate.upgrade(migration_folder)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/flas
f(*args, **kwargs)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/flas
command.upgrade(config, revision, sql=sql, tag=tag)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
script.run_env()
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
util.load_python_file(self.dir, "env.py")
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
module = load_module_py(module_id, path)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
spec.loader.exec_module(module)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/pga
run_migrations_online()
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/pga
context.run_migrations()
File "", line 8, in run_migrations
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
self.get_context().run_migrations(**kw)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
step.migration_fn(**kw)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/pga
op.create_table('version',
File "", line 8, in create_table
File "", line 3, in create_table
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
return operations.invoke(op)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
return fn(self, operation)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
operations.impl.create_table(table)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
self._exec(schema.CreateTable(table))
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/ale
return conn.execute(construct, multiparams)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
return connection._execute_ddl(
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
ret = self._execute_context(
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
self._handle_dbapi_exception(
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
util.raise_(
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
raise exception
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
self.dialect.do_execute(
File "/home/lj/pgadmin4/pgadmin4env/lib/python3.8/site-packages/sql
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table versio
[SQL:
CREATE TABLE version (
name VARCHAR(32) NOT NULL,
value INTEGER NOT NULL,
PRIMARY KEY (name)
)

]
(Background on this error at: http://sqlalche.me/e/14/e3q8)
^C
[1]+ Exit 1 ./pgadmin4env/bin/pgadmin4

Reply

Danny Hamshananth
April 16, 2021 at 12:07 pm

Hi LJ,

Got the same error as yours…

Tried to fix it by myself. But it didn’t worked.

My Linux Mint is 20.1 Ulyssa and the Python version is 3.8.5 (The
default one available with the OS).

I was managed to install and connect Postgres with Ravi Saive’s


guidelines (Author of this article).

But, I managed to connect PGAdmin3 (the version currently available in


Mint’s Software Manager) with the Postgres server.

But with one change..

1) Login to Server as Super User – sudo -u postgres psql postgres

2) Reset the super user’s password using – postgres=# ALTER USER


postgres PASSWORD 'root';

(https://stackoverflow.com/questions/7695962/postgresql-password-
authentication-failed-for-user-postgres)

Please share if you find out a solution for PGAdmin4

Reply


Ahmad
May 11, 2021 at 3:04 am

I have the same issue…

Reply

Aditya Saxena
June 6, 2021 at 2:00 pm

Same issue for me too

Got something to say? Join the discussion.


Have a question or suggestion? Please leave a comment to start the discussion.
Please keep in mind that all comments are moderated and your email address will
NOT be published.

Name *

Email *

Save my name, email, and website in this browser for the next time I comment.

Notify me of followup comments via e-mail. You can also subscribe without
commenting.

Post Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Over 3,500,000+ Readers

A Beginners Guide To Learn Linux for Free [with Examples]

Red Hat RHCSA/RHCE 8 Certification Study Guide [eBooks]

Linux Foundation LFCS and LFCE Certification Study Guide [eBooks]

Learn Linux Commands and Tools 


How to Install and Use dig and nslookup Commands in Linux

Mhddfs – Combine Several Smaller Partition into One Large Virtual Storage

How to Run or Repeat a Linux Command Every X Seconds Forever

12 Useful “df” Commands to Check Disk Space in Linux

10 Linux Dig (Domain Information Groper) Commands to Query DNS

How to Delete HUGE (100-200GB) Files in Linux

If You Appreciate What We Do Here On TecMint, You Should Consider:


Linux Server Monitoring Tools

bmon – A Powerful Network Bandwidth Monitoring and Debugging Tool for


Linux

Bandwhich – A Network Bandwidth Utilization Tool for Linux

How to Install Cacti with Cacti-Spine in Debian and Ubuntu

linux-dash: Monitors “Linux Server Performance” Remotely Using Web


Browser

How to Setup Central Logging Server with Rsyslog in Linux

Install Munin (Network Monitoring) in RHEL, CentOS and Fedora

Learn Linux Tricks & Tips

10 Useful Sudoers Configurations for Setting ‘sudo’ in Linux

How to Test Website Loading Speed in Linux Terminal

Learn The Basics of How Linux I/O (Input/Output) Redirection Works

How to Configure Custom SSH Connections to Simplify Remote Access

How to Record and Replay Linux Terminal Sessions using ‘script’ and
‘scriptreplay’ Commands

Display Command Output or File Contents in Column Format

Best Linux Tools

The 8 Best Open Source Web Servers

4 Open Source Log Monitoring and Management Tools for Linux

9 Best File Comparison and Difference (Diff) Tools for Linux



13 Most Used Microsoft Office Alternatives for Linux
10 Useful Tools to Create Bootable USB from an ISO Image

Top 3 Open-Source Cross-Distribution Package Management Systems for


Linux

Donate to TecMint Contact Us Advertise on TecMint Linux Services Copyright Policy

Privacy Policy Career Sponsored Post

Tecmint: Linux Howtos, Tutorials & Guides © 2022. All Rights Reserved.
The material in this site cannot be republished either online or offline, without our permission.

Hosting Sponsored by : Linode Cloud Hosting

You might also like