How to Upgrade Node.js via NPM
Abstract: Install Nodejs – Let’s install or update latest nodejs version on your system using n module. sudo n ltsSetup Binary Link - Now link your node binary
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.
- How to Install Multiple Node.js Versions via NVM
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.0 - Clean 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