Skip to content

Mac上安装node.js #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
qwtoe opened this issue Sep 16, 2024 · 0 comments
Open

Mac上安装node.js #3

qwtoe opened this issue Sep 16, 2024 · 0 comments
Labels
Mac Extra attention is needed 报错 Something isn't working 搭建环境

Comments

@qwtoe
Copy link
Owner

qwtoe commented Sep 16, 2024

官网的安装教程 https://nodejs.org/en/download/package-manager

# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# download and install Node.js (you may need to restart the terminal)
nvm install 20

# verifies the right Node.js version is in the environment
node -v # should print `v20.17.0`

# verifies the right npm version is in the environment
npm -v # should print `10.8.2`

但是执行第一条命令就报错:Failed to connect to raw.githubusercontent.com port 443 after 8 ms: Couldn't connect to server

解决办法:

1、https://www.ipaddress.com 查询 raw.githubusercontent.com 域名的 ip 地址。查出四条 ip 地址:

raw  IN  A  185.199.108.133
raw  IN  A  185.199.109.133
raw  IN  A  185.199.110.133
raw  IN  A  185.199.111.133

2、下载SwitchHosts软件

https://github.com/oldj/SwitchHosts/releases

https://switchhosts.vercel.app

3、SwitchHosts中加入以下host

185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com

记得打开开关。

最后:ping raw.githubusercontent.com 成功,然后执行第一条命令即可。


执行完之后,发现nvm并没有生效,于是手动配置nvm:配置nvm:https://juejin.cn/post/7232499180660768829

1、配置环境变量
    vim ~/.bash_profile
    
2、然后将下面的配置信息输入保存
    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
    
3、刷新环境变量
    source ~/.bash_profile

nvm -v 成功!

继续根据node官网步骤往下安装就行。

@qwtoe qwtoe added 报错 Something isn't working Mac Extra attention is needed 搭建环境 labels Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mac Extra attention is needed 报错 Something isn't working 搭建环境
Projects
None yet
Development

No branches or pull requests

1 participant