In this step-by-step tutorial, learn how to install and use PostgreSQL on Ubuntu 25.04 entirely via the Linux terminal. This guide covers everything from installation to creating a database, table, inserting data, and running basic SQL queries — all from the command line. Perfect for beginners and those getting started with PostgreSQL and Ubuntu!
🛠️ Commands Covered:
Update and upgrade system packages
Install PostgreSQL and tools
Check PostgreSQL service status
Switch to the postgres user
Enter psql shell
Create a database and table
Insert and select data using SQL
Exit PostgreSQL properly
🔍 Commands Used:
sudo apt update && sudo apt upgrade
sudo apt install postgresql postgresql-contrib
sudo systemctl status postgresql
sudo -i -u postgres
psql
CREATE DATABASE testdb;
\c testdb
CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL);
INSERT INTO users (name) VALUES ('Alice'), ('Bob'), ('Charlie');
SELECT * FROM users;
\q
exit