Ubuntu 16.04.2 LTS
2.1.7
npm i -g n while on node v4.2.6 which is installed with default apt-get registry for my version of Ubuntu.
npm i -g n
n latest
node -v
It outputs v4.2.6, but I was expecting v8.1.4
5.0.3
> which n
/usr/local/bin/n
> node -v
v4.2.6
To work around the problem for now, I've symlinked /usr/local/bin/node to the version installed in /usr/local/n/. Another option is to manually update PATH.
what is the output of which node? It seems the symlink didn't happen or the node you are using isn't the one from n. I have a docker container that is Ubuntu:16.04 you can try at troy0820/node-n:latest. I'm trying to reproduce your issue, but I'm not having any luck.
I'm getting the same result.
>which node
/usr/local/bin/node
>ls -la /usr/local/bin/
lrwxrwxrwx 1 root root 27 Jul 19 13:52 n -> ../lib/node_modules/n/bin/n
-rwxr-xr-x 1 root root 29851602 Jul 19 13:52 node
lrwxrwxrwx 1 root root 38 Jul 19 13:52 npm -> ../lib/node_modules/npm/bin/npm-cli.js
Edit: Looks like it's an overuse of sudo that's tripping me up here.
~ ❯ which node
/usr/local/bin/node
Hmmm, maybe that's not the default one? I think sudo apt-get install nodejs installs /usr/bin/nodejs, but I'm not sure about /usr/local/bin/node.
I seem to run into the same issue where n links the new version to /usr/local/bin/nodejs whereas my install has Node running from /usr/local/bin/node.
I've installed Node using the following:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs
For now fixing this using:
sudo n 8.4.0
sudo ln -sf /usr/local/n/versions/node/8.4.0/bin/node /usr/bin/node
Once linked, changing the version using n will automatically maintain the symlink correctly.
May actually be a duplicate of https://github.com/tj/n/issues/381
I've found that indeed after restarting the shell it did find the correct Node version.
Restarting shell didn't work for me. It turned out that something (I'm guessing heroku toolbelt?) had added a new binary for me.
➜ ~ sudo n 6.7.0
➜ ~ node --version
v8.1.4
➜ ~ which -a node
/usr/local/heroku/bin/node
/usr/local/bin/node
/usr/bin/node
➜ ~ sudo ls -ltr /usr/local/heroku/bin
total 33960
-rwxrwxr-x 1 500 500 34764936 Jul 11 03:10 node
-rw-r--r-- 1 root root 310 Jul 20 00:18 heroku.js
-rwxr-xr-x 1 root root 836 Jul 20 00:18 heroku
➜ ~ sudo rm /usr/local/heroku/bin/node
➜ ~ node --version
v6.7.0
Removing that worked.
I had something similar:
$ which -a node
/usr/local/bin/node
/usr/bin/node
$ /usr/local/bin/node -v
v8.4.0
$ which node
/usr/local/bin/node
$ /usr/bin/node -v
v5.4.1
$ node -v
v5.4.1
$ rehash
$ node -v
v8.4.0
So I needed to rehash (or quit and re-run the shell) to fix this.
This was from doing the git clone version of install and then the foregoing n-based installs, all in one shell. Hard to think how to fix this, except perhaps by making 'n' check whether 'which node' changes value and printing a BIG OBVIOUS WARNING about it for stupid people like me. :)
Here's hoping I won't suffer the npm install Buffer.alloc bug now.
Same problem still, as of March 2018 (well, it's the same n version, 2.1.7). Restarting bash did fix it.
It might help to remove the pre-installed version of node
sudo apt remove nodejs
I solved it.
I uninstalled node with apt-get and then set 777 permisions to /usr/local/bin/node
sudo apt-get remove nodejs
sudo chmod 777 -R /usr/local/bin/node
Previously I had installed node 8.11.3 with:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
and then I installed n with:
sudo npm -g install n
sudo n latest
But, when I changed the node version with n to 10.5.0 for example node -v showed 8.11.3. However, if I use sudo node -v it showed the correct version (10.5.0)
@guido4000 thx - that fixed it.
Restarting the shell was the most common fix.
This issue has not had any activity in over six months. It isn't likely to get acted on due to this report.
Feel free to open a new issue if it comes up again, with new information and renewed interest.
Thank you for your contributions.
n v6.1.2 has additional output for the situation when node command location changes, and the old location may be remembered by the current shell.
e.g.
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
(Longer transcript: https://github.com/tj/n/issues/588#issuecomment-554601529)
After installing bu using root permissions i simply type >exit in terminal and relogin again as sudo
my node , and npm versions became a stable as I prefered before!
export PATH=$PATH:/usr/local/bin/node
export PATH=$PATH:/usr/local/bin/node
This solved it for me.
Most helpful comment
I seem to run into the same issue where
nlinks the new version to/usr/local/bin/nodejswhereas my install has Node running from/usr/local/bin/node.I've installed Node using the following:
For now fixing this using:
Once linked, changing the version using
nwill automatically maintain the symlink correctly.