Install Node.js and npm with Homebrew. First, install Homebrew. /usr/bin/ruby -e '$(curl -fsSL Then run brew update to make sure Homebrew is up to date. Brew update As a safe measure you should run brew doctor to make sure your system is ready to brew. Run the command below and follow any recommendations from brew doctor. Homebrew - The Missing Package Manager for macOS. Npm - The package manager for JavaScript.
In this tutorial we will learn to install PostgreSQL database on Mac using Homebrew.
Prerequisite
It is assumed that you have Homebrew installed on your Mac.
If you don't have Homebrew installed on your Mac then open Terminal and run the following command.
You can visit Homebrew official website https://brew.sh to learn more about it.
Once you have Homebrew (a.k.a. brew) installed on your machine you can run the following command in the Terminal to check the version.
To update run the following command.
Alright, time to install PostgreSQL on Mac.
Install PostgreSQL using Homebrew
In Terminal run the following command to install PostgreSQL on Mac using Homebrew.
We can check the version of PostgreSQL using the psql
command.
Start PostgreSQL
To start PostgreSQL run the following command in the Terminal.
We will get a similar output shown below.
Stop PostgreSQL
To stop PostgreSQL run the following command in the Terminal.
We will get a similar output.
Restart PostgreSQL
Homebrew Npm Location
To restart PostgreSQL run the following command in the Terminal.
We will get a similar output as shown below.
Login to PostgreSQL database
By default we will get a database by the name postgres. So, to connect to it we will run the following command.
We will see the following output.
List all the users
To list all the users we use the du
command.
List all the databases
To list all the databases run the l
command.
Create a database
To create a database run the following command. In the given example mydb is the name of the database.
Connect to a database
Homebrew Npm Install
To connect to a database use the c
command.
List all the tables inside a database
To list all the tables inside a database we run the d
command.
Note! If there is no table then we will get a prompt stating no relations found.
Let us go ahead and create a simple users table inside the mydb database and try the above command again.
Create table
In the following example we are creating a simple users table.
Now if we list the tables using the d
command we will get the table.
How to exit from psql?
To exit or quit from psql type the q
command.
Alright, this brings us to the end of this tutorial. Hope you found it useful. Please share this tutorial if it was helpful. See you in the next tutorial. Have fun developing :-)
Hi! I am new to packages and just want to be sure on what's going here... I installed homebrew, npm and node at my mac with the terminal following this guide: https://treehouse.github.io/installation-guides/mac/node-mac.html
Is homebrew, npm and node saved just as files in finder? Or are they programs that should be among applications? For example I can't see home brew anywhere except when I used it in the terminal.
Homebrew Npm Download
When I search for npm on my computer I find 2 files called node_modules. One in the file flashcards and one in the file Debug node Applications with VS code (both are downloaded from courses at treehouse). Is this the npm-package? Why is it at 2 places? Since I am done with these courses I want to delete those files - is that 'ok'?
Bonus question: I installed Xcode because I read had to have that for installing the other stuff... and it is saved as a program. But I am not sure on when or how to use Xcode?
Homebrew Npm Path
To locate homebrew, npm and node try the which
command in terminal. For example I used which brew
and found
which is an alias for
Here is the npm doc for folder use and the npm doc for install. For local installs packages are installed in the node_modules folder in the project folder. So each project will have its own local node_modules folder. You should be able to delete the project folder if no longer needed.
Files installed with Xcode are used by other applications. You don't have to learn or use Xcode yourself.
Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.