In the dynamic landscape of web development, staying current with the latest versions of Node.js is crucial for performance, security, and compatibility. Node Version Manager (NVM) is an essential tool for simplifying this process. This article provides a comprehensive guide on using NVM to upgrade Node.js, ensuring a smooth and efficient workflow for developers.
Understanding NVM
Node Version Manager (NVM) is a command-line utility that enables you to manage multiple Node.js versions. It’s especially useful in environments where different projects require different Node.js versions, allowing you to switch between them effortlessly.
Why Use NVM for Upgrading Node.js?
- Versatility: Manage multiple Node.js versions on a single machine.
- Convenience: Easily switch between Node.js versions as per project requirements.
- Safety: Test new versions without affecting existing setups.
- Simplicity: Streamline the upgrade process with straightforward commands.
Installing NVM
Before upgrading Node.js, you need to install NVM. Follow these steps:
- Open your terminal.
- Run the installation script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
(Visit the NVM GitHub page for the latest version.)
- Restart your terminal or run
source ~/.bashrc
(or equivalent for your shell) to apply the changes.source ~/.bashrc
Upgrading Node.js with NVM
With NVM installed, upgrading Node.js is straightforward.
- Check Available Versions:
List all available Node.js versions with:nvm ls-remote
- Install a New Version:
Install the desired version (e.g., v20.0.0) using:nvm install 20.0.0
- Switch to the New Version:
Change to the newly installed version with:nvm use 20.0.0
- Set Default Node Version:
Set the default Node.js version for new terminals:nvm alias default 20.0.0
Verifying the Upgrade
Confirm that the upgrade was successful by checking the Node version:
node -v
Best Practices for Upgrading
- Read Release Notes: Before upgrading, review the release notes for potential breaking changes.
- Backup Projects: Always backup your projects before upgrading.
- Test Thoroughly: After upgrading, test your applications to ensure compatibility.
Troubleshooting
- Installation Issues: Ensure your shell is supported and the installation script ran without errors.
- Version Not Found: Check for typos in the version number or update NVM.
- Switching Versions: If nvm use doesn’t reflect changes, ensure your shell’s configuration file is correctly set up.
Conclusion
NVM is a powerful tool that simplifies the process of managing and upgrading Node.js versions. By following these steps, developers can maintain an efficient and flexible development environment. Remember to stay informed about the latest Node.js releases and upgrade regularly to leverage new features and improvements.
Further Resources:
- NVM GitHub Repository: For the latest updates and detailed documentation.
- Node.js Official Website: For official Node.js documentation and release notes.
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!