How to Install PostgreSQL on Ubuntu 25.10
PostgreSQL is a powerful, open-source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.
Install PostgreSQL
To install the latest PostgreSQL version on Ubuntu 25.10, we’ll use the official PostgreSQL repository to ensure we get the newest release (currently PostgreSQL 18).
apt update && apt upgrade -y
Install required dependencies to add the PostgreSQL repository:
apt install -y ca-certificates curl gnupg lsb-release
Add the PostgreSQL GPG key and repository:
install -d /usr/share/postgresql-common/pgdg
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(. /etc/os-release && echo $VERSION_CODENAME)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
Update the package list again:
apt update
Now, install PostgreSQL and the additional contributed modules:
apt install -y postgresql postgresql-contrib
Output:
root@server:~# apt install -y postgresql postgresql-contrib
Installing:
postgresql postgresql-contrib
Installing dependencies:
libcommon-sense-perl libjson-xs-perl libpq5 postgresql-18 postgresql-client-18 postgresql-client-common postgresql-common ssl-cert
Start and Enable PostgreSQL Service
Enable and start the PostgreSQL service to ensure it runs automatically on system boot:
systemctl enable postgresql
systemctl start postgresql
Access PostgreSQL Shell
Switch to the default PostgreSQL user account:
sudo -i -u postgres
Access the PostgreSQL interactive shell:
psql
Output:
postgres@server:~$ psql
psql (18.0 (Ubuntu 18.0-1.pgdg25.10+3))
Type "help" for help.
postgres=#
Exit the PostgreSQL shell:
\q
Create PostgreSQL Role
To create a new user/role that can interact with the database:
createuser --interactive
Output:
postgres@server:~$ createuser --interactive
Enter name of role to add: adam
Shall the new role be a superuser? (y/n) y
Create a Database
Create a new database owned by your user:
createdb database_name
Example:
postgres@server:~$ createdb my_db
Add a Matching Linux User
For simplicity, you can create a Linux user with the same name as your PostgreSQL role:
adduser adam
Output:
root@server:~# adduser adam
Adding user `adam' ...
Adding new group `adam' (1000) ...
Adding new user `adam' (1000) with group `adam' ...
Creating home directory `/home/adam' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Switch to the new user and connect to PostgreSQL:
su - adam
psql -d my_db
Output:
adam@server:~$ psql -d my_db
psql (18.0 (Ubuntu 18.0-1.pgdg25.10+1))
Type "help" for help.
my_db=#
Check connection info:
\conninfo
Output:
my_db=# \conninfo
You are connected to database "my_db" as user "adam" via socket in "/var/run/postgresql" at port "5432".
Secure PostgreSQL
Set a strong password for the postgres user:
psql -U postgres
ALTER USER postgres WITH ENCRYPTED PASSWORD 'your_secure_password';
\q
Enable Remote Connections (Optional)
To allow external connections, edit PostgreSQL configuration files:
nano /etc/postgresql/18/main/postgresql.conf
Uncomment and modify the line:
listen_addresses = '*'
Then edit the host-based authentication file:
nano /etc/postgresql/18/main/pg_hba.conf
Add the following line at the end:
host all all 0.0.0.0/0 md5
Restart PostgreSQL to apply changes:
systemctl restart postgresql
Conclusion
You have successfully installed PostgreSQL 18 on Ubuntu 25.10. The PostgreSQL service is now active, and you can manage databases and roles as needed. For enhanced security, remember to restrict access via firewall or network configuration when enabling remote access.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS