Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Created December 15, 2024 12:49
Show Gist options
  • Save barbietunnie/29acdb7fdc8ada927bc56f8e7cd027ae to your computer and use it in GitHub Desktop.
Save barbietunnie/29acdb7fdc8ada927bc56f8e7cd027ae to your computer and use it in GitHub Desktop.
How to Install Postgres 16 on Ubuntu

How to Install Postgres 16 on Ubuntu

To install PostgreSQL 16 on Ubuntu, follow these steps:

Step 1: Update the System

Before installing PostgreSQL, ensure that your system is up-to-date.

sudo apt update
sudo apt upgrade -y

Step 2: Add the PostgreSQL APT Repository

The PostgreSQL APT repository contains the latest stable PostgreSQL releases. Add it to your system.

  1. Install prerequisites for adding a new repository:
sudo apt install -y wget gnupg
  1. Add the PostgreSQL repository key:
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg \
  --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg
  1. Add the PostgreSQL repository:
echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt/ \
  $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

Step 3: Install PostgreSQL 16

  1. Update the package lists:
sudo apt update
  1. Install PostgreSQL 16:
sudo apt install -y postgresql-16

Step 4: Verify Installation

  1. Check the PostgreSQL service status:
sudo systemctl status postgresql
  1. Verify the PostgreSQL version:
psql --version

Step 5: Configure PostgreSQL (Optional)

  1. Switch to the postgres user:
sudo -i -u postgres
  1. Access the PostgreSQL shell:
psql
  1. Exit the shell:
\q
  1. Return to your normal user account:
exit

Troubleshooting

• If PostgreSQL does not start automatically, start it manually:

sudo systemctl start postgresql

• Enable PostgreSQL to start on boot:

sudo systemctl enable postgresql

PostgreSQL 16 is now installed and ready for use!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment