安装最新版本的Nodejs


安装最新版本的Nodejs
==================

1
2
3
4
5
6
7
sudo apt-get install npm
sudo npm install [email protected] -g
sudo npm cache clean -f
sudo npm install -g n
sudo n latest

sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs

ref: https://segmentfault.com/a/1190000007542620
如果遇到以下问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sudo npm install -g n 
/usr/local/lib/node_modules/npm/bin/npm-cli.js:79
let notifier = require('update-notifier')({pkg})
^^^

SyntaxError: Block-scoped declarations (let, const, function, class)
not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3

则只需要删除安装的npm

1
2
cd /usr/local/lib/node_modules
mv npm/ /tmp/usr_local_lib_node_modules_npm

然后重新执行

1
2
sudo npm install -g n 
sudo n stable

Limin Wang wechat
Welcome!
I'm happy it's useful to you!
Show comments from Gitment