Skip to content

Instantly share code, notes, and snippets.

@lizTheDeveloper
Created July 13, 2024 01:48
Show Gist options
  • Save lizTheDeveloper/f766e1a6165d2e3006454234b5346562 to your computer and use it in GitHub Desktop.
Save lizTheDeveloper/f766e1a6165d2e3006454234b5346562 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Install Script for PostgreSQL 16 and pgAdmin4 on Mac
# Install PostgreSQL
echo "Installing PostgreSQL 16 and pgAdmin4..."
echo "Downloading PostgreSQL 16..."
curl -O https://get.enterprisedb.com/postgresql/postgresql-16.0-1-osx.dmg
echo "Installing PostgreSQL 16..."
hdiutil attach postgresql-16.0-1-osx.dmg
sudo installer -pkg /Volumes/PostgreSQL\ 16.0-1/PostgreSQL\ 16.0-1.pkg -target /
hdiutil detach /Volumes/PostgreSQL\ 16.0-1
echo "PostgreSQL 16 installed successfully."
echo "Configuring PostgreSQL..."
# Initialize PostgreSQL database
sudo mkdir -p /usr/local/var/postgres
sudo chown -R $(whoami) /usr/local/var/postgres
/usr/local/pgsql/bin/initdb -D /usr/local/var/postgres
echo "Starting PostgreSQL service..."
# Start PostgreSQL service
/usr/local/pgsql/bin/pg_ctl -D /usr/local/var/postgres start
echo "PostgreSQL service started successfully."
# Set environment variables
echo 'export PGDATA="/usr/local/var/postgres"' >> ~/.bash_profile
echo 'export PGDATABASE="postgres"' >> ~/.bash_profile
echo 'export PGUSER="postgres"' >> ~/.bash_profile
echo 'export PGPASSWORD="yourpassword"' >> ~/.bash_profile
echo 'export PGPORT="5432"' >> ~/.bash_profile
echo 'export PGHOST="localhost"' >> ~/.bash_profile
source ~/.bash_profile
echo "PostgreSQL configuration completed successfully."
echo "Downloading pgAdmin4..."
# Download and install pgAdmin4
curl -O https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.20/macos/pgadmin4-6.20.dmg
echo "Installing pgAdmin4..."
hdiutil attach pgadmin4-6.20.dmg
cp -r /Volumes/pgAdmin\ 4/pgAdmin\ 4.app /Applications/
hdiutil detach /Volumes/pgAdmin\ 4
echo "pgAdmin4 installed successfully."
echo "Cleaning up installers..."
# Clean up
rm postgresql-16.0-1-osx.dmg
rm pgadmin4-6.20.dmg
echo "PostgreSQL 16 and pgAdmin4 installation completed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment