Skip to main content
0 reactions

How to Install PostgreSQL 19 on Ubuntu

Featured card for How to Install PostgreSQL 19 on Ubuntu. A terminal window ticks off four results from the install: apt.postgresql.org, postgresql-19, cluster 19/main and port 5432.
Install PostgreSQL 19 on Ubuntu from the official PostgreSQL apt repository.

PostgreSQL 19 is out. This guide shows how to install PostgreSQL 19 on Ubuntu from the official PostgreSQL repository, then connect to it with psql.

Ubuntu has its own PostgreSQL package, but each Ubuntu release stays on the version it shipped with: on Ubuntu 26.04 LTS, that’s PostgreSQL 18. The PostgreSQL project runs its own apt repository with every supported version, so you get 19 today, and its updates arrive through apt like the rest of Ubuntu’s. PostgreSQL’s Ubuntu download page (opens in a new tab) points to this repository when Ubuntu’s version isn’t the one you want.

By the end, you’ll have:

  • PostgreSQL 19 running on Ubuntu, starting by itself whenever Ubuntu starts
  • psql, the PostgreSQL command-line tool, connected to your new server
  • PostgreSQL updates that arrive with Ubuntu’s own updates

No Ubuntu machine yet? On a Mac, How to Create an Ubuntu VM on a Mac with Multipass sets one up.

Every command and output on this page is real, from PostgreSQL 19.0 on Ubuntu 26.04 LTS.

Prerequisites

Step 1: Refresh Ubuntu’s Package List

Open a terminal on your Ubuntu machine and run:

Ubuntu TerminalBash
sudo apt update

sudo runs a command as the administrator. If Ubuntu asks for your password, type it and press Enter: nothing appears while you type. apt update downloads the newest list of packages, so the next commands install current versions. The output ends like this:

Output (the last lines)Plain text
Fetched 4742 kB in 4s (1154 kB/s)
25 packages can be upgraded. Run 'apt list --upgradable' to see them.

Your numbers will differ. You don’t need to upgrade those packages to install PostgreSQL.

Step 2: Add the Official PostgreSQL Repository

First, install postgresql-common, a small Ubuntu package that contains the PostgreSQL repository’s setup script:

Ubuntu TerminalBash
sudo apt install -y postgresql-common

-y answers yes when apt asks whether to go ahead. Then run the setup script:

Ubuntu TerminalBash
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

It names your Ubuntu release and waits. Press Enter to continue:

OutputPlain text
This script will enable the PostgreSQL APT repository on apt.postgresql.org on
your system. The distribution codename used will be resolute-pgdg.

Press Enter to continue, or Ctrl-C to abort.

Using keyring /usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg
Writing /etc/apt/sources.list.d/pgdg.sources ...

Running apt-get update ...
Hit:1 http://archive.ubuntu.com/ubuntu resolute InRelease
Hit:2 http://security.ubuntu.com/ubuntu resolute-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu resolute-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu resolute-backports InRelease
Get:5 https://apt.postgresql.org/pub/repos/apt resolute-pgdg InRelease [189 kB]
Get:6 https://apt.postgresql.org/pub/repos/apt resolute-pgdg/main arm64 Packages [1173 kB]
Fetched 1362 kB in 3s (417 kB/s)
Reading package lists... Done

You can now start installing packages from apt.postgresql.org.

Have a look at https://wiki.postgresql.org/wiki/Apt for more information;
most notably the FAQ at https://wiki.postgresql.org/wiki/Apt/FAQ

The script added the PostgreSQL repository, with the key apt uses to check its packages, and refreshed the package list. resolute is the code name of Ubuntu 26.04; on Ubuntu 24.04 it says noble.

Step 3: Install PostgreSQL 19 on Ubuntu

Ubuntu TerminalBash
sudo apt install -y postgresql-19

This installs the PostgreSQL 19 server and its command-line tools, including psql. Near the end, it creates your first database cluster:

Output (the lines that matter)Plain text
Setting up postgresql-19 (19.0-1.pgdg26.04+1) ...
Creating new PostgreSQL cluster 19/main ...
/usr/lib/postgresql/19/bin/initdb -D /var/lib/postgresql/19/main --auth-local peer --auth-host scram-sha-256 --no-instructions

A cluster is the set of databases one PostgreSQL server manages (Part 1 explains it), and 19/main is the one for PostgreSQL 19. Its data lives in /var/lib/postgresql/19/main. The server is already running, and it starts by itself whenever Ubuntu starts.

Step 4: Connect to PostgreSQL with psql

PostgreSQL’s admin user is called postgres, and the install also created a Linux user with the same name. Connect by running psql as that user:

Ubuntu TerminalBash
sudo -u postgres psql

-u postgres makes sudo run psql as the Linux user postgres. On the same machine, PostgreSQL on Ubuntu uses peer authentication (opens in a new tab): it lets you in as the database user with your Linux user’s name, without a password.

OutputPlain text
psql (19.0 (Ubuntu 19.0-1.pgdg26.04+1))
Type "help" for help.

postgres=#

You’re connected. postgres=# is the psql prompt: psql is waiting for a command. Ask the server which version it runs:

postgres=#SQL
SHOW server_version;
OutputPlain text
          server_version
----------------------------------
 19.0 (Ubuntu 19.0-1.pgdg26.04+1)
(1 row)

The server answers 19.0, built for Ubuntu 26.04 by the PostgreSQL repository. Type \q and press Enter to leave psql:

postgres=#Plain text
\q

Clean Up

There’s nothing to clean up: this guide only installs PostgreSQL, and the server keeps running so it’s ready when you need it. A guide to removing it completely, How to Completely Uninstall PostgreSQL from Ubuntu, is coming later in the series.

Common Mistakes

MistakeWhat you seeFix
Installing postgresql-19 before Step 2Error: Unable to locate package postgresql-19Do Step 2, then install again.
Installing postgresql before Step 2apt installs PostgreSQL 18, the version Ubuntu 26.04 includesDo Step 2 first, then install postgresql-19.
Typing psql on its ownpsql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "ubuntu" does not exist, with your own user nameConnect as the postgres user: sudo -u postgres psql.
Typing psql -U postgrespsql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres"Use sudo -u postgres psql. Peer authentication checks your Linux user, not the name after -U.

FAQ

Does PostgreSQL start by itself when Ubuntu starts?

Yes. The install sets up a service called postgresql that starts the server whenever Ubuntu starts. You don’t need to start it yourself.

Where does PostgreSQL keep my databases on Ubuntu?

In /var/lib/postgresql/19/main. Its settings files are in /etc/postgresql/19/main. Leave the data files to PostgreSQL: change your data with SQL, never by editing those files.

What is the password of the postgres user?

It has none, and psql doesn’t need one: sudo -u postgres psql connects through peer authentication. You only need a password to connect over the network, for example from pgAdmin.

How do I update PostgreSQL on Ubuntu?

With Ubuntu’s normal updates. Run sudo apt update, then sudo apt upgrade, and apt installs new minor releases of PostgreSQL 19 from the PostgreSQL repository along with the rest.

Is PostgreSQL free?

Yes, for personal and commercial use. Is PostgreSQL Free for Commercial Use? explains its licence.

Conclusion

PostgreSQL 19 is installed on Ubuntu, starts by itself and answers in psql. Next in the series: Part 2: Connect with psql and Run Your First Commands (coming soon). The PostgreSQL Tutorial for Beginners page lists every part and setup guide.

Additional Resources

Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.

0 comments