How to install and configure the Postgres database server on Linux Mint
CS-160: Software Engineering
Instructor: Rob Bruce
Fall 2016

OBJECTIVE: to install and configure Postgres on Linux Mint.

  • Launch a terminal window (also known as a command line prompt or shell).

Step 1 of 10: in terminal window, log in as root

  • In your terminal window type the following at the command prompt: su
  • You will be prompted to enter the root password. Enter that password.
  • Your terminal window should now display a "#" (hash mark) prompt. This indicates you are logged in as root!

Step 2 of 10: update software library cache

  • First we need to update our cache of software libraries that are available to install or update.
  • In your terminal window type the following at the command prompt (you should be root): apt-get update

Step 3 of 10: install Postgres

  • Now that we've updated our cache, the next step is to install the Postgres database server.
  • In your terminal window type the following at the command prompt (you should be root): apt-get install postgresql postgresql-server-dev-all

Step 4 of 10: log into the Postgres server

  • Now that we've installed Postgres, the next step is to log into the Postgres server.
  • In your terminal window type the following at the command prompt (you should be root): su postgres
  • In your terminal window type the following at the command prompt (you should now be user postgres): psql
  • You should now be logged into Postgres.

Step 5 of 10: change Postgres password

  • Now that we are logged into Postgres, it's time to change the password when connecting to the Postgres database as user "postgres". We will change the Postgres password to student.
  • In your terminal window while logged into Postgres database (include the semicolon after this SQL statement): ALTER USER postgres WITH PASSWORD 'student';

Step 6 of 10: exit Postgres

  • Now that we've changed the Postgres password, it's time to log out of the database.
  • In your terminal window while logged into Postgres database enter the following command (no semicolon needed): \q

Step 7 of 10: logout of terminal window as user Postgres

  • Now it's time to log out as Postgres user in the terminal window.
  • At the command prompt in the terminal window type exit

Step 8 of 10: logout of terminal window as user root

  • Now it's time to log out as root user in the terminal window.
  • At the command prompt in the terminal window type exit

Step 9 of 10: log in to Postgres

  • Your terminal window should still be present. Now your window is probably user student. This is a non-priviledged user (i.e. not root).
  • Now it's time to log into the Postgres database again but this time it'll be much easier now that we've updated the Postgres password.
  • At the command prompt type in the terminal window type the following: psql -U postgres -h localhost
  • Postgres will then prompt you to enter the password. Enter student
  • You should now be logged into Postgres.

Step 10 of 10: create a database in Postgres

  • Now that you are logged into the Postgres server, we need to create a new database. This database will serve as container for one or more relational tables. We will create a database called cs160.
  • In your terminal window at the postgres command prompt (include the semicolon after this SQL statement): CREATE DATABASE cs160;