I have a program on my path. The program runs when executed with a full path specified. But the program cannot be found when I run it with just its name.
Essentially, I want to understand how the below output is possible, and how to fix it so that my program can actually be found without a full path specified:
root:/usr/local/bin# ./siege **************************************************** siege: could not open /usr/local/bin/etc/siegerc run 'siege.config' to generate a new .siegerc file **************************************************** root:/usr/local/bin# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games root:/usr/local/bin# siege bash: /usr/bin/siege: No such file or directory root:/usr/local/bin# wtf!?!?
I’m on Ubuntu 12.04 using bash. Also please note the warning output from siege is not relevant for the purposes of this question, as I am only interested in whether or not the program can be found and invoked.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Note the output here:
root:/usr/local/bin# siege bash: /usr/bin/siege: No such file or directory
Bash maintains an internal hash of previously found executables in your path. In this case, it has details that at one time there was an executable at /usr/bin/siege, and reuses that path to avoid having to search again. You need to tell bash to manually rehash the path for siege like so:
hash siege
You can also clear all hashed locations:
hash -r
Method 2
Another cause of this problem might be that the path to the executable itself is on the path, instead of the executable’s containing directory.
So instead of putting
/home/myDir/theExecutable
on the path, merely add this
/home/myDir
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0