之前使用命令安装的node版本太低,只有v4.6,且使用命令更新报错。
/usr/local/lib/node_modules/npm/bin/npm-cli.js:85
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
于是摸索出以下安装方法:
1. 下载node:https://nodejs.org/zh-cn/download/
2. 解压,复制到/opt/: cp /home/by/node-v10.14.2 /opt/
3. 修改/etc/profile : sudo gedit /etc/profile
#node
export NODE_HOME=/opt/node-v10.14.2
export PATH=$NODE_HOME/bin:$PATH
4.安装 npm 和 node 命令到系统命令 sudo ln -s /opt/node-v
10.14.2/bin/node /usr/local/bin/node
sudo ln -s /opt/node-v
10.14.2/bin/npm /usr/local/bin/npm
这样在所有用户下node和npm版本都一致。