使用nvs管理你本地的node版本

791 阅读1分钟

可以看到node官网给出了以下多种node 包管理器

今天要讲的主角是nvs

image.png

为什么要介绍它?

  1. 跨平台的 可以在Windows,macOS和类Unix系统上使用(请注意,在安装这个包管理器之前,你并不需要先安装node)

windows安装看这里

nvs for windows

macos 或 unix安装 看这里

[macOS,UnixLike](nvs/SETUP.md at master · jasongin/nvs · GitHub)

使用方法

用法

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

添加最新版本的 node:

nvs add latest

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

nvs add lts

然后运行 ​​nvs use 命令为当前 shell 添加一个版本的 node 到你的 PATH

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

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

nvs link lts

使用nvs ls 查看本地已安装版本

C:\Users\Administrator>nvs ls
  node/16.0.0/x64
  node/14.17.6/x64 (Fermium)
  node/14.17.0/x64 (Fermium)
  node/12.22.0/x64 (Erbium)
>#node/12.16.1/x64 (Erbium)
  node/10.16.1/x64 (Dubnium)

其它功能 使用nvs --help查看:

C:\Users\Administrator>nvs --help
NVS (Node Version Switcher) usage

nvs help <command>             Get detailed help for a command
nvs install                    Initialize your profile for using NVS
nvs --version                  Display the NVS tool version

nvs menu                       Launch an interactive menu

nvs add <version>              Download and extract a node version
nvs rm <version>               Remove a node version
nvs migrate <fromver> [tover]  Migrate global modules
nvs upgrade [fromver]          Upgrade to latest patch of major version

nvs use [version]              Use a node version in the current shell
nvs auto [on/off]              Automatically switch based on cwd
nvs run <ver> <js> [args...]   Run a script using a node version
nvs exec <ver> <exe> [args...] Run an executable using a node version
nvs which [version]            Show the path to a node version binary

nvs ls [filter]                List local node versions
nvs ls-remote [filter]         List node versions available to download
nvs outdated                   List local node versions and available udates

nvs link [version]             Link a version as the default
nvs unlink [version]           Remove links to a default version

nvs alias [name] [value]       Set or recall aliases for versions
nvs remote [name] [uri]        Set or recall download base URIs