Launch your terminal and type in the command below to install Homebrew. Do note that it works for both Intel MacBook and ARM-based MacBook so you don't have to worry about incompatibility.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Next, do update the brew to get the latest package version from the source.
If necessary, also run brew doctor to run diagnosis to check if there are any errors.
To install PostgreSQL version 13 (the latest version at the time of writing) run the command below. Do note that each new version released will still be named "postgresql".
brew install postgresql
If for some reason you prefer to install PostgreSQL version 11 or 12 do specify the version by appending the version number at the end.
brew install [email protected] brew install [email protected]
To start the PostgreSQL server, run the brew services command like below.
brew services start postgresql
If you want to stop it then run the stop command.
brew services stop postgresql
Lastly, to view any running services run the services command.
brew services list
Integrate with Laravel
If you are developing a Laravel web application and you want to make use of PostgreSQL, do change the environment configuration like below. The connection should be "pgsql", the port number is 5432, the username is "postgres" and the password is empty.
DB_CONNECTION=pgsql DB_HOST=127.0.0.1 DB_PORT=5432 DB_DATABASE=your_db_name DB_USERNAME=postgres DB_PASSWORD=
If you find this tutorial to be helpful do share it with others and cheers! 🍻