Skip to content

nvs

相比于nvm和n, 自认为node最好用的包管理工具

参考

https://github.com/jasongin/nvs

nvs -h

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 updates

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

A version string consists of a semantic version number or version label
("lts" or "latest"), optionally preceeded by a remote name, optionally
followed by an architecture, separated by slashes.
Examples: "lts", "4.6.0", "6.3.1/x86", "node/6.7.0/x64"
Aliases may also be used anywhere in place of a version string.

共用 npm 全局模块

使用 nvs 时,默认的 prefix 是当前激活的 Node.js 版本的安装路径。

带来一个问题是:切换版本之后,之前安装全局命令模块需要重新安装,非常不方便。

解决方案是配置统一的全局模块安装路径到 ~/.npm-global,如下:

$ mkdir -p ~/.npm-global
$ npm config set prefix ~/.npm-global

还需配置环境变量到 ~/.bashrc

echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.bashrc

windows使用gitbash 事项

会出现找不到命令情况,应在.bash_profile加入以下命令

export NVS_HOME=$LOCALAPPDATA/nvs
. $NVS_HOME/nvs.sh

配置 remotes 镜像地址

查看 remote

nvs remote

配置镜像地址

nvs remote node https://npmmirror.com/mirrors/node/

Comments