Bash – Installed program executable runs from wrong location

bashgnome-shellparcellitepathUbuntu

I installed parcellite in Ubuntu (downloaded from http://parcellite.sourceforge.net/)

After installing from sources, sudo make install, I can see that it is installed at below location.

However, when I try to run it, it tries to run it from another path. Why is that?

user$ which parcellite
/usr/local/bin/parcellite

user$ parcellite -h
bash: /usr/bin/parcellite: No such file or directory

$PATH is as below

/home/user/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

I tried changing ownership of executable as follows. Still the problem persists.

user$ ls -l /usr/local/bin/parcellite 
-rwxr-xr-x 1 root root 452K Oct  7 21:00 /usr/local/bin/parcellite
user$sudo chown user:user /usr/local/bin/parcellite
user$ ls -l /usr/local/bin/parcellite 
-rwxr-xr-x 1 user user 452K Oct  7 21:01 /usr/local/bin/parcellite

I had an older version of parcellite installed. But I removed it prior to installing new version.


Update: @Fox's solution works. But any idea why which command gives correct path, despite hashNOT being updated?

Best Answer

If you had a version installed, then installed another version elsewhere, then your shell will have cached (hashed) the original path. You can clear this cache with hash -r. Then the next time you run the command it will be rehashed with the new path.

Note that this cache is not global, if you have several running shells you will have to update each of them.

As to why which sees the correct path, "Why not use which" is a good source of information, but the short answer is that which is an external command that doesn't see the shell's path cache.

Related Question