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: refers to any version-like string nvm understands. This includes:
- 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] Download and install a , [-s] from source. Uses .nvmrc if available
--reinstall-packages-from= When installing, reinstall packages installed in <node|iojs|node version number>
--lts When installing, only select from LTS (long-term support) versions
--lts= When installing, only select from versions for a specific LTS line
--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 Uninstall a version
nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias lts/*, if available.
nvm uninstall --lts= Uninstall using automatic alias for provided LTS line, if available.
nvm use [--silent] Modify PATH to use . Uses .nvmrc if available
--lts Uses automatic LTS (long-term support) alias lts/*, if available.
--lts= Uses automatic alias for provided LTS line, if available.
nvm exec [--silent] [] Run on . Uses .nvmrc if available
--lts Uses automatic LTS (long-term support) alias lts/*, if available.
--lts= Uses automatic alias for provided LTS line, if available.
nvm run [--silent] [] Run node on with as arguments. Uses .nvmrc if available
--lts Uses automatic LTS (long-term support) alias lts/*, if available.
--lts= Uses automatic alias for provided LTS line, if available.
nvm current Display currently activated version of Node
nvm ls List installed versions
nvm ls List versions matching a given
nvm ls-remote List remote versions available for install
--lts When listing, only show LTS (long-term support) versions
nvm ls-remote List remote versions available for install, matching a given
--lts When listing, only show LTS (long-term support) versions
--lts= When listing, only show versions for a specific LTS line
nvm version Resolve the given description to a single local version
nvm version-remote Resolve the given description to a single remote version
--lts When listing, only select from LTS (long-term support) versions
--lts= When listing, only select from versions for a specific LTS line
nvm deactivate Undo effects of nvm on current shell
nvm alias [] Show all aliases beginning with
nvm alias Set an alias named pointing to
nvm unalias Deletes the alias named
nvm install-latest-npm Attempt to upgrade to the latest working npm on the current node version
nvm reinstall-packages Reinstall global npm packages contained in to current version
nvm unload Unload nvm from shell
nvm which [current | ] Display path to installed node version. Uses .nvmrc if available
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 ## 安装指定版本,可模糊安装,如:安装v4.4.0,既可nvm install v4.4.0,又可nvm install 4.4
nvm uninstall ## 删除已安装的指定版本,语法与install类似
nvm use ## 切换使用指定的版本node
nvm ls ## 列出所有安装的版本
nvm ls-remote ## 列出所有远程服务器的版本(官方node version list)
nvm current ## 显示当前的版本
nvm alias ## 给不同的版本号添加别名
nvm unalias ## 删除已定义的别名
nvm reinstall-packages ## 在当前版本 node 环境下,重新全局安装指定版本号的 npm 包

本文章是转载...

posted @ 2020-01-13 16:59  wpt80  阅读(318)  评论(0)    收藏  举报