通过包管理器安装 Node.js

通过包管理器安装 Node.js

¥Installing Node.js via Package Managers

此页面上的软件包由其各自的打包者维护和支持,而不是 Node.js 核心团队。请将你遇到的任何问题报告给软件包维护者。如果事实证明你的问题是 Node.js 本身的一个错误,维护者将向上游报告该问题。

¥The packages on this page are maintained and supported by their respective packagers, not the Node.js core team. Please report any issues you encounter to the package maintainer. If it turns out your issue is a bug in Node.js itself, the maintainer will report the issue upstream.



Alpine Linux

Node.js LTS 和 npm 包在主存储库中可用。

¥Node.js LTS and npm packages are available in the Main Repository.

apk add nodejs npm

Node.js Current 可以从社区存储库安装。

¥Node.js Current can be installed from the Community Repository.

apk add nodejs-current

Android

Node.js 对 Android 的支持仍处于试验阶段,因此 Node.js 开发者尚未提供预编译的二进制文件。

¥Android support is still experimental in Node.js, so precompiled binaries are not yet provided by Node.js developers.

但是,有一些第三方解决方案。例如,Termux 社区为 Android 提供了终端模拟器和 Linux 环境,以及自己的包管理器和许多预编译应用的 广泛收集。Termux 应用中的此命令将安装最新可用的 Node.js 版本:

¥However, there are some third-party solutions. For example, Termux community provides terminal emulator and Linux environment for Android, as well as own package manager and extensive collection of many precompiled applications. This command in Termux app will install the last available Node.js version:

pkg install nodejs

目前,Termux Node.js 二进制文件与 system-icu 链接(取决于 libicu 包)。

¥Currently, Termux Node.js binaries are linked against system-icu (depending on libicu package).

Arch Linux

Node.js 和 npm 包在社区存储库中可用。

¥Node.js and npm packages are available in the Community Repository.

pacman -S nodejs npm

CentOS、Fedora 和 Red Hat Enterprise Linux

¥CentOS, Fedora and Red Hat Enterprise Linux

Node.js 在 CentOS/RHEL 8 和 Fedora 中作为名为 nodejs 的模块提供。

¥Node.js is available as a module called nodejs in CentOS/RHEL 8 and Fedora.

dnf module install nodejs:<stream>

其中 <stream> 对应于 Node.js 的主要版本。要查看可用流的列表:

¥where <stream> corresponds to the major version of Node.js. To see a list of available streams:

dnf module list nodejs

例如,要安装 Node.js 18:

¥For example, to install Node.js 18:

dnf module install nodejs:18/common

替代方案

¥Alternatives

这些资源提供与 CentOS、Fedora 和 RHEL 兼容的软件包。

¥These resources provide packages compatible with CentOS, Fedora, and RHEL.

基于 Debian 和 Ubuntu 的 Linux 发行版

¥Debian and Ubuntu based Linux distributions

Node.js 二进制发行版 可从 NodeSource 获得。

¥Node.js binary distributions are available from NodeSource.

替代方案

¥Alternatives

与基于 Debian 和 Ubuntu 的 Linux 发行版兼容的软件包可通过 Node.js snaps 获得。

¥Packages compatible with Debian and Ubuntu based Linux distributions are available via Node.js snaps.

Exherbo Linux

Node.js 和 npm 包在 arbor 存储库 中可用。

¥Node.js and npm packages are available in the arbor repository.

cave resolve -x node

fnm

使用 Rust 构建的快速简便的 No​​de.js 版本管理器,用于管理多个已发布的 Node.js 版本。它允许你执行安装、卸载、根据当前目录自动切换 Node 版本等操作。要安装 fnm,请使用此 安装脚本

¥Fast and simple Node.js version manager built in Rust used to manage multiple released Node.js versions. It allows you to perform operations like install, uninstall, switch Node versions automatically based on the current directory, etc. To install fnm, use this install script.

fnm 具有跨平台支持(macOS、Windows、Linux)和所有流行的 shell(Bash、Zsh、Fish、PowerShell、Windows 命令行提示符)。fnm 的构建考虑了速度,并支持 .node-version.nvmrc 文件的兼容性。

¥fnm has cross-platform support (macOS, Windows, Linux) & all popular shells (Bash, Zsh, Fish, PowerShell, Windows Command Line Prompt). fnm is built with speed in mind and compatibility support for .node-version and .nvmrc files.

FreeBSD

最新版本的 Node.js 可通过 www/node 端口获得。

¥The most recent release of Node.js is available via the www/node port.

通过 pkg 安装二进制包:

¥Install a binary package via pkg:

pkg install node

或者使用 ports 自行编译:

¥Or compile it on your own using ports:

cd /usr/ports/www/node && make install

Gentoo

Node.js 在 portage 树中提供。

¥Node.js is available in the portage tree.

emerge nodejs

IBM i

IBM 提供 Node.js 的 LTS 版本,并通过 'yum' 包管理器 提供。软件包名称为 nodejs,后跟主版本号(例如 nodejs18nodejs20 等)

¥LTS versions of Node.js are available from IBM, and are available via the 'yum' package manager. The package name is nodejs followed by the major version number (for instance, nodejs18, nodejs20 etc)

要从命令行安装 Node.js 20.x,请以具有 *ALLOBJ 特殊权限的用户身份运行以下命令:

¥To install Node.js 20.x from the command line, run the following as a user with *ALLOBJ special authority:

yum install nodejs20

Node.js 也可以与 IBM i Access Client Solutions 产品一起安装。有关更多详细信息,请参阅 本支持文档

¥Node.js can also be installed with the IBM i Access Client Solutions product. See this support document for more details

macOS

直接从 nodejs.org 网站下载 macOS 安装程序

¥Download the macOS Installer directly from the nodejs.org web site.

如果你想使用 bash 下载软件包:

¥If you want to download the package with bash:

curl "https://nodejs.cn/dist/latest/$(curl -s https://nodejs.cn/dist/latest/ | grep "pkg" | cut -d'"' -f 2)" -o "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"

替代方案

¥Alternatives

使用 Homebrew

¥Using Homebrew:

brew install node

使用 MacPorts

¥Using MacPorts:

port install nodejs<major version>

# Example
port install nodejs7

使用 pkgsrc

¥Using pkgsrc:

安装二进制包:

¥Install the binary package:

pkgin -y install nodejs

或者从 pkgsrc 手动构建:

¥Or build manually from pkgsrc:

cd pkgsrc/lang/nodejs && bmake install

n

n 是一个易于使用的适用于 Mac 和 Linux 的 Node.js 版本管理器。使用丰富的语法指定要安装的目标版本,或从以前下载的版本菜单中选择。版本安装在系统范围或用户范围内,对于更有针对性的使用,你可以直接从缓存的下载中运行版本。

¥n is a simple to use Node.js version manager for Mac and Linux. Specify the target version to install using a rich syntax, or select from a menu of previously downloaded versions. The versions are installed system-wide or user-wide, and for more targeted use you can run a version directly from the cached downloads.

请参阅 homepage 了解安装方法(bootstrap、npm、Homebrew、第三方)和所有使用细节。

¥See the homepage for install methods (bootstrap, npm, Homebrew, third-party), and all the usage details.

如果你已经拥有 npm,那么安装 n 和最新的 LTS node 版本非常简单:

¥If you already have npm then installing n and then the newest LTS node version is as simple as:

npm install -g n
n lts

NetBSD

Node.js 在 pkgsrc 树中提供:

¥Node.js is available in the pkgsrc tree:

cd /usr/pkgsrc/lang/nodejs && make install

或者使用 pkgin 安装二进制包(如果适用于你的平台):

¥Or install a binary package (if available for your platform) using pkgin:

pkgin -y install nodejs

Nodenv

nodenv 是一个轻量级的 node 版本管理器,类似于 nvm。它简单且可预测。丰富的插件生态系统可让你根据自己的需求进行定制。使用 nodenv 为你的应用选择一个 Node 版本,并确保你的开发环境与生产环境相匹配。

¥nodenv is a lightweight node version manager, similar to nvm. It's simple and predictable. A rich plugin ecosystem lets you tailor it to suit your needs. Use nodenv to pick a Node version for your application and guarantee that your development environment matches production.

Nodenv 安装说明由 在其 Github 页面上 维护。请访问该页面以确保你遵循最新版本的安装步骤。

¥Nodenv installation instructions are maintained on its Github page. Please visit that page to ensure you're following the latest version of the installation steps.

nvm

Node 版本管理器是一个 bash 脚本,用于管理多个已发布的 Node.js 版本。它允许你执行安装、卸载、切换版本等操作。要安装 nvm,请使用此 安装脚本

¥Node Version Manager is a bash script used to manage multiple released Node.js versions. It allows you to perform operations like install, uninstall, switch version, etc. To install nvm, use this install script.

在 Unix / OS X 系统上,可以使用 nvm 安装从源代码构建的 Node.js,方法是将其安装到 nvm 所需的位置:

¥On Unix / OS X systems Node.js built from source can be installed using nvm by installing into the location that nvm expects:

env VERSION=`python tools/getnodeversion.py` make install DESTDIR=`nvm_version_path v$VERSION` PREFIX=""

此后,你可以使用 nvm 在已发布的版本和从源代码构建的版本之间切换。例如,如果 Node.js 的版本是 v8.0.0-pre:

¥After this you can use nvm to switch between released versions and versions built from source. For example, if the version of Node.js is v8.0.0-pre:

nvm use 8

一旦正式发布,你将需要卸载从源代码构建的版本:

¥Once the official release is out you will want to uninstall the version built from source:

nvm uninstall 8

nvs

Windows

nvs 版本管理器是跨平台的,可以在 Windows、macOS 和类 Unix 系统上使用

¥The nvs version manager is cross-platform and can be used on Windows, macOS, and Unix-like systems

要在 Windows 上安装 nvs,请转到此处的 发布页面 并下载最新版本的 MSI 安装程序文件。

¥To install nvs on Windows go to the release page here and download the MSI installer file of the latest release.

你也可以使用 chocolatey 来安装它:

¥You can also use chocolatey to install it:

choco install nvs

macOS,UnixLike

你可以在 macOS/Unix 类系统 此处 中找到有关 nvs 安装步骤的文档

¥You can find the documentation regarding the installation steps of nvs in macOS/Unix-like systems here

用法

¥Usage

之后,你可以使用 nvs 在不同版本的 node 之间切换。

¥After this you can use nvs to switch between different versions of node.

要添加最新版本的 node:

¥To add the latest version of node:

nvs add latest

或者添加最新的 LTS 版本的 node:

¥Or to add the latest LTS version of node:

nvs add lts

然后运行 ​​nvs use 命令,为当前 shell 将 node 版本添加到 PATH

¥Then run the nvs use command to add a version of node to your PATH for the current shell:

$ nvs use lts
PATH -= %LOCALAPPDATA%\nvs\default
PATH += %LOCALAPPDATA%\nvs\node\14.17.0\x64

要将其永久添加到 PATH,请使用 nvs link

¥To add it to PATH permanently, use nvs link:

nvs link lts

OpenBSD

Node.js 可通过 ports 系统提供。

¥Node.js is available through the ports system.

/usr/ports/lang/node

在 OpenBSD 上使用 pkg_add

¥Using pkg_add on OpenBSD:

pkg_add node

openSUSE 和 SLE

¥openSUSE and SLE

Node.js 在以下软件包下的主要存储库中提供:

¥Node.js is available in the main repositories under the following packages:

  • openSUSE Leap 15.2:nodejs10, nodejs12, nodejs14

  • openSUSE Tumbleweed:nodejs20

  • SUSE Linux Enterprise Server (SLES) 12:nodejs10nodejs12nodejs14("Web 和脚本模块" 必须是 enabled。)

    ¥SUSE Linux Enterprise Server (SLES) 12: nodejs10, nodejs12, and nodejs14 (The "Web and Scripting Module" must be enabled.)

  • SUSE Linux Enterprise Server (SLES) 15 SP2:nodejs10nodejs12nodejs14("Web 和脚本模块" 必须是 enabled。)

    ¥SUSE Linux Enterprise Server (SLES) 15 SP2: nodejs10, nodejs12, and nodejs14 (The "Web and Scripting Module" must be enabled.)

例如,要在 openSUSE Leap 15.2 上安装 Node.js 14.x,请以 root 身份运行以下命令:

¥For example, to install Node.js 14.x on openSUSE Leap 15.2, run the following as root:

zypper install nodejs14

可以同时安装和使用不同的 Node 主要版本。

¥Different major versions of Node can be installed and used concurrently.

SmartOS 和 illumos

¥SmartOS and illumos

SmartOS 映像预装了 pkgsrc。在其他 illumos 发行版上,首先安装 pkgsrc,然后可以正常安装二进制包:

¥SmartOS images come with pkgsrc pre-installed. On other illumos distributions, first install pkgsrc, then you may install the binary package as normal:

pkgin -y install nodejs

或者从 pkgsrc 手动构建:

¥Or build manually from pkgsrc:

cd pkgsrc/lang/nodejs && bmake install

Snap

Node.js snaps 在 Snap 商店中可用作 node

¥Node.js snaps are available as node on the Snap store.

Solus

Solus 在其主存储库中提供 Node.js。

¥Solus provides Node.js in its main repository.

sudo eopkg install nodejs

vfox

跨平台(Windows、macOS、Linux)和可扩展的版本管理器。

¥A cross-platform(Windows, macOS, Linux) and extendable version manager.

它允许你为不同的项目使用不同的版本,为不同的 shell 使用不同的版本,并根据当前目录自动切换 Node 版本等。

¥It allows you to different versions for different projects, different versions for different shells, and switch Node versions automatically based on the current directory, etc.

它支持所有流行的 shell(Bash、Zsh、Fish、PowerShell、Clink、Cmder)。

¥It support all popular shells (Bash, Zsh, Fish, PowerShell, Clink, Cmder).

请参阅 快速入门 了解快速使用 vfox 和所有使用细节。

¥See the Quick Start for quickly using vfox, and all the usage details.

Void Linux

Void Linux 在主存储库中稳定地发布 Node.js。

¥Void Linux ships Node.js stable in the main repository.

xbps-install -Sy nodejs

Windows

直接从 nodejs.org 网站下载 Windows 安装程序

¥Download the Windows Installer directly from the nodejs.org web site.

替代方案

¥Alternatives

使用 Winget

¥Using Winget:

winget install OpenJS.NodeJS
# or for LTS
winget install OpenJS.NodeJS.LTS

运行上述两个命令之一后,可能需要重新启动终端模拟器,然后 node CLI 命令才可用。

¥After running one of the two commands above, it may be necessary to restart the terminal emulator before the node CLI command becomes available.

使用 Chocolatey

¥Using Chocolatey:

cinst nodejs
# or for full install with npm
cinst nodejs.install

使用 Scoop

¥Using Scoop:

scoop install nodejs
# or for LTS
scoop install nodejs-lts

z/OS

IBM® SDK for Node.js - z/OS® 有两种安装格式:SMP/E 和 PAX。选择适合你的安装格式:

¥IBM® SDK for Node.js - z/OS® is available in two installation formats, SMP/E and PAX. Select the installation format that applies to you: