NPM is a package manager for nodejs and many other languages. Currently, I was running nodejs version v5.4.0 on my system. I was in required to install Latest nodejs package on my system. After searching I found the best and easier way to Upgrade Node.js version using NPM quickly. It works perfectly for me and hopes so for you.
Steps to Upgrade Node.Js
Use the following steps to install or upgrade node.js to latest available version.
Current NodeJs Version – First check current nodejs version on your system using following command. In my case it is v5.4.0.node -v
v5.4.0Clean Cache Forcefully – Now clean all npm cache from your system forcefully.sudo npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.Install n Module – After cleaning all cache from your system, now install n modules using npm command.sudo npm install -g n
/root/.npm-global/bin/n -> /root/.npm-global/lib/node_modules/n/bin/n + [email protected]Install Nodejs – Let’s install or update latest nodejs version on your system using n module.sudo n lts installing : node-v12.18.4 mkdir : /usr/local/n/versions/node/12.18.4 fetch : https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-x64.tar.xz installed : v12.18.4 (with npm 6.14.6)
Setup Binary Link - Now link your node binary with latest nodejs installed binary file using following command.sudo ln -sf /usr/local/n/versions/node/12.18.4/bin/node /usr/bin/node
Check Nodejs Version - Finally recheck your nodejs version. You will find that it showing latest version on your system.node -v
v12.18.4
45 Comments
Hi, Having an issue here.
sudo n lts
appears to work correctly
installing : node-v14.18.1 …
It told me it changed location…
old : /usr/bin/node
new : /usr/local/bin/node
But now I don’t have node.
node -v
bash: /usr/bin/node: No such file or directory
Thank you for any advice
Thank you very much its working.
great post! thanks a lot 😀
Thanks! All works!
thanks
Regards from Brazil, thanks!
Thanks, it worked at Fedora 28
Hi, thanks for this tutorial!
I had to do : $ NODE_MIRROR=http://nodejs.org/dist/ n –lts instead of : $ sudo n stable.
At the end, I did : $ sudo ln -sf /usr/local/n/versions/node/10.16.0/bin/node /usr/bin/node.
When I check the version, I have this message : bash /usr/bin/node no such file or directory.
Thanks for your answer.
You saved my life, mister!
I updated to node 12.2.0, however when I run “node -v”, still shows the previous version. And the command “sudo ln -sf /usr/local/n/versions/node/12.2.0/bin/node /usr/bin/node” doesn’t help.
Jone, First check which node binary is default executed…
Then you can symlink /usr/local/n/versions/node/12.2.0/bin/node to that binary file.
Thanks, it worked.
not working on ubuntu 16.04 LTS… come on
Doesn’t work on Fedora
Very clear instructions, thank you 🙂
Great!!!! Bravo!
You are Awesome bro
executed all steps without any single error but version is still as it is.
Thank you ..it so valuable information
Thank you
After typed this command, when I typed “node -v” show error “no such file or directory”. Give me a help please!
ln -sf /usr/local/n/versions/node/6.0.0/bin/node /usr/bin/node
Thanks a lot
Worked, Thanks!
Nice work! Good little guide, just enough detail to upgrade Node.Js safely – thanks
Thanks!
Thank you very much for this! I was trying to install LESS but was having a hard time. It turns out it’s just the version compatibility with my node. I finally get it to work.:D
Thanks man….. You are my hero …. There are many option to do that all over the net including nodejs.org. But i understand that once npm is installed as a package manager then it should be done by npm itself. I used fedora 24 with dnf to install the default package from the repo. Then upgrade npm and then node…. thanks again…. now i am learning npm cli command before anything.
Or if you installed using homebrew, you can omit the ‘sudo’…
Thank you bro , worked to me.
Awesome!
worked 🙂 thanks man
Very Nice @ Rahul
Thanu!!
Thank you so much, so helpful!
Works on Fedora 21. Thanks a lot!
Is this powershell, command prompt…(windows,Mac,Linux) sudo suggest linux ..so probabbly mac lynux. node -v is the only thing that worked for me. Should i just download the node windows install and run tha
Hi, I hope you can help me out. I tried to upgrade my Pi but I still have an older version of nodejs:
pi@raspberrypi:~ $ node -v
v5.6.0
pi@raspberrypi:~ $ nodejs -v
v0.10.29
Hi Joey,
Create a symbolic link for nodejs command also.
wtf this just broke the node command for me… when I punch in node -v or any node command now it gives me /usr/bin/node: No such file or directory. awesome.
I just had that same thing happen to me, how did you fix it?
Note that the line:
sudo ln -sf /usr/local/n/versions/node/5.0.0/bin/node /usr/bin/node
will need the 5.0.0 version number updated to match the stable version that was installed.
hello
about ‘Setup Binary Link’
i can’t find “`/usr/bin/node“` in my osx
and then i type “`node -v“`
the latest version already installed.
I survey other post , find other user no do this step.
https://github.com/tj/n/issues/307
Thank your share.
Doesn’t work on windows:
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your operating system or architecture: [email protected]
.0
npm ERR! notsup Valid OS: !win32
npm ERR! notsup Valid Arch: any
npm ERR! notsup Actual OS: win32
npm ERR! notsup Actual Arch: x64
have the same error on Win 8.1
Spot on, this works for me on CentOS 7 where many other instructions I found did not.
Thanks for your help!