Skip to content

Instantly share code, notes, and snippets.

@kljensen
Created March 30, 2021 00:25
Show Gist options
  • Save kljensen/f4c884950f2cb41cdc17a6a5d33119b8 to your computer and use it in GitHub Desktop.
Save kljensen/f4c884950f2cb41cdc17a6a5d33119b8 to your computer and use it in GitHub Desktop.
Install PostgreSQL from source on GNU/Linux systems (likely also bsd)
#!/bin/sh
# Create a temprary directory
tmp_dir=$(mktemp -d -t pg-install-XXXXXXXXXX)
printf "Using tmp directory $tmp_dir\n"
# Remove that directory upon exit
trap 'cd && rm -rf -- "$tmp_dir"' EXIT
# Change to tmp dir
cd $tmp_dir
# Download postgresql source
PG_VERSION=13.2
printf "Downloading source for PostgreSQL version $PG_VERSION"
curl -s -O https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2 >/dev/null
tar jxf postgresql-$PG_VERSION.tar.bz2 >/dev/null
cd postgresql-$PG_VERSION
printf "Configuring PostgreSQL"
./configure >/dev/null
printf "Compiling PostgreSQL (takes a few minutes)"
make >/dev/null
printf "Installing PostgreSQL"
sudo make install
sudo ln -s /usr/local/pgsql/bin/psql /usr/local/bin/psql
printf "Done! PostgreSQL v$PG_VERSION is now installed. Have fun.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment