Skip to main content

Node.js

是否在大陆内网

安装

nodejs 偶数版号代表稳定性,我们应该选择偶数版。 请见发行时间表

使用包管理器安装

Package Manager:
dnf module list nodejs

Fedora 35 默认为 16 版。若要切换其它版本:

sudo dnf module enable -y nodejs:X
sudo dnf in -y nodejs

使用 nvm 脚本安装

Debian 默认提供的 nodejs 12 版本太低,很多 npm 依赖包不支持。

在 Debian 中,推荐使用 nvm 安装 LTS 新版:

# curl: `curl -o- $url | bash`
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
( source ~/.nvm/nvm.sh && nvm install --lts )
exec $SHELL

安装到 Windows

scoop bucket add versions
scoop search nodejs
scoop install nodejs?

npm 镜像

使用 npmmirror 阿里镜像站

一次性使用参数:

--registry=https://registry.npmmirror.com

要想永久切换,打开编辑器:

notepad %userprofile%/.npmrc

粘贴内容:

registry=https://registry.npmmirror.com
disturl=https://npmmirror.com/dist
sass_binary_site=https://npmmirror.com/mirrors/node-sass/
phantomjs_cdnurl=https://npmmirror.com/mirrors/phantomjs/
electron_mirror=https://npmmirror.com/mirrors/electron/
chromedriver_cdnurl=https://npmmirror.com/mirrors/chromedriver
operadriver_cdnurl=https://npmmirror.com/mirrors/operadriver
selenium_cdnurl=https://npmmirror.com/mirrors/selenium
node_inspector_cdnurl=https://npmmirror.com/mirrors/node-inspector
fsevents_binary_host_mirror=https://npmmirror.com/mirrors/fsevents/

使用 yarn

比 npm 更好的包管理工具

Install by Package Manger:
sudo pacman -S --noconfirm yarn

或者使用 npm 全局安装:

sudo npm install --global yarn
On Windows, add to user environment variable PATH:
[Environment]::SetEnvironmentVariable("PATH",
[Environment]::GetEnvironmentVariable("PATH", "User") +
";$(yarn global bin)",
"User")

使用 PNPM

比 npm 更好的包管理工具

sudo npm install -g pnpm

赞助作者 (Sponse me):