PostgreSQL, often referred to as Postgres, is a powerful, open-source relational database system trusted by developers, businesses, and governments around the world. It supports advanced data types, indexing, transactions, and concurrency, making it a top choice for both small and large-scale applications. If you're working with Ubuntu’s latest version, this guide will help you install Postgres on Ubuntu 24.04, following the trusted steps from Vultr’s official documentation.
What Is Postgres and Why Use It?
Postgres is a robust, extensible database system that supports:
- ACID-compliant transactions
- Full-text search
- Advanced indexing techniques
- JSON support for semi-structured data
- Extensibility with custom functions and data types
Its strong security features and active development community make it ideal for modern web apps, APIs, and enterprise-level systems.
Why Choose Ubuntu 24.04?
Ubuntu 24.04 is the latest Long-Term Support (LTS) release, offering five years of security updates. It provides developers with a stable, secure environment to deploy critical applications. Combining Ubuntu 24.04 with PostgreSQL ensures high compatibility and up-to-date features.
Prerequisites
Before starting the installation, make sure:
- You are running Ubuntu 24.04
- You have a sudo-enabled user account
- Your system is connected to the internet
Update the package list and upgrade installed packages:
sudo apt update && sudo apt upgrade -y
Step 1: Install Postgres on Ubuntu 24.04
Ubuntu includes PostgreSQL in its default APT repositories. Install it with:
sudo apt install postgresql postgresql-contrib -y
- postgresql: Core database server
- postgresql-contrib: Extra utilities and extensions like pg_stat_statements, tablefunc, and more
Step 2: Check PostgreSQL Status
After installation, the PostgreSQL service starts automatically. Check its status with:
sudo systemctl status postgresql
If it's active and running, you're good to go. You can also manage the service using:
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
sudo systemctl enable postgresql
Step 3: Access the PostgreSQL Shell
PostgreSQL creates a default Linux user called postgres. Switch to this user and access the database shell with:
sudo -i -u postgres
psql
Once you're in the PostgreSQL prompt, you can execute SQL commands. To exit the shell, type:
\q
Step 4: Create a New Database and User
To create a new user:
createuser --interactive
Follow the prompts to name the user and assign privileges.
To create a new database:
createdb mydatabase
You can then connect to the new database:
psql mydatabase
Step 5: Enable Remote Access (Optional)
PostgreSQL listens only to local connections by default. To enable remote access:
- Edit the configuration file:
sudo nano /etc/postgresql/16/main/postgresql.conf
Set:
listen_addresses = '*'
- Update the authentication file:
sudo nano /etc/postgresql/16/main/pg_hba.conf
Add:
host all all 0.0.0.0/0 md5
Restart the PostgreSQL service:
sudo systemctl restart postgresql
Step 6: Test Your Setup
Log into the database and create a table to confirm everything works:
CREATE TABLE demo (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);
INSERT INTO demo (name) VALUES ('Ubuntu 24.04 User');
SELECT * FROM demo;
This confirms your PostgreSQL setup is running properly.
Conclusion
Now that you know how to install Postgres on Ubuntu 24.04, you’re ready to take advantage of one of the most reliable database platforms available. Whether you're building a personal project, launching a new application, or managing enterprise data, PostgreSQL on Ubuntu provides a stable, secure, and scalable environment. For more details and troubleshooting, refer to the official Vultr guide.
With just a few terminal commands, you’ve set the foundation for powerful, data-driven development!