文章最初发表于szhshp的第三边境研究所
转载请注明
Ubuntu 16.04 安装NodeJS
天哪Linux安装NodeJS居然也这么麻烦
NodeJS安装
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
可能会出现找不到 curl
的错误, apt-get
一下curl
就可以了
NPM安装
curl http://npmjs.org/install.sh | sudo sh
sudo apt-get install curl
node VS nodeJS?
NPM, Node安装成功后执行:
node -v
发现报错
-bash: /usr/sbin/node: No such file or directory
但是可以使用
nodejs -v
这个问题的原因:
There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed from node to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.
当然直接用nodejs命令
也可以执行node程序, 不过后续如果安装modules就会出现node 未定义
的错误
解决方法是添加一个link:
You need to manually create a symlink
/usr/bin/node
. Shortcut for bash compatible shells:sudo ln -s `which nodejs` /usr/bin/node
Or if you use non-standard shells, just hardcode the path you find with which nodejs:
sudo ln -s /usr/bin/nodejs /usr/bin/node
NPM: Permission Denied
npm安装Hexo出现问题:
node scripts/build_highlight_alias.js > highlight_alias.json
sh: 1: cannot create highlight_alias.json: Permission denied
换成sudo依然报错.
解决方法见官方Guide: https://docs.npmjs.com/getting-started/fixing-npm-permissions