当前位置:   article > 正文

3 款非常实用的 Node.js 版本管理工具_node版本管理工具

node版本管理工具

为了能够对 Node.js 版本进行版本管理,我整理了 3 款非常实用的 Node.js 版本管理工具,让大家能够自由的切换本地环境不同的 Node.js 版本。

1. nvm

⭐ Github stars: 60K+

nvm[2] 是一款 Node.js 版本管理工具,允许用户通过命令行快速安装、切换和管理不同的 Node.js 版本。

图片

(图片来自:github[3])

nvm 只适用于 macOS 和 Linux 用户的项目,如果是 Windows 用户,可以使用 nvm-windows[4] 、nodist[5] 或 nvs[6] 替换。

安装方式

macOS 下载方式:

  1. # 方式1 浏览器打开下面链接下载
  2. https://github.com/nvm-sh/nvm/blob/v0.39.1/install.sh
  3. # 下载完成后,通过命令安装
  4. sh install.sh
  5. # 方式2 推荐
  6. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  7. # 方式3
  8. wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

安装过程中如果遇到一些奇怪的问题,可以查看下 nvm 补充说明[7]。

常用命令

  1. nvm ls                # 查看版本安装所有版本
  2. nvm ls-remote         # 查看远程所有的 Node.js 版本
  3. nvm install 17.0.0    # 安装指定的 Node.js 版本
  4. nvm use 17.0.0        # 使用指定的 Node.js 版本
  5. nvm alias default 17.0.0  # 设置默认 Node.js 版本
  6. nvm alias dev 17.0.0  # 设置指定版本的别名,如将 17.0.0 版本别名设置为 dev

图片

2. n

⭐ Github stars: 16.7K+

n[8] 是一款交互式的 Node.js 版本管理工具,没有子脚本,没有配置文件,也没有复杂的 API,使用起来非常简单。

n 只适用于 macOS 和 Linux ,不适用于 Windows。

安装方式

可以使用 npm 直接安装到全局:

npm install n -g

常用命令

  1. n          # 显示所有已下载版本
  2. 10.16.0  # 下载指定版本
  3. n lts      # 查看远程所有 LTS Node.js 版本
  4. n run 10.16.0 # 运行指定的 Node.js 版本

输入 n -h查看帮助信息,主要命令如下:

  1.   n                              Display downloaded Node.js versions and install selection
  2.   n latest                       Install the latest Node.js release (downloading if necessary)
  3.   n lts                          Install the latest LTS Node.js release (downloading if necessary)
  4.   n <version>                    Install Node.js <version> (downloading if necessary)
  5.   n install <version>            Install Node.js <version> (downloading if necessary)
  6.   n run <version> [args ...]     Execute downloaded Node.js <version> with [args ...]
  7.   n which <version>              Output path for downloaded node <version>
  8.   n exec <vers> <cmd> [args...]  Execute command with modified PATH, so downloaded node <version> and npm first
  9.   n rm <version ...>             Remove the given downloaded version(s)
  10.   n prune                        Remove all downloaded versions except the installed version
  11.   n --latest                     Output the latest Node.js version available
  12.   n --lts                        Output the latest LTS Node.js version available
  13.   n ls                           Output downloaded versions
  14.   n ls-remote [version]          Output matching versions available for download
  15.   n uninstall                    Remove the installed Node.js

3. fnm

⭐ Github stars: 8.4K+

fnm [9]是一款快速简单

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/973667
推荐阅读
相关标签