How to Install PgAdmin4 on Ubuntu 18.04 / 20.04 / 22.04

Posted on

How to Install PgAdmin4 on Ubuntu 18.04 / 20.04 / 22.04

How to Install PgAdmin4 on Ubuntu 18.04 / 20.04 / 22.04

PgAdmin4 is an invaluable open-source administration and management tool for PostgreSQL databases. It provides a user-friendly interface for interacting with your PostgreSQL server, allowing you to create, manage, and query databases with ease. This article provides a comprehensive step-by-step guide on how to install PgAdmin4 on Ubuntu 18.04, 20.04, and 22.04.

Step 1: Update your Ubuntu system

Before embarking on the installation process, it’s crucial to update your Ubuntu system. This ensures that you have the latest security patches, bug fixes, and software package information. A system update minimizes potential conflicts and ensures a smoother installation.

To update your Ubuntu system, open a terminal and execute the following command:

$ sudo apt update && sudo apt upgrade -y

This command first updates the package lists (apt update) and then upgrades any outdated packages (apt upgrade -y). The -y flag automatically answers "yes" to any prompts during the upgrade process, streamlining the process.

Step 2: Install PostgreSQL

PgAdmin4 is a dedicated management tool for PostgreSQL, meaning you must have PostgreSQL installed on your Ubuntu system before proceeding. If you haven’t already, you can install PostgreSQL using the following command:

$ sudo apt install postgresql postgresql-contrib -y

This command installs the PostgreSQL server itself (postgresql) along with a collection of useful additional utilities (postgresql-contrib). These utilities can significantly enhance your PostgreSQL experience.

For a more detailed walkthrough of PostgreSQL installation, you can refer to our guide on How to Install PostgreSQL in Ubuntu 18.04/ 20.4/ 22.04.

Step 3: Install PgAdmin4

Now, let’s move on to the core of this guide: installing PgAdmin4. To install the latest version of PgAdmin4, you need to add the official PgAdmin4 repository to your system’s package sources.

First, add the public key for the PgAdmin4 repository. This key verifies the authenticity of the packages you’ll be downloading:

$ sudo curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add

This command downloads the public key using curl and then adds it to your system’s trusted keys using apt-key add.

Next, add the PgAdmin4 repository itself to your system’s sources list. This tells your system where to find the PgAdmin4 packages:

$ echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" | sudo tee /etc/apt/sources.list.d/pgadmin4.list

This command dynamically determines your Ubuntu version using lsb_release -cs and then adds the appropriate repository URL to a new file /etc/apt/sources.list.d/pgadmin4.list. The tee command ensures that the output is both displayed in the terminal and written to the file.

Now, update your system’s package list to include the newly added repository:

$ sudo apt update

Finally, install PgAdmin4 itself:

$ sudo apt install pgadmin4

This command downloads and installs PgAdmin4 along with all its required dependencies.

Step 4: Access PgAdmin4

Once the installation is complete, you can access PgAdmin4 through your web browser. Open your browser and enter the following URL:

http://localhost/pgadmin4

This URL should take you to the PgAdmin4 login page. The default username is ‘[email protected]‘, and the default password is ‘admin’. Enter these credentials and click the "Sign in" button to access the PgAdmin4 web interface.

Important Security Note: Immediately change the default password after your first login. This is a crucial security measure to protect your PostgreSQL server.

Step 5: Configure PgAdmin4

After logging in, you can customize PgAdmin4 to match your preferences. Click on the "File" menu and select "Preferences."

Within the Preferences dialog, you can configure various settings, including:

  • Default Server Group: Organize your servers into logical groups.
  • Default Language: Choose your preferred language for the interface.
  • Default Font Size: Adjust the font size for improved readability.
  • Advanced Settings: Configure SSL certificates, email notifications, and backup options for enhanced security and functionality.

Step 6: Create a Server

To start managing your PostgreSQL databases with PgAdmin4, you need to define a connection to your PostgreSQL server. This is done by creating a "Server" entry.

Click on the "Servers" menu and select "Create Server."

In the "Create – Server" dialog box, you’ll need to provide the following details:

  • General Tab:

    • Name: A descriptive name for your server connection (e.g., "Local PostgreSQL Server").
    • Group: Assign the server to a server group (you can create new groups as needed).
  • Connection Tab:

    • Host name/address: Typically localhost if the server is running on the same machine as PgAdmin4.
    • Port: The PostgreSQL server’s port number (default is 5432).
    • Maintenance database: The database to connect to for maintenance tasks (usually postgres).
    • Username: The PostgreSQL username to connect with (e.g., postgres).
    • Password: The password for the specified username.
    • Save password?: Choose whether to save the password for future connections.

Click the "Save" button to save the server details. You can now connect to your PostgreSQL server through PgAdmin4.

Alternative Solutions for Installing PgAdmin4 on Ubuntu

While the above method outlines the standard approach to installing PgAdmin4, there are alternative methods that can be used depending on your specific needs and preferences.

1. Using Docker

Docker provides a containerized environment for running applications, including PgAdmin4. This approach offers several advantages:

  • Isolation: PgAdmin4 runs in its own container, isolated from the rest of your system, preventing conflicts.
  • Reproducibility: The Docker image encapsulates all the necessary dependencies, ensuring consistent behavior across different environments.
  • Easy Deployment: Deploying PgAdmin4 with Docker is simple and efficient.

Here’s how to install and run PgAdmin4 using Docker:

  1. Install Docker: If you don’t have Docker installed, follow the official Docker documentation for Ubuntu installation.

  2. Pull the PgAdmin4 Docker Image:

    docker pull dpage/pgadmin4
  3. Run the Docker Container:

    docker run -d -p 8080:80 --name pgadmin4 -e 'PGADMIN_DEFAULT_EMAIL=admin@example.com' -e 'PGADMIN_DEFAULT_PASSWORD=admin' dpage/pgadmin4
    • -d: Runs the container in detached mode (in the background).
    • -p 8080:80: Maps port 8080 on your host machine to port 80 inside the container. You can access PgAdmin4 at http://localhost:8080.
    • --name pgadmin4: Assigns a name to the container for easy management.
    • -e 'PGADMIN_DEFAULT_EMAIL=admin@example.com': Sets the default email for PgAdmin4.
    • -e 'PGADMIN_DEFAULT_PASSWORD=admin': Sets the default password for PgAdmin4. Remember to change this password immediately after logging in!

2. Using Snap

Snap is a package management system developed by Canonical (the company behind Ubuntu). It offers a convenient way to install and manage applications.

Here’s how to install PgAdmin4 using Snap:

  1. Install Snapd: If Snapd is not already installed, install it using the following command:

    sudo apt update
    sudo apt install snapd
  2. Install PgAdmin4:

    sudo snap install pgadmin4

    This command installs the PgAdmin4 snap package.

  3. Access PgAdmin4:

    The Snap version might require setting up the web server part manually, check the Snap’s documentation page for the correct way to access it. You can usually find the URL and any specific instructions by looking at the Snap’s information:

    snap info pgadmin4

    The output will provide details about the snap, including how to access the PgAdmin4 web interface.

Choosing the Right Method:

  • APT (the original method): Suitable for users who prefer a traditional installation and want PgAdmin4 integrated directly into their system.
  • Docker: Ideal for isolating PgAdmin4, ensuring reproducibility, and simplifying deployment.
  • Snap: A convenient option for users who prefer using Snap packages and want a simplified installation process.

No matter which method you choose, remember to prioritize security by changing the default password immediately after installation.

Conclusion

This article has outlined the traditional method and alternative methods for how to install PgAdmin4 on Ubuntu 18.04, 20.04, and 22.04. PgAdmin4 provides a powerful and user-friendly interface for managing your PostgreSQL databases. By following the steps outlined in this guide, you can easily install and configure PgAdmin4 to streamline your database administration tasks. Remember to choose the installation method that best suits your needs and preferences. Successfully implementing how to install PgAdmin4 on Ubuntu is the first step towards easier PostgreSQL management. With how to install PgAdmin4 on Ubuntu mastered, you are well on your way to database management success.

Leave a Reply

Your email address will not be published. Required fields are marked *