0%

Mac中Node多版本管理

  1. 安装brew

    1
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. 安装NVM

    1
    brew install nvm
  3. 配置环境变量
    在环境变量文件中加入如下内容,如zsh即为~/.zshrc

    1
    2
    export NVM_DIR=~/.nvm
    source $(brew --prefix nvm)/nvm.sh
  4. 安装指定版本的node

    1
    2
    3
    4
    5
    6
    7
    8
    nvm install 8.17.0        
    Downloading and installing node v8.17.0...
    Downloading https://nodejs.org/dist/v8.17.0/node-v8.17.0-darwin-x64.tar.xz...
    ######################################################################################################################################################### 100.0%
    Computing checksum with shasum -a 256
    Checksums matched!
    Now using node v8.17.0 (npm v6.13.4)
    Creating default alias: default -> 8.17.0 (-> v8.17.0)
  5. nvm常用命令

    1
    2
    3
    4
    nvm ls-remote           # 查看所有的node可用版本
    nvm install xxx # 下载你想要的版本
    nvm use xxx # 使用指定版本的node
    nvm alias default xxx # 每次启动终端都使用该版本的node
  6. 问题解决

  • 问题如下:

    1
    2
    3
    4
    5
    6
    7
    8
    nvm ls-remote
    dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
    Referenced from: /usr/local/opt/curl-openssl/bin/curl
    Reason: image not found
    dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
    Referenced from: /usr/local/opt/curl-openssl/bin/curl
    Reason: image not found
    N/A
  • 解决方法:

    1
    2
    3
    brew switch openssl 1.0.2s
    Cleaning /usr/local/Cellar/openssl/1.0.2s
    Opt link created for /usr/local/Cellar/openssl/1.0.2s