MacOS X
官网文档: 点此进入
macOS Installer
使用 bash 下载软件包:
curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"
Homebrew
brew install node
Debian / Ubuntu
Node.js 二进制发行版可从 NodeSource 获得。
基于 Debian 和 Ubuntu 的发行版 (deb)
Node.js Current
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs
Node.js LTS
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
安装命令
sudo apt-get update
sudo apt-get install nodejs
CentOS
Node.js LTS
# As root
curl -sL https://rpm.nodesource.com/setup_lts.x | bash -
# No root privileges
curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
Node.js Current
# As root
curl -sL https://rpm.nodesource.com/setup_current.x | bash -
# No root privileges
curl -sL https://rpm.nodesource.com/setup_current.x | sudo bash -
yarn 源
# 添加源
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
# 安装
sudo yum install yarn
安装
sudo yum install -y nodejs
sudo yum install yarn
nvm
Node Version Manager 是一个 bash 脚本,用于管理多个已发布的Node.js版本。它允许您执行安装,卸载,切换版本等操作。要安装nvm,请使用此安装脚本。
在Unix / OS X系统上,可以通过将nvm期望的位置安装到使用 nvm 来安装从源代码构建的Node.js
env VERSION=`python tools/getnodeversion.py` make install DESTDIR=`nvm_version_path v$VERSION` PREFIX=""
之后,您可以nvm用来在发布的版本和从源构建的版本之间切换。例如,如果Node.js的版本为v8.0.0-pre:
nvm use 8
正式发行后,您将需要卸载从源代码构建的版本:
nvm uninstall 8
————————————-
NPM 配置
配置 npm 源为 cnpm
# 查询源
npm config get registry
# 淘宝源(cnpm源)
npm config set registry https://registry.npm.taobao.org/
# 官方 npm
npm config set registry https://registry.npmjs.org/
# 配置 npm 用户;解决无权限问题
npm -g config set user root
Yarn 配置
yarn 的安装 : https://www.yuque.com/jonnychang/fe8cqg/spmzpd#Fx946
# 查询源
yarn config get registry
# 淘宝源
yarn config set registry "https://registry.npm.taobao.org"
# 官方源
yarn config set registry "https://registry.yarnpkg.com"
Linux 编译安装
- 参考地址:
https://github.com/nodejs/help/wiki/Installation#how-to-install-nodejs-via-binary-archive-on-linux