Terminal – Command Found with `which` but Runs from Old Path

command lineenvironment-variablespathterminal

I have installed new version of npm in the custom directory .npm-global/bin and removed it from /usr/local/bin. The new path is declared:

PATH=/usr/local/bin:./node_modules/.bin:/Users/dmitrizaitsev/.npm-global/bin:...

and the new npm is found with which:

which npm
/Users/dmitrizaitsev/.npm-global/bin/npm

However, it still attempts to run from the old path and fails:

npm
-bash: /usr/local/bin/npm: No such file or directory

Any idea what is wrong here?

Best Answer

The old path is still cached by the shell. Either open a new tab/window or run hash -r to clear it.