Want to quickly how to Install PostgreSQL on Ubuntu 24.04? Follow this easy-to-understand guide based on Vultr’s official instructions. Whether you're a developer, student, or system admin, this step-by-step tutorial walks you through updating your system, installing PostgreSQL, verifying the service, and creating users and databases. PostgreSQL is a robust, open-source relational database ideal for scalable and secure applications. Get your Ubuntu 24.04 environment ready for development or production in just a few minutes. This classified post is your shortcut to mastering PostgreSQL setup on Linux. Start building smarter with PostgreSQL today!
How to Install PostgreSQL on Ubuntu 24.04 – Complete Step-by-Step Guide
If you're a developer, database administrator, or Linux enthusiast, setting up a robust database system is essential for application development and data management. PostgreSQL is one of the most advanced and widely used open-source relational database systems. In this blog, you’ll learn how to install PostgreSQL on Ubuntu 24.04 with simple steps, following the official guide from Vultr’s documentation.
What Is PostgreSQL?
PostgreSQL, often referred to as Postgres, is a feature-rich, open-source object-relational database system. Known for its high performance, scalability, and support for advanced data types, PostgreSQL is a top choice for applications ranging from simple websites to large-scale enterprise systems. Its ACID compliance and extensibility make it a trusted solution for developers and organizations around the world.
Why Ubuntu 24.04?
Ubuntu 24.04 is the latest Long-Term Support (LTS) version, offering five years of security updates and stability. It's optimized for developers and system administrators who need a reliable Linux environment. Installing PostgreSQL on Ubuntu 24.04 combines the power of Postgres with the stability of Ubuntu, making it a great combination for modern application stacks.
Prerequisites
Before starting the installation process, ensure you meet the following requirements:
A system running Ubuntu 24.04
A user account with sudo privileges
An active internet connection
First, update your system to ensure all packages are up to date:
sudo apt update && sudo apt upgrade -y
Step 1: Install PostgreSQL
Ubuntu’s default package repositories include PostgreSQL, making the installation simple and quick. To install both PostgreSQL and its additional utilities, run:
sudo apt install postgresql postgresql-contrib -y
postgresql installs the core database system.
postgresql-contrib includes additional tools and modules like table functions and extensions.
Step 2: Verify the PostgreSQL Installation
Once the installation is complete, the PostgreSQL service starts automatically. You can check its status with:
sudo systemctl status postgresql
You should see that the service is active (running). If needed, you can also manage the PostgreSQL service using:
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
Step 3: Access the PostgreSQL CLI
After installation, a Linux user named postgres is created. To access the PostgreSQL shell (psql), switch to this user:
sudo -i -u postgres
psql
You’re now inside the PostgreSQL command-line interface where you can execute SQL commands. To exit, type:
\q
Step 4: Create a New User and Database
You can create new PostgreSQL users and databases as follows:
To create a new user:
createuser --interactive
You’ll be prompted to enter the username and choose whether the user should be a superuser.
To create a new database:
createdb mydatabase
To access your new database:
psql mydatabase
Step 5: Configure Remote Access (Optional)
If you need to connect to PostgreSQL from another machine, modify the configuration:
Open the PostgreSQL config file:
sudo nano /etc/postgresql/16/main/postgresql.conf
Change:
listen_addresses = '*'
Edit the authentication config file:
sudo nano /etc/postgresql/16/main/pg_hba.conf
Add:
host all all 0.0.0.0/0 md5
Then restart PostgreSQL:
sudo systemctl restart postgresql
Step 6: Test Your Setup
You can verify that everything works by creating a test table:
CREATE TABLE test (
id SERIAL PRIMARY KEY,
name VARCHAR(100)
);
INSERT INTO test (name) VALUES ('Ubuntu User');
SELECT * FROM test;
You should see your inserted data returned.
Conclusion
Now you know how to install PostgreSQL on Ubuntu 24.04 by following a few simple commands. PostgreSQL’s powerful features combined with Ubuntu’s latest LTS release offer a dependable environment for your applications. For more detailed information and troubleshooting tips, refer to the official Vultr guide. With PostgreSQL running on your Ubuntu 24.04 system, you're ready to build secure, scalable, and high-performance applications.