nvm之node 多版本管理
简介:
nvm:nodejs 版本管理工具,一个nvm可以管理很多node版本和npm版本
nodejs:在项目开发时的所需要的代码库
npm:nodejs 包管理工具
nvm、nodejs、npm的关系:
nvm 管理 nodejs 和 npm 的版本。npm 可以管理 nodejs 的第三方插件。
安装 nvm
可以使用curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
或者使用wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
都可以的,到这步一般情况下都没问题,然后终端输入 nvm,然后看到如下打印信息就可以了
Node Version Manager
Note:
- full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
- default (built-in) aliases: node, stable, unstable, iojs, system
- custom aliases you define with nvm alias foo
Any options that produce colorized output should respect the --no-colors option.
Usage:
nvm --help Show this message
nvm --version Print out the installed version of nvm
nvm install [-s]
--reinstall-packages-from=
--lts When installing, only select from LTS (long-term support) versions
--lts=
--skip-default-packages When installing, skip the default-packages file if it exists
--latest-npm After installing, attempt to upgrade to the latest working npm on the given node version
--no-progress Disable the progress bar on any downloads
nvm uninstall
nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias lts/*, if available.
nvm uninstall --lts=
nvm use [--silent]
--lts Uses automatic LTS (long-term support) alias lts/*, if available.
--lts=
nvm exec [--silent]
--lts Uses automatic LTS (long-term support) alias lts/*, if available.
--lts=
nvm run [--silent] node on
--lts Uses automatic LTS (long-term support) alias lts/*, if available.
--lts=
nvm current Display currently activated version of Node
nvm ls List installed versions
nvm ls
nvm ls-remote List remote versions available for install
--lts When listing, only show LTS (long-term support) versions
nvm ls-remote
--lts When listing, only show LTS (long-term support) versions
--lts=
nvm version
nvm version-remote
--lts When listing, only select from LTS (long-term support) versions
--lts=
nvm deactivate Undo effects of nvm on current shell
nvm alias [
nvm alias
nvm unalias
nvm install-latest-npm Attempt to upgrade to the latest working npm on the current node version
nvm reinstall-packages npm packages contained in
nvm unload Unload nvm from shell
nvm which [current |
nvm cache dir Display path to the cache directory for nvm
nvm cache clear Empty cache directory for nvm
Example:
nvm install 8.0.0 Install a specific version number
nvm use 8.0 Use the latest available 8.0.x release
nvm run 6.10.3 app.js Run app.js using node 6.10.3
nvm exec 4.8.3 node app.js Run node app.js with the PATH pointing to node 4.8.3
nvm alias default 8.1.0 Set default node version on a shell
nvm alias default node Always default to the latest available node version on a shell
Note:
to remove, delete, or uninstall nvm - just remove the $NVM_DIR folder (usually ~/.nvm)
如果呢,你没有看到,而是出现 command not found: nvm 你可以排查下是否有.bash_profile 这个文件,别人都是这么说的,你可以排查下,没有这个文件就建一个,然后把如下加入到环境变量里保存,然后source ~/.bashrc这个命令生效,就可以了,更多请详见nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
nvm 常用命令
nvm install stable ## 安装最新稳定版 node,当前是node v9.5.0 (npm v5.6.0)
nvm install
nvm uninstall
nvm use
nvm ls ## 列出所有安装的版本
nvm ls-remote ## 列出所有远程服务器的版本(官方node version list)
nvm current ## 显示当前的版本
nvm alias
nvm unalias
nvm reinstall-packages
本文章是转载...


浙公网安备 33010602011771号