I have installed node.js
from repositories (v0.10.25
, Ubuntu 14.04.3, nodejs-legacy
package).
I need a specific version (v0.10.35
) for a project.
I installed n
(sudo npm install -g n
) and installed the needed node.js
version using it (sudo n 0.10.35
).
Now this thing happens:
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ which node
/usr/local/bin/node
$ node --version
v0.10.25
$ /usr/local/bin/node --version
v0.10.35
Questions:
What is going on here? Shouldn't be the same executable used in both cases with the same version being reported?
I can try to uninstall
node.js
installed from repositories, but is this safe?
you have 2 different version of node installed and the one in:
is the one you have just installed. however, if you check node in:
Then you will see where it is linked, all you need is to change the symlink path to desired version of node.
This way of messing version is not recommended if you are not experienced.
hope this helps
bash
caches paths to commands:So the issue was that I first launched
node
which was found in/usr/bin
. Then I installed another version ofnode
into/usr/local/bin
which should take precedence according to$PATH
, but the path was cached by bash. So launchingnode
used the old path, whilewhich node
did not use bash's cache.To fix the issue, I should have logged out then in. Or manually clear the entire cache: