Skip to content

Instantly share code, notes, and snippets.

@ammarshah
Last active October 25, 2024 13:47
Show Gist options
  • Save ammarshah/40535b7e6c76597bda58afece875b7e6 to your computer and use it in GitHub Desktop.
Save ammarshah/40535b7e6c76597bda58afece875b7e6 to your computer and use it in GitHub Desktop.
Install PostgreSQL 17 on Ubuntu 24.04

Install PostgreSQL 17 on Ubuntu 24.04

1. Import the repository signing key:

$ sudo apt install curl ca-certificates
$ sudo install -d /usr/share/postgresql-common/pgdg
$ sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc

2. Create the repository configuration file:

$ sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

3. Update the package lists:

$ sudo apt update

4. Install PostgreSQL 17:

# If you want the latest version, use 'postgresql' instead of 'postgresql-17'
$ sudo apt -y install postgresql-17

5. Verify PostgreSQL installation:

$ sudo systemctl status postgresql

6. Check the PostgreSQL version:

$ psql --version

Update PostgreSQL Admin User Password

1. Access psql terminal:

$ sudo -u postgres psql

2. Set password for postgres user:

postgres=# ALTER USER postgres PASSWORD 'root';

3. Exit psql:

postgres=# \q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment