You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu服务器Git拉取报错Could not resolve host: bitbucket.org及npm卡住求助

解决Ubuntu服务器Git拉取失败与npm安装卡住问题

问题现象

  • 执行git pull时报错:
    fatal: unable to access 'https://<user>@bitbucket.org/<repo>.git/': Could not resolve host: bitbucket.org
    
  • npm install命令持续卡住,无法完成安装
  • 已确认Git远程仓库配置正常(git remote -v输出符合预期),且尝试过删除并重新设置远程仓库,网络连接检查未发现明显异常

排查与解决步骤

1. 检查DNS解析能力

DNS解析失败是导致Could not resolve host的常见原因,先验证解析是否正常:

# 测试bitbucket.org的DNS解析
nslookup bitbucket.org
# 或用dig工具更详细查看
dig bitbucket.org

如果解析无结果或报错,手动配置公共DNS:

# 临时修改resolv.conf(重启后可能失效)
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
echo "nameserver 8.8.4.4" | sudo tee -a /etc/resolv.conf

# 若使用systemd-resolved,可修改配置文件永久生效
sudo nano /etc/systemd/resolved.conf
# 取消注释并修改DNS项:DNS=8.8.8.8 8.8.4.4
# 重启服务
sudo systemctl restart systemd-resolved

2. 清除Git的代理配置

清理空间过程中可能误保留或损坏了代理设置,导致Git无法正常连接:

# 清除全局HTTP/HTTPS代理
git config --global --unset http.proxy
git config --global --unset https.proxy

# 检查并清除本地仓库的代理配置(如果存在)
git config --local --unset http.proxy
git config --local --unset https.proxy

3. 验证网络连通性

确认服务器能正常连接到bitbucket.org的HTTPS端口:

# 测试ICMP连通性
ping bitbucket.org -c 4

# 测试443端口是否可访问
telnet bitbucket.org 443
# 或用curl测试
curl -I https://bitbucket.org

如果端口无法访问,检查防火墙规则:

# 查看ufw防火墙状态
sudo ufw status
# 确保允许出站HTTPS流量(若未允许则添加)
sudo ufw allow out 443/tcp

4. 重置Git网络相关配置

重置Git的SSL验证和凭证缓存,排除配置损坏问题:

# 清除凭证缓存
git config --global credential.helper ''

# 重置SSL验证配置
git config --global --unset-all http.sslVerify
git config --global http.sslVerify true

5. 修复npm安装卡住问题

npm卡住多因网络或源的问题,尝试以下操作:

# 切换到国内镜像源
npm config set registry https://registry.npmmirror.com/

# 清除npm缓存
npm cache clean --force

# 重新执行安装
npm install

内容的提问来源于stack exchange,提问作者Kunal Arora

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 19:15:25