如何升级nodejs到最新版本
HOW-TO: upgrade nodejs to latest version
Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node
To upgrade to latest version (and not current stable) version, you can use
sudo n latest
To undo:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n
Found in David Walsh blog http://davidwalsh.name/upgrade-nodejs
======================
后记:这个方法在centos6.5上面不能成功,后来项目中还是下载了nodejs的源代码自己编译。
对于centos linux, 另外一个办法是从nodesource.com下载。不过他家服务器不稳定,常常抽风。如果需要每次在CI/CD过程中安装升级nodejs,需要谨慎使用nodesource。