PostgreSQL Tutorials: How To Install PostgreSQL On Linux

By Nicholas Brown – Follow me on X.

You can install PostgreSQL on Linux using multiple methods, including compiling it from source, using your Linux distribution’s built-in package manager (Ubuntu/Debian’s Aptitude, Gentoo’s Ebuild, or Fedora/RedHat’s RPM), or you can use PostgreSQL’s official repository with your operating system’s built-in package manager.

How To Install PostgreSQL From The Ubuntu Repository

You can install PostgreSQL using only one command if you are using the built-in Ubuntu repository as shown below:

sudo apt install postgresql

How To Install PostgreSQL From PostgreSQL’s Repository

If you’re willing to type a few extra commands, i’d recommend the official PostgreSQL repository because it will get the latest version before the built-in repositories will:

The following commands will set up PostgreSQL’s official repository. Note that the ‘-y‘ command after ‘apt-get’ will install it without confirmation and you can remove that if you wish.

PostgreSQL Tutorial: How To Create A User In PostgreSQL

sudo sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

wget --quiet -O - | sudo apt-key add -

sudo apt-get update
sudo apt-get -y install postgresql