1、先在系统上安装好nodejs和npm
sudo apt-get install nodejs-legacy
这一部出错请参考:这里
sudo apt-get install npm
2、升级npm为最新版本
sudo npm install npm@latest -g
3、安装用于安装nodejs的模块n
sudo npm install -g n
4、通过n模块安装指定的nodejs
sudo n latest
sudo n stable
sudo n lts
5、查看版本
sudo node -v
sudo npm -v
报错:
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
cd /usr/local/lib/node_modules
mv npm/ /tmp/usr_local_lib_node_modules_npm
然后重新执行
sudo npm install -g n
sudo n stable
就好了,结果如下
sudo n stable
install : node-v10.6.0
mkdir : /usr/local/n/versions/node/10.6.0
fetch : https://nodejs.org/dist/v10.6.0/node-v10.6.0-linux-x64.tar.gz
######################################################################## 100.0%
installed : v10.6.0
转:https://segmentfault.com/a/1190000007542620
webpack出错
sh: 1: webpack: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! superset@0.26.3 build: `NODE_ENV=production webpack --colors --progress`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the superset@0.26.3 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/andy/.npm/_logs/2018-08-28T09_43_09_707Z-debug.log
缺少webpack包
pip install webpack
然后(会出现两个错误,但是不影响)
sudo ./js_build.sh
执行命令
npm run build