Lesson Weekend

Starting in week 3 of Ruby and Rails, we'll be using a tool called Postgres for SQL database management. Even though we won't be using this tool for a few weeks, it's important to install it now so you'll have ample time to troubleshoot if there are any issues.


Postgres requires a fair amount of configuration to run correctly on Windows. You might find it helpful to use this Stack Overflow answer to guide you.

If you have Windows, begin by registering and installing Postgres from its main site. Make sure to install version 12.3, for Windows. Use the default values for the setup, and make sure to keep note of the password you use for Postgres. For the purposes of this lesson, we will assume the password epicodus.

Add Postgres to your PATH by running the following:

$ echo 'export PATH="/c/Program Files/PostgreSQL/12/bin:$PATH"'

Open the application pgAdmin 4, which should be located in the directory C:\Program Files\PostgreSQL\12\pgAdmin 4\bin. On the left site of the page you should see the "Browser" panel. In this panel, there should be a tree including Servers, containing PostgreSQL 12. Right-click on Login/Group Roles, under PostgreSQL 12, and select Create > Login/Group Role.... The Name for this role should be the same as the name of your Operating System username -- so, whatever user you would see at C:\Users. In the Privileges tab, set all privileges for your account to Yes.

Finally, to start the Postgres server, you'll need to run:

$ pg_ctl -D "C:\Program Files\PostgreSQL\12\data" start

Once you've completed the set up instructions, ensure you can run the psql command in the terminal. You can type \q to exit from this prompt.


If you've already set up Ruby according to the earlier lessons, you have Homebrew installed. Homebrew makes it really easy to install Postgres. To install the version of Postgres used at Epicodus, run the following command:

$ brew install [email protected]

Note: While you may choose to install the latest version of Postgres on your home environment, do not ever try to change the version on Epicodus computers. Remember that in a professional environment, you will be expected to adapt to the environment used at your workplace, not the other way around!

After it finishes installing, you'll need to configure your computer a bit. First, you need to tell Postgres where to find the database cluster where your databases will be stored:

echo "export PGDATA=/usr/local/var/postgres" >> ~/.bash_profile

This command will help some programs find Postgres more easily:

echo "export PGHOST=/tmp" >> ~/.bash_profile

To load these configuration changes, run:

source ~/.bash_profile

To start the Postgres server, simply run:


You'll have to leave that window open while you need the server. To stop the server, press Ctrl + C (_not_ Cmd + C). If you want Postgres to boot at startup and run in the background, run:

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

And to start it now (since it won't boot automatically until you restart your computer), run:

pg_ctl start

The computers at Epicodus are configured to have Postgres launch at startup, so you don't need to start it manually in class.

To prepare for the next lesson, create a default database with your computer's username:

createdb $USER

And you're done.

Lesson 5 of 6
Last updated February 11, 2021