# remove the old postgres version (not data) sudo apt-get remove -y postgresql postgresql-9.3 # add package sources list, key and update sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list" wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update -y --fix-missing sudo apt-get install -y libpq-dev postgresql-9.4
References
1. http://ubuntuhandbook.org/index.php/2014/02/install-postgresql-ubuntu-14-04/
2. https://gorails.com/setup/ubuntu/14.04
3. http://superuser.com/questions/416497/how-do-i-extract-just-the-name-or-version-number-from-my-ubuntu-release-on-the