Mac 安装 nvm 教程

在安装 nvm 之前我们首先需要确保电脑上没有安装 node 版本,如果安装了 node 版本,可以使用以下命令卸载已安装的node,然后再进行安装。

  卸载已安装的node

sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

 安装 nvm

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

安装成功终端大概长这样

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14926  100 14926    0     0  15580      0 --:--:-- --:--:-- --:--:-- 15564
=> nvm is already installed in /Users/liuyuanyuan/.nvm, trying to update using git
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /Users/liuyuanyuan/.bash_profile
=> Appending bash_completion source string to /Users/liuyuanyuan/.bash_profile
=> Close and reopen your terminal to start using nvm or run the following to use it now:

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_completion

正常情况下安装完成后,会自动在全局配置文件中,配置好相应的环境变量。可以使用 nvm -v 命令进行验证。

443报错

curl: (7) Failed to connect to raw.githubusercontent.com port 443: 拒绝连接

解决方式:修改host,通过以下地址 找raw.githubusercontent.com对应IP

https://www.ipaddress.com/site/raw.githubusercontent.com
终端输入:sudo vim /etc/hosts
进入hosts文件,按 i 变成编写模式,编写对应ip和地址,比如:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost
185.199.108.133 raw.githubusercontent.com

写完按esc键退出编写模式,输入 :wq 保存后返回

如果不能正常使用可以手动配置环境变量

cd ~
vim .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_completion

刷新环境变量:

source ~/.bash_profile

关闭命令行窗口,然后重启窗口查看是否生效。

如果新打开的窗口仍无法使用 nvm

则需要手动配置一些 .zshrc 文件 与配置 .bash_profile 文件一致

vim ~/.zshrc

然后将下面的配置信息输入保存

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_completion

刷新环境变量:

source ~/.zshrc

结束

你可能感兴趣的:(github,git)