首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >优雅地乱玩Linux-3-NodeJS的安装

优雅地乱玩Linux-3-NodeJS的安装

作者头像
szhshp
发布2022-09-21 09:52:42
发布2022-09-21 09:52:42
7750
举报

更新历史:

  • 2017 年 06 月 10 日
    • 攒写最初正文
  • 2017 年 11 月 05 日
    • 添加一些 Issue Solution

Ubuntu 16.04 安装 NodeJS

天哪 Linux 安装 NodeJS 居然也这么麻烦

NodeJS 安装

代码语言:javascript
复制
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

可能会出现找不到 curl的错误, apt-get一下curl就可以了

Issue Solution

注意:

上方执行 curl 可能会报错, 很可能说找不到 curl 这个命令

并且因为 curl 执行失败就会安装到稳定版的 node 而不是最新版的 node

稳定版的 node 很可能无法执行多数程序, 因此一定要保证安装的是最新版

NPM 安装

代码语言:javascript
复制
curl http://npmjs.org/install.sh | sudo sh
sudo apt-get install curl

node VS nodeJS?

NPM, Node 安装成功后执行:

代码语言:javascript
复制
node -v

发现报错

代码语言:javascript
复制
-bash: /usr/sbin/node: No such file or directory

但是可以使用

代码语言:javascript
复制
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 出现问题:

代码语言:javascript
复制
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

系列文章

优雅地乱玩 Linux

参考文献

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-06-10,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • Ubuntu 16.04 安装 NodeJS
    • NodeJS 安装
      • Issue Solution
    • NPM 安装
    • node VS nodeJS?
    • NPM: Permission Denied
  • 系列文章
  • 参考文献
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档