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

    本文章是转载...

  • 相关阅读:
    onpropertychange与onchange事件应用
    HttpWorkerRequest实现大文件上传asp.net
    JQuery中对option的添加、删除、取值
    "分析 EntityName 时出错"的解决方法
    asp.net断点续传
    直接在ASP.net中上传大文件的方法
    ASP.NET中文件上传下载方法集合
    asp.net .ashx文件使用Server.MapPath解决方法
    FF与IE下javascript计算屏幕尺寸
    处理顶点——为赛道创建顶点
  • 原文地址:https://www.cnblogs.com/wpt80/p/12188130.html
Copyright © 2011-2022 走看看