Learn how to install PostgreSQL on Ubuntu 26.04 with this beginner friendly step by step guide. Install PostgreSQL, create databases and users, verify the service, and start using PostgreSQL in minutes.
PostgreSQL is one of the most popular open source relational database systems. It is trusted by startups, enterprises, and developers because it is reliable, fast, and supports advanced SQL features. Whether you're building a web application, REST API, or analytics platform, PostgreSQL is a solid choice.
Prerequisites
Before you begin, make sure you have:
-
Ubuntu 26.04 installed dedicated server.
-
A user account with sudo privileges
-
An internet connection
Let's start learning how to install PostgreSQL on Ubuntu 26.04 LTS.
Step 1: Update Your System
Start by refreshing your package list and installing available updates.
sudo apt update
sudo apt upgrade -y
This helps ensure you're installing the latest available packages.
Step 2: Install PostgreSQL
Ubuntu 26.04 includes PostgreSQL 18 in its default repositories, making installation very simple.
Run:
sudo apt install postgresql postgresql-contrib -y
The postgresql-contrib package installs additional extensions that are commonly used with PostgreSQL.
Step 3: Check the PostgreSQL Service
After installation, PostgreSQL starts automatically.
Check its status with:
sudo systemctl status postgresql
If everything is working correctly, you should see that the service is active (running).
If the service is not running, start it manually:
sudo systemctl start postgresql
Enable PostgreSQL to start automatically after every reboot:
sudo systemctl enable postgresql
Step 4: Verify the Installed Version
To see which PostgreSQL version is installed:
psql --version
Example output:
psql (PostgreSQL) 18.x
The exact version may differ depending on the latest package updates available.
Step 5: Switch to the PostgreSQL User
PostgreSQL creates a system user named postgres.
Switch to it using:
sudo -i -u postgres
You should now see something similar to:
postgres@server:~$
Step 6: Open the PostgreSQL Shell
Launch the PostgreSQL command line interface:
psql
You'll enter the PostgreSQL prompt:
postgres=#
To exit the shell later, run:
\q
Step 7: Set a Password for the PostgreSQL User
Although local authentication works without a password by default, setting one is recommended.
Inside the PostgreSQL shell, run:
ALTER USER postgres WITH PASSWORD 'YourStrongPassword';
Replace YourStrongPassword with a secure password.
Exit PostgreSQL:
\q
Step 8: Create a New Database
Switch back into the PostgreSQL shell if needed:
sudo -u postgres psql
Create a database:
CREATE DATABASE mydatabase;
Check that it exists:
\l
You should see mydatabase in the list.
Step 9: Create a New User
Create a user for your applications instead of using the default postgres account.
CREATE USER myuser WITH PASSWORD 'MySecurePassword';
Grant access to the database:
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
Exit PostgreSQL:
\q
Step 10: Test the Connection
Connect using the new user:
psql -U myuser -d mydatabase -h localhost
Enter the password when prompted.
If the connection succeeds, PostgreSQL is ready to use.
Useful PostgreSQL Commands
Restart PostgreSQL
sudo systemctl restart postgresql
Stop PostgreSQL
sudo systemctl stop postgresql
Start PostgreSQL
sudo systemctl start postgresql
Check Service Status
sudo systemctl status postgresql
List All Databases
sudo -u postgres psql -c "\l"
List All Users
sudo -u postgres psql -c "\du"
Common Installation Issues
psql: command not found
Verify that PostgreSQL is installed:
dpkg -l | grep postgresql
If it isn't installed, run:
sudo apt install postgresql postgresql-contrib -y
PostgreSQL Service Is Not Running
Start the service:
sudo systemctl start postgresql
Then verify:
sudo systemctl status postgresql
Authentication Failed
Double check:
-
Username
-
Password
-
Database name
-
Host value (
localhost)
If you've recently changed the password, reconnect after restarting the session.
Conclusion
In this tutorial we have seen how to install PostgreSQL on Ubuntu 26.04. You've verified the installation, connected to the database server, created your first database, added a new user, and tested a database connection. Your server is now ready for applications such as Node.js, Python, PHP, Java, or any framework that supports PostgreSQL.

