0

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:

  1. What is going on here? Shouldn't be the same executable used in both cases with the same version being reported?

  2. I can try to uninstall node.js installed from repositories, but is this safe?

warvariuc
  • 358
  • 1
  • 5
  • 14

2 Answers2

0

you have 2 different version of node installed and the one in:

   /usr/local/bin/node

is the one you have just installed. however, if you check node in:

/usr/bin or /bin (check with locate or whereis)

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

ostendali
  • 403
  • 2
  • 4
0

bash caches paths to commands:

$ help hash
hash: hash [-lr] [-p pathname] [-dt] [name ...]
    Remember or display program locations.

    Determine and remember the full pathname of each command NAME.  If
    no arguments are given, information about remembered commands is displayed.

    Options:
      -d                forget the remembered location of each NAME
      -l                display in a format that may be reused as input
      -p pathname       use PATHNAME as the full pathname of NAME
      -r                forget all remembered locations
      -t                print the remembered location of each NAME, preceding
                each location with the corresponding NAME if multiple
                NAMEs are given
    Arguments:
      NAME              Each NAME is searched for in $PATH and added to the list
                of remembered commands.

    Exit Status:
    Returns success unless NAME is not found or an invalid option is given.

So the issue was that I first launched node which was found in /usr/bin. Then I installed another version of node into /usr/local/bin which should take precedence according to $PATH, but the path was cached by bash. So launching node used the old path, while which node did not use bash's cache.

To fix the issue, I should have logged out then in. Or manually clear the entire cache:

$ hash -r
warvariuc
  • 358
  • 1
  • 5
  • 14