I just updated macOS to Mojave, updated brew and reinstalled php (version 7.3, still via brew).

If I run php I get

-bash: /usr/local/opt/[email protected]/bin/php: No such file or directory

But if I do which php I get


(that php -v reports as 7.1.23)

Makes no sense. Why does php calls a path different reported by which?
And how can I make the system use the last version rather than those wrong ones?

I tried to brew unlink php && brew link php but when I run php it still calls the version 7.2 instead of the 7.3 that I just installed.

1 Answer 1


In my case the issue was with the /usr/local/bin appearing in PATH environment variable after /usr/bin (reported by brew doctor).

I fixed easily adding

export PATH="/usr/local/bin:$PATH"

to .bash_profile (or .bashrc) in the user home directory.

Don't really like the solution since I'd like to know why /usr/bin comes before /usr/local/bin (that, in macOS, is supposed provide the chance to override the paths) in the first place.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .