How to install PostgreSQL and PGAdmin on Ubuntu 22.04
- 01:08 lsb_release -a
- 01:28 sudo apt update
- 01:51 sudo apt install curl ca-certificates
- 02:18 sudo install -d /usr/share/postgresql-common/pgdg
- 02:56 sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
- 03:07 sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgd
- 03:30 sudo apt -y install postgresql
- 04:24 curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg
- 04:36 sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/
- 04:46 sudo apt install pgadmin4
- 07:52 sudo -u postgres psql
- 08:02 alter user postgres with password '123456';
- 08:32 quit
To Install PostgreSQL And PGAdmin On Ubuntu 22.04
Introduction
PgAdmin is a widely-used open source platform designed specifically for PostgreSQL, offering intuitive graphical user interface administration tools for effectively managing relational databases. Key features include a query tool for executing SQL statements and importing/exporting csv files. PgAdmin utilizes your preferred web browser to provide a user-friendly interface, allowing for easy access to local servers without internet connectivity. A master password is required each time PgAdmin is opened to ensure secure access. It is recommended to keep default settings when installing PostgreSQL to avoid any complications. Please remember that forgetting your password may result in losing access to your PostgreSQL server.
Procedure
Step 1: Check the OS-version by using the below command
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
Step 2: Update the system using the below command
root@linuxhelp:~# sudo apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [129 kB]
Hit:4 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:5 http://in.archive.ubuntu.com/ubuntu jammy-updates/main i386 Packages [666 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1,853 kB]
Get:7 http://security.ubuntu.com/ubuntu jammy-security/main i386 Packages [509 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu jammy-updates/main Translation-en [334 kB]
Fetched 13.2 MB in 4s (2,973 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
339 packages can be upgraded. Run 'apt list --upgradable' to see them.
Step 3: Install the curl ca-certificates using the below command
root@linuxhelp:~# sudo apt install curl ca-certificates
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be upgraded:
curl libcurl4
2 upgraded, 0 newly installed, 0 to remove and 337 not upgraded.
Need to get 0 B/484 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 203969 files and directories currently installed.)
Setting up libcurl4:amd64 (7.81.0-1ubuntu1.16) ...
Setting up curl (7.81.0-1ubuntu1.16) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Step 4: Install the postgresql-common/pgdg using the below command
root@linuxhelp:~# sudo install -d /usr/share/postgresql-common/pgdg
root@linuxhelp:~#
Step 5: Copy the scripts and run it
root@linuxhelp:~# sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4812 100 4812 0 0 5982 0 --:--:-- --:--:-- --:--:-- 5977
Step 6: Add the repo to the source list file and update the repository
root@linuxhelp:~# sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
root@linuxhelp:~#
Step 7: Install the postgresql package
root@linuxhelp:~# sudo apt -y install postgresql
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libflashrom1 libftdi1-2 libllvm13
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5 libtypes-serialiser-perl postgresql-14
postgresql-client-14 postgresql-client-common postgresql-common sysstat
Suggested packages:
postgresql-doc postgresql-doc-14 isag
The following NEW packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5 libtypes-serialiser-perl postgresql
postgresql-14 postgresql-client-14 postgresql-client-common postgresql-common sysstat
0 upgraded, 12 newly installed, 0 to remove and 337 not upgraded.
Need to get 42.4 MB of archives.
update-alternatives: using /usr/share/postgresql/14/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmas
ter.1.gz (postmaster.1.gz) in auto mode
Setting up postgresql (14+238) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Step 8: To install the public key for the repository ,copy the following command and run it.
root@linuxhelp:~# curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg
root@linuxhelp:~#
Step 9: Create the repository configuration file using the below command
root@linuxhelp:~# sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:5 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/jammy pgadmin4 InRelease [4,217 B]
Get:6 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/jammy pgadmin4/main all Packages [3,104 B]
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
343 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://apt.postgresql.org/pub/repos/apt jammy-pgdg InRelease' doesn't support architecture 'i386'
Step 10: Install pgAdmin by using the below command
root@linuxhelp:~# sudo apt install pgadmin4
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libflashrom1 libftdi1-2 libllvm13
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapache2-mod-wsgi-py3 libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap pgadmin4-desktop pgadmin4-server pgadmin4-web
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom
Need to get 220 MB of archives.
After this operation, 8,028 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libapr1 amd64 1.7.0-8ubuntu0.22.04.1 [108 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libaprutil1 amd64 1.6.1-5ubuntu4.22.04.2 [92.8 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-5ubuntu4.22.04.2 [11.3 kB]
Setting up libaprutil1:amd64 (1.6.1-5ubuntu4.22.04.2) ...
Enabling module env.
Enabling module mime.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service →
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Step 11 : Switch to the postgresql user using the below command
root@linuxhelp:~# sudo -u postgres psql
could not change directory to "/root": Permission denied
psql (14.12 (Ubuntu 14.12-0ubuntu0.22.04.1))
Step 12: Alter the postgresql password using the below command
postgres=# alter user postgres with password '123456';
ALTER ROLE
Step 13: Exit from the postgresql user using the below command
postgres=# quit
root@linuxhelp:~#
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to installation of PostgreSQL and PgAdmin on Ubuntu 22.04. Your feedback is much welcome.
Comments ( 0 )
No comments available