Mac管理多版本nodeJS


场景安装步骤


场景

在我们开发多个项目的时候,因为框架支持的node版本不同,所以要切换多个node版本

安装步骤

  • 使用npm安装一个模块 n 的全局
Honglei:~ honglei$ npm  install  -g  n 
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ n@6.0.1 added 1 package from 4 contributors in 12.449s
  • 安装n v8.11.3版本
    注意:如果权限不够,记得添加权限给文件目录
#安装其他版本node n+后加版本号(eg:n v8.11.3) 
Honglei:local honglei$ n v8.11.3
installing : node-v8.11.3
mkdir : /usr/local/n/versions/node/8.11.3
fetch : https://nodejs.org/dist/v8.11.3/node-v8.11.3-darwin-x64.tar.gz
############# 18.7%
  • n --help
    使用时的选择:再使用 n ,通过上下键选择需要用的node版本,选择后回车即可
➜  ~ 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
  • 其它命令
#执行语句  
n latest 安装最新版本
n stable 安装稳定版本
n rm x.x.x 删除某个版本
n rm v8.11.3