当前位置:   article > 正文

Mac上安装nvm

Mac上安装nvm

Mac上安装nvm

一、卸载npm

如果之前没有安装过node,跳过这一步。如果之前安装过node,先把node卸载。

npm uninstall npm -g

#查看npm是否卸载

npm -v

#卸载node

sudo rm /usr/local/bin/node

#查看node是否卸载

node -v

//删除全局node模块注册的软链 cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs sudo rm
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

二、在终端输入以下命令下载nvm

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

github/nvm里可以找到该链接
  • 1
  • 2
  • 3

可能会遇到的错误:

1.fatal: unable to access 'https://github.com/nvm-sh/nvm.git/

那么需要执行:

git config --global --unset http.proxy
git config --global --unset https.proxy
  • 1
  • 2

此时如果遇到以下错误:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
  • 1

则需再执行:

xcode-select --install
  • 1

在这里插入图片描述

2.Failed to connect to raw.githubusercontent.com port 443,couldn’t find the server.

解决步骤:

(1)利用代理地址,去https://ipaddress.com输入地址raw.githubusercontent.com找到对应ip。(此步骤可能需要翻墙)
在这里插入图片描述

(2)终端输入sudo vim /etc/hosts编辑hosts文件,加入raw.githubusercontent.com的ip地址。
在这里插入图片描述

(3)进入hosts文件,按下按键ℹ️进入编写模式,编写对应的ip和地址,写完按下esc键退出编辑模式。输入:wq然后回车。
在这里插入图片描述

(4)终端输入cat /etc/hosts 查看hosts,是否加入和ip和地址。

最后重新运行nvm下载命令:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

三、配置环境变量,添加bash.profile文件。

(1)终端输入touch .bash_profile,创建.bash.profile文件。

(2)终端输入open .bash_profile,编辑.bash.profile文件。

(3)在弹出的.bash.profile文件内增加以下代码

#nvm
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
  • 1
  • 2
  • 3
  • 4

(4)终端输入nvm -v 输出版本号,即为安装成功。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/703690
推荐阅读
相关标签
  

闽ICP备14008679号