How to Install PostgreSQL on Ubuntu 24.04 LTS
Install Ubuntu’s PostgreSQL 16 package or PostgreSQL 18 from PostgreSQL’s official APT repository on Ubuntu 24.04 LTS, then verify the server.
On this page
Ubuntu 24.04 LTS (Noble Numbat) includes PostgreSQL in its APT repository. The postgresql metapackage installs the major version selected for this Ubuntu release, currently PostgreSQL 16. If you need a specific version such as PostgreSQL 18, the PostgreSQL project’s APT repository supports Ubuntu 24.04. See the official Ubuntu release list and PostgreSQL’s Ubuntu installation instructions.
If PostgreSQL is already installed and contains data, make a verified backup before installing another major version. A new package does not upgrade an existing database cluster; follow PostgreSQL’s major version upgrade instructions when moving existing data.
Prerequisites
- Ubuntu 24.04 LTS with internet access.
- A user account with
sudoprivileges. - A terminal and basic familiarity with Linux commands.
Install PostgreSQL 16 from Ubuntu’s Repository
Ubuntu’s postgresql package installs the major version selected and maintained for Ubuntu 24.04. Check the package candidate, then install it:
sudo apt update
apt-cache policy postgresql
sudo apt install postgresql
On Ubuntu 24.04, the postgresql metapackage depends on PostgreSQL 16. Ubuntu publishes maintenance updates for that major version during the release’s support lifetime.
Install PostgreSQL 18 from the PostgreSQL APT Repository
Use the PostgreSQL project’s repository when you need to choose a specific major version. The official instructions list Ubuntu 24.04 (noble) as supported and provide the postgresql-18 package. For LTS releases, the repository supports amd64, arm64, and ppc64el architectures.
Install the repository setup package and run its configuration script:
sudo apt update
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
Refresh APT’s package index and check that PostgreSQL 18 is available:
sudo apt update
apt-cache policy postgresql-18
The candidate should come from the PostgreSQL APT repository. Install the versioned server package:
sudo apt install postgresql-18
The versioned package keeps the server on major version 18 while receiving package updates within that major version. See the project’s Ubuntu installation instructions for supported versions and repository setup details.
Verify the Installation
Check the client version and service status:
psql --version
sudo systemctl status postgresql --no-pager
Ask the server for its version:
sudo -u postgres psql -c 'SELECT version();'
Create an Application Role and Database
Open an interactive session as PostgreSQL’s administrative postgres account:
sudo -u postgres psql
Create a login role, set its password with \password so it is not written in the SQL command or shell history, and create a database owned by that role:
CREATE ROLE app_user LOGIN;
\password app_user
CREATE DATABASE appdb OWNER app_user;
\q
Connect as the application role and verify the database and user:
psql -h localhost -U app_user -d appdb -W
At the psql prompt, run:
SELECT current_database(), current_user;
The -W option prompts for the role password. Keep the database bound to local access unless remote clients need to connect; configure authentication and firewall rules for the intended hosts before opening network access.
Manage the PostgreSQL Service
Use systemctl to manage PostgreSQL:
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
sudo systemctl status postgresql --no-pager
Troubleshooting
- If
psqlcannot connect, checksudo systemctl status postgresqland review recent service logs withsudo journalctl -u postgresql -e --no-pager. - Ubuntu can run multiple PostgreSQL clusters or major versions. Use
pg_lsclustersto see the installed clusters, versions, ports, and status; connect to the intended cluster and port. - If
apt-cache policy postgresql-18has no candidate after running the setup script, runsudo apt updateand confirm the PGDG source uses thenoble-pgdgsuite.
Conclusion
Ubuntu’s postgresql package installs the version maintained for Ubuntu 24.04. If you need to select a specific major version, PGDG’s APT repository supports Noble and provides versioned packages such as postgresql-18.
For other Ubuntu releases, see our PostgreSQL installation guide for Ubuntu 22.04 and Ubuntu 26.04. For PostgreSQL on Debian 13, see our Debian 13 installation guide. You can also visit our PostgreSQL tutorials and PostgreSQL Reference.