小鱼资料库

小鱼资料库 > 计算机 > 前端 >

mac安装nvm

第一种方案

  1. 从github上下载nvm,地址:https://github.com/nvm-sh/nvm.git

git clone https://github.com/nvm-sh/nvm.git
  1. 进入下载的nvm目录中执行install.sh等待执行完成

./install.sh
  1. 配置nvm环境变量将下面代码复制到 ~/.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

如果没有配置环境变量,先配置环境变量,方法如下:

终端输入 open ~/.bash_profile

执行 source ~/.bash_profile

执行 nvm --version 是否正常输出,若不行则重启终端再次尝试。

第二种方案

  1. brew install nvm 首先保证之前没有安装过node,如果安装过,要先 brew uninstall node
  2. 上面的操作之后,终端可能会报错:Command failed with exit 128: git,不要着急,这是终端输入brew -v ,回提示添加 git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core和git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask,只要将两行代码复制到终端执行,之后再重新brew install nvm,之后就是等待了
  3. 下载完之后,需要在环境变量的文件中添加 echo "source $(brew --prefix nvm)/nvm.sh" >> .bash_profile,并source ~/.bash_profile保存变量,之后就可以正常使用了
标签:mac安装nvm(1)