zoukankan      html  css  js  c++  java
  • node版本管理工具nvm的安装及使用

    一、什么是nvm

    nvm是一个node版本管理工具。

    由于不同项目依赖的node版本可能不同,所以在维护多个项目时通常需要使用不同的node版本,这时候用nvm来切换不同的node版本就很方便。

    官方文档: https://github.com/nvm-sh/nvm/blob/master/README.md

    二、安装nvm

    1、安装nvm:在终端运行如下命令(建议到官网获取最新版本号)

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

    安装成功,会在如图位置看到nvm配置

    2、配置nvm

      • 前往文件夹   /用户/xxx

     

      • shift+command+.显示隐藏文件,找到.bash_profile文件

     

      • 打开.bash_profile,将上面那段配置填进去
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completio
      • 命令行执行下面的命令,使配置生效
    source  ~/.bash_profile
      • 执行下面的命令,确认是否安装成功
    command -v nvm

    如果命令不存在,重启一下终端。若是还不行,建议检查配置是否正确,或是到issues里面找找解决方法。

    三、nvm常用命令

    1、安装和卸载  install

    nvm install stable ## 安装最新稳定版 node
    nvm install <version> ## 安装指定版本
    nvm uninstall <version> ## 删除已安装的指定版本

    2、切换版本 use

    nvm use <version> ## 切换使用指定的版本node

    3、添加和删除别名

    nvm alias <name> <version> ## 给不同的版本号添加别名
    nvm unalias <name> ## 删除已定义的别名

    注:别名设置为default,则是系统默认版本

    4、查看已安装版本

    nvm ls ## 列出所有安装的版本

    四、其他

    1、mac如何运行.sh文件

    直接把.sh文件拖到终端里就可以了。

     

    2、npm install 出现 ETIMEDOUT

    解决办法:

    npm config set registry https://registry.npm.taobao.org

    3、由于node版本改变,node sass报错

    Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime

    解决办法:

    • 卸载node-sass
    npm uninstall --save node-sass
    • 清除缓存
    npm cache clean -f
    • 升级node-sass模块
    npm install --save node-sass

        ✨:如果重新安装不好使,那可能是两处运行的node环境不一样(尤其是运行react native,最好设置node的default版本是rn需要的版本)

     

     

    End----------------------

    去简书避难了几天,我又回来啦~

  • 相关阅读:
    客户端本地存储,web存储,localStorage
    js地理定位对象 navigator.geolocation
    使用defined和require引入js
    VUE的使用方法
    $.each()的用法
    jQuery的deferred对象详解
    jquery 中prop()的使用方法
    IE7下对某些seajs压缩文件不兼容的解决方法
    饼状图注释
    $.grep()的用法
  • 原文地址:https://www.cnblogs.com/MaiJiangDou/p/14606069.html
Copyright © 2011-2022 走看看