Search code examples
shellhashpath-variables

Command not found, although it is in the $PATH


My system does not find phpunit, although it is definitely in my $PATH.

I am using ubuntu 16.04. Here is my PATH, which contains /usr/local/bin

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

composer and phpunit both lie in the same directory:

$ which composer;which phpunit
/usr/local/bin/composer
/usr/local/bin/phpunit

but when i call them, phpunit is not found althogh composer is found... since composer is found, my path should be okay...

$ composer --version;phpunit --version
Composer version 1.4.2 2017-05-17 08:17:52
-bash: /usr/bin/phpunit: Datei oder Verzeichnis nicht gefunden

when I call it with the entire path the which command says, it works....

$ /usr/local/bin/phpunit --version
PHPUnit 6.2.3 by Sebastian Bergmann and contributors.

and I don't have an alias:

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

am i missing something here?


Solution

  • Drop the bash's executables locations hash

    Run hash phpunit

    Explanation:

    There was a phpunit binary in /usr/bin/ folder (as can be seen from the error message).

    Now it has been moved to /usr/local/bin/.

    But bash stored the previously found locations of executables and doesn't update them immediately, so the old /usr/bin/phpunit location should be cleared for the new one to be found.

    Check this ServerFault answer for more info.