How To Install Psql On Debian, Ubuntu, Alpine, Arch, Kali, CentOS, Fedora, Raspbian And MacOS?

How To Install Psql On Debian, Ubuntu, Alpine, Arch, Kali, CentOS, Fedora, Raspbian And MacOS?

psql

PostgreSQL command-line client.

Install psql

  • Debian apt-get install postgresql-client-9.1 Click to copy
  • Ubuntu apt-get install postgresql-client-9.3 Click to copy
  • Alpine OS apk add postgresql Click to copy
  • Arch Linux pacman -S postgresql-old-upgrade Click to copy
  • Kali Linux apt-get install postgresql-client-11 Click to copy
  • CentOS yum install postgresql Click to copy
  • Fedora dnf install postgresql Click to copy
  • Raspbian apt-get install postgresql-client-9.5 Click to copy
  • macOS brew install postgresql Click to copy

PostgreSQL command-line client.

How to use psql?

Below are few example commands for psql that you can use in the terminal.

Connect to database. It connects to localhost using default port 5432 with default user as currently logged in user:
psql databaseClick to copy
Connect to database on given server host running on given port with given username, without a password prompt:
psql -h host -p port -U username databaseClick to copy
Connect to database; user will be prompted for password:
psql -h host -p port -U username -W databaseClick to copy
Execute a single SQL query or PostgreSQL command on the given database (useful in shell scripts):
psql -c 'query' databaseClick to copy
Execute commands from a file on the given database:
psql database -f file.sqlClick to copy
Installation of latest psql command is available for Debian, Ubuntu, Alpine, Arch, Kali, CentOS, Fedora, Raspbian and macOS. You can copy the command for your OS from above and paste it into your terminal. Once you run the command it will download the 2026 latest package from the repository and install it in your computer/server.