Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Here's my situation: I have two versions of postgres installed, and with the two versions, come two different psql interactive terminals.

One is located at /usr/bin/psql, and starts when I run # psql -U username

Another newer one is located at /usr/pgsql-9.1/bin/psql

I want the newer one to start by default when I run psql from the command line. How can this be done? Thanks!

Edit: I am using centos

share|improve this question

migrated from stackoverflow.com Jul 22 '12 at 2:44

This question came from our site for professional and enthusiast programmers.

2  
You cunningly kept your OS and package-format a secret. If you use Debian packages (apt - on Debian, Ubuntu, ...), this problem is resolved automatically, as explained under this related question. –  Erwin Brandstetter Jul 20 '12 at 22:58

2 Answers 2

Edit your PATH so that /usr/pgsql-9.1/bin/ (the newer one) comes before /usr/bin/.

A less package-manager-safe safe alternative is to move/remove/rename the psql in /usr/bin/ and create a symlink in /usr/bin/ to the new one (not tested):

> cd /usr/bin
# move the old one however you like
> ln -s /usr/pgsql-9.1/bin/psql .
share|improve this answer
4  
I strongly recommend that you do not alter /usr/bin/psql if you are on any distro other than maybe slackware. It will get replaced when an update to the postgresql packages are applied. It's a really, really, bad idea. Change your PATH instead. –  Craig Ringer Jul 21 '12 at 1:29

Alternatively, to avoid symlinks, and to avoid changing your $PATH, you could add your command to the hash table:

hash -p /usr/pgsql-9.1/bin/psql psql

This will put your command into the command hash table and it will be executed before any other command (in fact, no path search will be performed).

If you used a command called psql before, then it already sits in the hash table and it will be the first hit when searching for commands. In that case, remove the old entry first by typing

hash -d psql

and then issue the command above. You can source it in your .bashrc should you want to.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.