1

Here's my situation: I have two versions of PostgreSQL installed on my CentOS system, 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?

Kusalananda
  • 333,661
Nyx
  • 31

2 Answers2

2

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.

Wojtek
  • 2,330
1

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 .
Matt Ball
  • 121
  • 5
    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. –  Jul 21 '12 at 01:29