Menu

How to Install PostgreSQL on Ubuntu 22.04 LTS

Install PostgreSQL on Ubuntu 22.04 LTS from Ubuntu’s repository or install PostgreSQL 18 from the official PostgreSQL APT repository, then verify the service and connect with psql.

Posted on By Updated on
On this page

Ubuntu 22.04 LTS includes PostgreSQL packages in its own APT repository. If you want to choose a specific PostgreSQL major version, the PostgreSQL project also maintains an APT repository for Ubuntu 22.04 (jammy). This guide shows both options and uses PostgreSQL 18 as the versioned example.

For Ubuntu 24.04, see our PostgreSQL installation guide for Ubuntu 24.04. For a new server on Ubuntu 26.04 LTS, see the Ubuntu 26.04 guide.

Support status: Ubuntu lists standard security maintenance for Ubuntu 22.04 LTS through May 2027. Check Ubuntu’s security maintenance schedule for current coverage.

Operating-system support does not extend a PostgreSQL major version’s support period. PostgreSQL 14 stops receiving updates on November 12, 2026; if this Ubuntu server runs PostgreSQL 14, plan a major upgrade and see our PostgreSQL 14 to 18 upgrade guide.

Prerequisites

  • An Ubuntu 22.04 LTS system with internet access.
  • A user account with sudo privileges.
  • A terminal and basic familiarity with Linux commands.

Install PostgreSQL from Ubuntu’s Repository

Ubuntu selects and maintains a PostgreSQL major version for each release. Choose this method if that version meets your needs:

sudo apt update
sudo apt install postgresql

Install PostgreSQL 18 from the PostgreSQL APT Repository

Use the PostgreSQL project’s APT repository when you need a specific supported major version. The repository lists Ubuntu 22.04 (jammy) as supported and provides the versioned postgresql-18 package. Follow the official PostgreSQL Ubuntu installation instructions.

Install the repository configuration package and run its setup script:

sudo apt update
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

Then install PostgreSQL 18:

sudo apt update
sudo apt install postgresql-18

The versioned package follows major version 18 and receives package updates within that major version. See the PostgreSQL APT repository documentation for repository details.

Verify the Installation

Check that the PostgreSQL service is running and query the server version:

sudo systemctl status postgresql --no-pager
sudo -u postgres psql -c 'SELECT version();'

Open the PostgreSQL prompt as the administrative postgres account:

sudo -u postgres psql

At the psql prompt, run a query and exit:

SELECT current_database(), current_user;
\q

Manage the PostgreSQL Service

Use systemctl to manage the service:

sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
sudo systemctl status postgresql --no-pager

To start PostgreSQL automatically at boot, run:

sudo systemctl enable postgresql

Conclusion

Install Ubuntu’s PostgreSQL package when you want the version maintained for Ubuntu 22.04, or use the official PostgreSQL APT repository to install a specific major version such as PostgreSQL 18. Verify the service and connect with psql after installation.

For more database tutorials, see our PostgreSQL tutorials and PostgreSQL Reference.