跳到主要内容

在WSL上安装Node.js

· 阅读需 1 分钟
luke
luke

如何在wsl上安装node.js 环境

安装Node js 的管理器 nvm

nvm 是 Node Version Manager 的缩写,它是一个用于管理 Node.js 版本的命令行工具。通过 nvm,你可以在同一台机器上安装和切换多个 Node.js 版本,这对于测试在不同 Node.js 版本上的应用程序兼容性非常有用。

在 Linux 上安装 nvm,你可以使用 cURL 或 Wget 运行安装脚本。以下是步骤:

打开你的终端。 使用 cURL 下载安装脚本:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

或者使用 Wget:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

该脚本会将 nvm 仓库克隆到 ~/.nvm,并将源行添加到你的配置文件(~/.bash_profile,~/.zshrc,~/.profile 或 ~/.bashrc)。

关闭你的终端并打开一个新的终端。

通过检查 nvm 的版本来验证安装是否成功:

nvm --version

记得将 v0.38.0 替换为最新可用的版本。

安装NodeJS

使用nvm命令安装NodeJS

nvm install 18

切换Node js版本

nvm use 18

检查已经安装的Node js

nvm list

检查node js 版本

node -v