Ubuntu

How to Install pgAdmin in Ubuntu 22.04?

How to Install pgAdmin in Ubuntu 22.04 copy

pgAdmin is the widely used and most popular GUI-based management Tool for PostgreSQL. “pgAdmin” is an advanced open-source tool that offers a better Graphical User Interface, and a simplified schema, and it also simplifies the use and creation of Database Objects. “pgAdmin” interacts with the PostgreSQL determined to Develop, Test and Maintain Databases.

This article explains how you can install “pgAdmin” in Ubuntu 22.04.

How to Install pgAdmin in Ubuntu 22.04?

pgAdmin is Installed from the pgAdmin Repository. While installing pgAdmin, you can either install both the web mode and desktop mode together, which the “apt install pgadmin4” command does by default, or you can install pgAdmin Web Mode and pgAdmin Desktop Mode individually as well. Below are the steps that demonstrate how you can install pgAdmin in your Ubuntu System.

Step 1: Update Packages

Before installing “pgAdmin”, update the existing Ubuntu Repository to look for any packages that require upgrades. Use the “apt update” command with sudo privileges:

sudo apt update

Enter the sudo user password to look for updates in the packages:

Once the Terminal completes updating, upgrade your Ubuntu Repository now with the “upgrade” command. Use the “apt upgrade” command with sudo privileges to upgrade any packages that require to be upgraded to the latest version:

sudo apt upgrade

Enter “Y” during the upgradation to continue the process:

Step 2: Install “curl”

Once the existing packages are updated, install “curl” before you download “pgAdmin”. The “curl” command downloads any packages from a server. With curl, not only can you Download packages, but you can also use it to transfer data to a server and retrieve data from a server. In most Ubuntu Systems, curl is pre-installed. If your system is missing curl, use the “apt install” command to install curl:

sudo apt install curl

In our case, it was already installed:

Step 3: Download “pgAdmin”

Now once “curl” is installed, Open any Web Browser to download “pgAdmin”. In our case, we opened the Firefox Browser:

“pgAdmin” should be downloaded from the official “pgAdmin” Website. Either search for the “pgAdmin” website or Download pgAdmin directly by visiting the web page.

On the official web page of “pgAdmin”, click on the Download option in the Navigation Bar:

The Download page will appear which will consist of Operating System Options for “pgAdmin” packages. As you are using Ubuntu, click on the “APT” option for the “pgAdmin 4”:

The various Ubuntu Versions that are available for the pgAdmin APT Repository will be listed. Choose the APT repository for Ubuntu 22.04 Version:

Scroll Down and you will see the “pgAdmin” repository setup commands for Ubuntu:

Download the Public Key for the “pgAdmin” Repository using the “curl” command:

curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg

The cursor moves to the next line in the Terminal indicating the Public Key was added:

Now, Set up the Repository for the “pgAdmin” Configuration File using the command:

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'

The repository will be added to the Configuration File:

Step 4: Install “pgAdmin”

Once the Public Key and the Packages are added to the Configuration File, install “pgAdmin” with the “apt install” command:

sudo apt install pgadmin4

The Terminal will start installing the packages, and wait for the installation process to complete:

Step 5: Configure Web Interface

After the packages are added and “pgAdmin” is installed, you have to configure the “pgAdmin” interface to start working with it. The first step in the configuration includes setting up the “pgAdmin 4” for web mode and then configuring the “pgAdmin” user account. Run the “setup-web.sh” script which will set up the pgAdmin 4 in Web Mode with the “sudo” command:

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

Once the Web Mode Configuration for “pgAdmin” is completed, the Terminal will ask for the initial “pgAdmin” user account details:

Enter the email and password for the initial “pgAdmin 4” user:

Once you Retype the password and hit “Enter”, the “pgAdmin” application will ask for the Apache Web Server configuration and mount the “pgAdmin 4” at “/pgadmin4”:

Enter “y” to continue configuring Apache Server and mounting the pgAdmin Application. As soon as the Apache Server is Configured, it will ask for the Server Restart. Enter “y” again to complete the pgAdmin installation. After the Apache Server restarts, the Terminal will show the local host URL where you can use the “pgAdmin 4” Application:

Starting pgAdmin in Web Mode

You can use the pgAdmin application once it is initialized. Once you’ve installed and configured pgAdmin, the Terminal displays the local host link which can be used in the URL of a browser to access pgAdmin. Usually, the pgAdmin Web Application runs on the “127.0.0.1/pgadmin4” URL:

Clicking on the URL will redirect you to the Web page on the Default Web Browser and open the pgAdmin Web Page:

In the Email and Password Input boxes, enter the email and password of the user that you created while configuring the pgAdmin Web Mode in the Terminal:

Once the email and password are entered, click on the Login button to access the pgAdmin Account:

Wait for the pgAdmin User Page to load:

The pgAdmin User Account Dashboard will open where you can Add a New Server, Configure Your Account, and do much more:

This is one way of starting the pgAdmin Application through Web Mode.

Starting pgAdmin in Desktop Mode

The pgAdmin Application can also be used as an Ubuntu Application on the Desktop instead of using the Web browser and then accessing the pgAdmin through the URL. While installing the pgAdmin Application through the Repository, both the Desktop and the Web Mode for the pgAdmin Application are installed.

If the pgAdmin Desktop Mode is not installed on your Ubuntu System, use the “apt install” command to install pgAdmin:

sudo apt install pgadmin4-desktop

The “pgAdmin4-desktop” command only installs the Desktop Version of pgAdmin. Once installed, open the Applications Menu from your Ubuntu Home Screen:

In the Applications Menu, click on the Search Bar to type the Application you want to search:

As we want to open pgAdmin, type pgAdmin in the Search Box. The pgAdmin Application icon will appear. Click on the application icon to start the application:

Wait for the application to initialize:

Once the pgAdmin Application starts, you will see the pgAdmin Home Screen where you can add a New Server and make changes to your pgAdmin account as well:

Registering a Server in “pgAdmin”

A new Server can be added to the pgAdmin Application. To Register a New Server, right-click on the Servers option in the left panel of the Application:

A drop-down menu will appear where you can register, create, refresh, and remove server groups. Click on the Register to expand it. In the additional expanded Register Option, click on the “Server” to Register your own Server:

The Server Registration Menu will appear:

Enter the Name of your Server in the “Name” Field:

In our case, we added the name “localhost”. Once you have added the name click on the Connection option from the Menu Options:

Now in the Connection Menu, the Port, maintenance Database, and username are pre-added. Add the Host Name only if you want to continue with the custom default settings:

Once the Hostname, username, and password are added for the new Server, click on the “Save” button:

The connections will be made successfully. If the connection fails, you have to set a password for your Postgres account as during the Creation of the Postgres Account, the password is not required:

To set the password for the User, Switch to the Postgres User with the command:

sudo -i -u <userName>

In our case, the user name is “darren”. Thus, to switch to the “darren” Postgres User, the “sudo” command will be:

sudo -i -u darren

This will change the Command line to the Postgres Account for darren:

Now, you have to Access the PostgreSQL Prompt with the following command:

psql

Once you have accessed the User PostgreSQL Prompt, you can run commands and queries. The “=#” indicates the PostgreSQL Prompt is currently being used:

You can now set the password for the Postgres User with the command “password” followed by the username of the User:

\password <<strong>userName</strong>>

In our case, the user is “darren”. Thus to set the password for “darren”, the command will be:

\password darren

The Command Line will ask you to Enter the New Password and then Retype the Password for confirmation:

Once the Password is set for the User “darren”, open the pgAdmin Connection Menu again and retype the new password. Click on the “Save” button as soon as you are done with the configuration:

After the connection is set, you will see the server activity on the pgAdmin Dashboard:

Moreover, you can expand the Servers and look for the “localhost” server that you created earlier:

Expanding the “localhost” server will list the options for Databases, Tablespaces, and User Roles:

At this point, you are all set to use pgAdmin to perform any specific Postgres tasks.

Conclusion

pgAdmin can be installed with the “apt install pgadmin4” command, but before the installation, the Public Key should be added and the configuration file for the pgAdmin Repository should be set up. Once pgAdmin is installed, we can either use the Web Mode or the Desktop Mode. Each step is discussed in detail in this article.

Similar Posts