In this article we will discuss the process of installing PostgreSQL on Ubuntu 24.04 (Noble Numbat) Linux operating system. PostgreSQL is an open source, yet powerful relation database management system with object-oriented concepts. It shines in robustness, performance, and reliability. There is a large community behind the development of this database system. PostgreSQL is an ideal choice when modeling more complex data relationships in your applications.
Since PostgreSQL is ACID Compliant (complies to Atomicity, Consistency, Isolation, and Durability), you are guaranteed of data reliability and integrity in transactions. This is a very important feature in all businesses. PostgreSQL is a winner when choosing the right database for mission-critical applications, huge and complex analytics. Use the steps in the next sections to install, configure, and start to use PostgreSQL on Ubuntu 24.04.
The Ultimate Ubuntu Desktop Handbook
Master Ubuntu like a pro - from beautiful desktop customization to powerful terminal automation. Perfect for developers, system admins, and power users who want total control of their workspace.
1. Prepare the system
To follow this article and be successful you will need the following.
- Ubuntu 24.04 (Noble Numbat) Linux system – VM or dedicated
- Internet access on the server
- User with sudo permissions, alternatively login as root user.
Login to your system with ssh or direct OS terminal access.
ssh user@serverIP
Update repository packages list.
sudo apt update
2. Install PostgreSQL database
You have two choices for this installation.
Option 1) Install from default system repositories
The default repositories of Ubuntu contain packages of PostgreSQL. If you don’t care about most latest releases, this is the easiest installation method.
Just start a terminal session in your machine and install postgresql packages.
sudo apt install postgresql postgresql-contrib
At the time of writing this article, the latest stable release available is PostgreSQL 16. This should be sufficient for most applications.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
ubuntu-advantage-tools
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libllvm17t64 libpq5 libtypes-serialiser-perl postgresql-16 postgresql-client-16 postgresql-client-common postgresql-common ssl-cert
Suggested packages:
postgresql-doc postgresql-doc-16
The following NEW packages will be installed:
libcommon-sense-perl libjson-perl libjson-xs-perl libllvm17t64 libpq5 libtypes-serialiser-perl postgresql postgresql-16 postgresql-client-16 postgresql-client-common postgresql-common
postgresql-contrib ssl-cert
0 upgraded, 13 newly installed, 0 to remove and 1 not upgraded.
Need to get 43.5 MB of archives.
After this operation, 175 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Database service is started automatically after the installation.
$ systemctl status postgresql@*-main.service
● [email protected] - PostgreSQL Cluster 16-main
Loaded: loaded (/usr/lib/systemd/system/[email protected]; enabled-runtime; preset: enabled)
Active: active (running) since Sun 2024-04-21 12:42:25 EAT; 4min 46s ago
Process: 21647 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 16-main start (code=exited, status=0/SUCCESS)
Main PID: 21652 (postgres)
Tasks: 6 (limit: 4614)
Memory: 19.7M (peak: 27.1M)
CPU: 206ms
CGroup: /system.slice/system-postgresql.slice/[email protected]
├─21652 /usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main -c config_file=/etc/postgresql/16/main/postgresql.conf
├─21653 "postgres: 16/main: checkpointer "
├─21654 "postgres: 16/main: background writer "
├─21656 "postgres: 16/main: walwriter "
├─21657 "postgres: 16/main: autovacuum launcher "
└─21658 "postgres: 16/main: logical replication launcher "
Apr 21 12:42:23 ubuntu-2404-server systemd[1]: Starting [email protected] - PostgreSQL Cluster 16-main...
Apr 21 12:42:25 ubuntu-2404-server systemd[1]: Started [email protected] - PostgreSQL Cluster 16-main.
Option 2) Install from PostgreSQL official repositories
An alternative installation method is from project’s upstream developer provided APT repository. This repository contain all supported versions of PostgreSQL. If you need to install an older, but stable release of PostgreSQL use this method.
Add PostgreSQL gpg key into your system.
sudo apt install curl ca-certificates
sudo curl -o /etc/apt/trusted.gpg.d/postgresql.gpg --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
Create a repository configuration file.
sudo sh -c 'echo "deb [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'
Update packages list after repository configuration.
sudo apt update
To install the latest PostgreSQL version from the repository, run:
sudo apt -y install postgresql
To install a specific version, use postgresql-<version> instead of postgresql. See examples below.
### PostgreSQL 16 ###
sudo apt install postgresql-16
### PostgreSQL 15 ###
sudo apt install postgresql-15
### PostgreSQL 14 ###
sudo apt install postgresql-14
### PostgreSQL 13 ###
sudo apt install postgresql-13
3. Connect to PostgreSQL shell
After installation, connect to the PostgreSQL shell on your Ubuntu system. Switch to postgres user.
sudo su - postgres
Once you’re postgres user, start the psql client shell.
postgres@ubuntu-2404-server:~$ psql
psql (16.2 (Ubuntu 16.2-1ubuntu4))
Type "help" for help.
postgres=#
One line command that does the same is sudo -u postgres psql.
postgres=# exit
postgres@ubuntu-2404-server:~$ exit
logout
jkmutai@ubuntu-2404-server:~$ sudo -u postgres psql
psql (16.2 (Ubuntu 16.2-1ubuntu4))
Type "help" for help.
postgres=#
4. Adding data to database
We can use the CREATE DATABASE command to create a test database on PostgreSQL
postgres=# CREATE DATABASE testdb;
CREATE DATABASE
A database user can be created using CREATE USER command.
postgres=# CREATE USER testuser WITH PASSWORD 'StrongDBPassword';
We have created a database and a user, but the user has not been granted access to the database created. We can use the GRANT ALL PRIVILEGES command for this operation.
GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;
To verify that created user has access to the database, we can reconnect as the user.
exit
psql -h localhost -U testuser -d testdb
Enter password when prompted.
jkmutai@ubuntu-2404-server:~$ psql -h localhost -U testuser -d testdb
Password for user testuser: <ENTER-PASSWORD>
psql (16.2 (Ubuntu 16.2-1ubuntu4))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.
testdb=>
Let’s create cars table with three columns – brand, model, and year.
CREATE TABLE cars (
brand VARCHAR(255),
model VARCHAR(255),
year INT
);
To insert sample data into the table created, run:
INSERT INTO cars (brand, model,year) VALUES ('BMW', 'X3','2020');
INSERT INTO cars (brand, model,year) VALUES ('Toyota', 'Harrier','2021');
INSERT INTO cars (brand, model,year) VALUES ('Audi', 'SQ5','2022');
View inserted data in the table
testdb=# SELECT * FROM cars;
brand | model | year
--------+---------+------
BMW | X3 | 2020
Toyota | Harrier | 2021
Audi | SQ5 | 2022
(3 rows)
testdb=#
To drop table use:
\q
DROP DATABASE testdb;
This marks the end of our article on how to install PostgreSQL on Ubuntu 24.04 (Noble Numbat). PostgreSQL comes with a rich set of features that are suitable for various application needs. Now that you are equipped with the basic understanding of PostgreSQL database server installation, configuration and basic usage, begin to explore extra advanced functionalities by referring to the official PostgreSQL documentation pages.







































