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.sudowas only used to install the required system build dependencies.
Check the compiler and build tools:
gcc --version
make --versionInstall the required PostgreSQL build dependencies:
sudo apt install libicu-dev bison flex libreadline-dev zlib1g-devThese provide:
- ICU — Unicode/collation support
- Bison/Flex — PostgreSQL parser generation
- Readline —
psqlinteractive command history/editing - zlib — compression support
Download the PostgreSQL source tarball from the official download directory:
- Open PostgreSQL Downloads
- Click
File Browser - Go to
source - Select the version you want, for example v18.4
- 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.4Install 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
Build PostgreSQL using all available CPU cores:
make -j"$(nproc)"If the server has limited resources:
make -j4Install PostgreSQL into the user's home directory:
make installNo sudo is required.
The installation is located at:
~/.local/postgresql
Add PostgreSQL to .bashrc:
echo 'export PGHOME="$HOME/.local/postgresql"' >> ~/.bashrc
echo 'export PATH="$PGHOME/bin:$PATH"' >> ~/.bashrcReload:
source ~/.bashrcVerify:
postgres --version
initdb --version
psql --versionExpected:
PostgreSQL 18.4
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.
Start the server:
pg_ctl \
-D "$HOME/.local/pgdata" \
-l "$HOME/.local/pgdata/postgresql.log" \
startCheck status:
pg_ctl -D "$HOME/.local/pgdata" statusExpected:
pg_ctl: server is running
By default, psql tries to connect to a database named after the Linux user.
If only the default postgres database is wanted:
psql -d postgresTo make psql always use postgres:
echo 'export PGDATABASE=postgres' >> ~/.bashrc
source ~/.bashrcThen:
psqlwill connect directly to:
postgres=#
No joebert database needs to be created.
pg_ctl -D "$HOME/.local/pgdata" \
-l "$HOME/.local/pgdata/postgresql.log" startpg_ctl -D "$HOME/.local/pgdata" stoppg_ctl -D "$HOME/.local/pgdata" restartpg_ctl -D "$HOME/.local/pgdata" statuspsqltail -f "$HOME/.local/pgdata/postgresql.log"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.