To install PostgreSQL 16.9 on Debian, you’ll want to use the official PostgreSQL APT repository, as Debian’s default repositories might not always have the latest version.
Here’s a step-by-step guide:
Step 1: Add PostgreSQL APT Repository
sudo apt update
sudo apt install -y curl gnupg2 ca-certificates lsb-release
Import the PostgreSQL signing key:
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql.gpg
Add the repository:
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
Step 2: Install PostgreSQL 16.9
Update your package list:
sudo apt update
Install PostgreSQL 16:
sudo apt install -y postgresql-16
Note: The version installed will be the latest available in the 16.x series, which is 16.9 as of now. If you’ve already added the PostgreSQL repository and the latest version isn’t showing, make sure no older packages are pinned.
Step 3: Verify Installation
Check PostgreSQL version:
psql --version
Start and enable PostgreSQL service:
sudo systemctl enable postgresql
sudo systemctl start postgresql
Step 4: Basic Usage
Switch to the postgres
user:
sudo -i -u postgres
Access the PostgreSQL prompt:
psql
Exit with:
\q
Leave a Reply