最近项目切换频繁,经常需要用到node版本的切换,现在总结一下Node的版本管理控制器的使用和安装
1、Node 可以用n来管理版本的切换
安装:
npm install -g n
查看帮助:
➜ ~ n --help
Usage: n [options] [COMMAND] [args]
Commands:
n Display downloaded node versions and install selection
n latest Install the latest node release (downloading if necessary)
n lts Install the latest LTS node release (downloading if necessary)
n <version> Install node <version> (downloading if necessary)
n run <version> [args ...] Execute downloaded node <version> with [args ...]
n which <version> Output path for downloaded node <version>
n exec <vers> <cmd> [args...] Execute command with modified PATH, so downloaded node <version> and npm first
n rm <version ...> Remove the given downloaded version(s)
n prune Remove all downloaded versions except the installed version
n --latest Output the latest node version available
n --lts Output the latest LTS node version available
n ls Output downloaded versions
n ls-remote [version] Output matching versions available for download
n uninstall Remove the installed node and npm
Options:
-V, --version Output version of n
-h, --help Display help information
-q, --quiet Disable curl output (if available)
-d, --download Download only
-a, --arch Override system architecture
--all ls-remote displays all matches instead of last 20
--insecure Turn off certificate checking for https requests (may be needed from behind a proxy server)
Aliases:
which: bin
run: use, as
ls: list
lsr: ls-remote
rm: -
lts: stable
latest: current
Versions:
Numeric version numbers can be complete or incomplete, with an optional leading 'v'.
Versions can also be specified by label, or codename,
and other downloadable releases by <remote-folder>/<version>
4.9.1, 8, v6.1 Numeric versions
lts Newest Long Term Support official release
latest, current Newest official release
boron, carbon Codenames for release streams
and nightly, chakracore-release/latest, rc/10 et al
查看已安装的Node版本(我本地只有两个版本):
➜ ~ n ls
node/9.10.1
node/12.10.0
安装不同的版本:
➜ ~ n 9.10.0
安装最新版本:
➜ ~ n latest
安装稳定版本:
➜ ~ n stable
删除某个版本:
➜ ~ n rm 9.10.1
**2、node的版本控制器nvm **
NVM官网:https://github.com/nvm-sh/nvm
下载地址:https://github.com/coreybutler/nvm-windows/releases
进入网址后下载nvm-setup.zip,点击安装nvm-setup.exe。
查看版本:
nvm -v
安装你想要的node的版本:
nvm install 9.10.1
安装稳定版:
nvm stable
安装最新版:
nvm latest
查看目前安装的node的版本有哪些:
nvm use *.*.*