So you’re starting your database journey using a MacOS and you want to use PostgreSQL, harnessing Structured Query Language used to interact with a Relational Database.
If you’re using a different platform, hit up this link if you’re using a Linux or Windows operating system
You can install Postgres on your machine in a variety of ways, you can simply go on this link to install it directly from the Postgres website, but in this guide, you will learn how to install Postgres on a mac using Homebrew command lines, that way, the installation will be smooth and easier as the external dependencies that we need is automatically managed while installing this way, now to install Postgresql on a Mac, these are the steps you should follow:
First, you’ll need a Homebrew, just click on the link and follow the steps and instructions to install it on your computer.
Once you’re finished installing and setting up the homebrew, run this command line:
and as soon the installation is finished, run this command:
this command boots PostgreSQL as a daemon making it run in the background and listen for connections.
and to update, simply run this command on Homebrew first run:
then:
and there you have it, it will update it without all the hassle.
and to check if your Postgre is updated and working flawlessly, run:
this command will grant you access to the Postgres database and it will show by default your macOS username because when installing Homebrew, it will also automatically create your user. Now you can create a new database by running:
Then, create a new line and we will switch to the newly created database with this simple command:
you will now see a prompt that looks something like this:
and while we’re at it, we can now create a simple table by just using the syntax:
after running this command and you encountered no errors, you now have a table within your system and to see it, just run this:
now it will show you a table and you can check if there’s an error on the said tables, if you want to delete the table, just run:
to exit PostgreSQL, run \q or just simply type quit and it will exit the program instantaneously.
Simple, easy, and efficient, installing Postgre thru Homebrew has its advantages like updating the program with just commands, and now you know just how easy to do it, and you can start your journey in the world of databases!
Related Articles:
MongoDB vs PostgreSQL: A Comparison
How to Download, Install and Verify PostgreSQL for Windows
Different PostgreSQL Data Types