Skip to content

About

A step-by-step guide for installing PostgreSQL 18.4 from source on Ubuntu without sudo or system-wide packages. It shows how to build, configure, install, initialize, and run PostgreSQL entirely in the user’s home directory, making it ideal for local development, testing, and learning.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

PostgreSQL 18.4 — User-Local Installation on Ubuntu

Author: Joebert L. Cerezo

Install PostgreSQL 18.4 from source into the user's home directory, without installing PostgreSQL system-wide.

PostgreSQL itself is installed without sudo. sudo was only used to install the required system build dependencies.

1. Prerequisites

Check the compiler and build tools:

gcc --version
make --version

Install the required PostgreSQL build dependencies:

sudo apt install libicu-dev bison flex libreadline-dev zlib1g-dev

These provide:

  • ICU — Unicode/collation support
  • Bison/Flex — PostgreSQL parser generation
  • Readline — psql interactive command history/editing
  • zlib — compression support

2. PostgreSQL Source

Download the PostgreSQL source tarball from the official download directory:

  1. Open PostgreSQL Downloads
  2. Click File Browser
  3. Go to source
  4. Select the version you want, for example v18.4
  5. Download the source archive

For PostgreSQL 18.4, the file used in this guide is:

Download/extract PostgreSQL 18.4:

cd ~/Downloads
tar -xvf postgresql-18.4.tar.gz
cd postgresql-18.4

3. Configure

Install PostgreSQL into:

~/.local/postgresql

Run:

./configure --prefix="$HOME/.local/postgresql"

The successful configuration detected:

ICU          yes
Readline     yes
zlib         yes
Bison        yes
Flex         yes
OpenSSL      yes

4. Compile

Build PostgreSQL using all available CPU cores:

make -j"$(nproc)"

If the server has limited resources:

make -j4

5. Install

Install PostgreSQL into the user's home directory:

make install

No sudo is required.

The installation is located at:

~/.local/postgresql

6. Add PostgreSQL to PATH

Add PostgreSQL to .bashrc:

echo 'export PGHOME="$HOME/.local/postgresql"' >> ~/.bashrc
echo 'export PATH="$PGHOME/bin:$PATH"' >> ~/.bashrc

Reload:

source ~/.bashrc

Verify:

postgres --version
initdb --version
psql --version

Expected:

PostgreSQL 18.4

7. Initialize the Database Cluster

Create the PostgreSQL data directory:

initdb -D "$HOME/.local/pgdata" -U "$USER"

Database cluster location:

~/.local/pgdata

initdb may warn that local authentication is using trust.

For a local development server, this is acceptable. Review pg_hba.conf if password authentication is required.


8. Start PostgreSQL

Start the server:

pg_ctl \
  -D "$HOME/.local/pgdata" \
  -l "$HOME/.local/pgdata/postgresql.log" \
  start

Check status:

pg_ctl -D "$HOME/.local/pgdata" status

Expected:

pg_ctl: server is running

9. Connect to PostgreSQL

By default, psql tries to connect to a database named after the Linux user.

If only the default postgres database is wanted:

psql -d postgres

To make psql always use postgres:

echo 'export PGDATABASE=postgres' >> ~/.bashrc
source ~/.bashrc

Then:

psql

will connect directly to:

postgres=#

No joebert database needs to be created.


10. Useful Commands

Start

pg_ctl -D "$HOME/.local/pgdata" \
  -l "$HOME/.local/pgdata/postgresql.log" start

Stop

pg_ctl -D "$HOME/.local/pgdata" stop

Restart

pg_ctl -D "$HOME/.local/pgdata" restart

Status

pg_ctl -D "$HOME/.local/pgdata" status

Connect

psql

View logs

tail -f "$HOME/.local/pgdata/postgresql.log"

Final Installation

PostgreSQL source:
~/Downloads/postgresql-18.4

PostgreSQL installation:
~/.local/postgresql

Database cluster:
~/.local/pgdata

Default database:
postgres

Default port:
5432

The PostgreSQL server runs entirely under the user's account and does not require a system-wide PostgreSQL installation or systemctl service.

About

A step-by-step guide for installing PostgreSQL 18.4 from source on Ubuntu without sudo or system-wide packages. It shows how to build, configure, install, initialize, and run PostgreSQL entirely in the user’s home directory, making it ideal for local development, testing, and learning.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors