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

Ubuntu 22.10下npm v9.5.1所有命令执行卡顿无响应求助

npm v9.5.1在Ubuntu 22.10下所有命令卡顿无响应的排查与解决

问题描述

在Ubuntu 22.10系统中使用npm v9.5.1时,所有命令均出现卡顿无响应,包括创建Vite项目和安装依赖。

执行npm create vite@latest --verbose后,输出以下内容后光标停滞:

npm verb cli /usr/local/bin/node /usr/local/bin/npm
npm info using npm@9.5.1
npm info using node@v18.16.0
npm verb title npm create vite@latest
npm verb argv "create" "vite@latest" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:/home/firesquid/.npm/_logs/2023-04-20T02_36_19_073Z-
npm verb logfile /home/firesquid/.npm/_logs/2023-04-20T02_36_19_073Z-debug-0.log

执行npm install --verbose安装依赖时,输出以下内容后停滞一分钟无动作:

npm verb cli /usr/local/bin/node /usr/local/bin/npm
npm info using npm@9.5.1
npm info using node@v18.16.0
npm verb title npm install
npm verb argv "install" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:/home/firesquid/.npm/_logs/2023-04-20T02_39_20_708Z-
npm verb logfile /home/firesquid/.npm/_logs/2023-04-20T02_39_20_708Z-debug-0.log

已尝试的修复手段:

  • 重启电脑
  • 重新安装nvm
  • 直接从官网安装node(不通过nvm)
  • 执行npm cache clear --force
  • 检查并确认npm配置正确
  • 尝试了Stack Overflow上《npm install hangs》问题中的所有方案

补充说明:未使用VPN,同一网络下其他设备可正常运行npm,推测问题出在npm未向registry发送GET请求。

排查与解决步骤

1. 检查并切换npm registry配置

先确认当前registry地址:

npm config get registry

若默认是https://registry.npmjs.org/,可切换到国内镜像测试:

npm config set registry https://registry.npmmirror.com/

切换后重新执行npm命令验证是否恢复正常。

2. 测试网络连通性

直接用curl测试与registry的网络请求:

curl -v https://registry.npmjs.org/vite

若请求超时或无响应,进一步排查:

  • 检查Ubuntu防火墙规则,确认未阻止npm的网络请求
  • 更换DNS服务器(如8.8.8.8或114.114.114.114),测试域名解析是否正常
  • 清除可能残留的代理配置:
npm config get proxy
npm config get https-proxy
# 若有值则执行清除
npm config delete proxy
npm config delete https-proxy

3. 分析npm debug日志

查看verbose输出中提到的日志文件,获取请求失败细节:

cat /home/firesquid/.npm/_logs/2023-04-20T02_36_19_073Z-debug-0.log

日志中可能暴露DNS解析失败、TCP连接超时等具体问题。

4. 切换node/npm版本

降级npm到稳定版测试:

npm install -g npm@8.19.4

或用nvm切换到不同node版本:

nvm install 16
nvm use 16

切换后重新执行npm命令验证。

5. 检查系统hosts文件

查看是否存在错误的registry域名映射:

cat /etc/hosts

若有registry.npmjs.org的错误条目,删除后刷新DNS缓存:

sudo systemctl restart systemd-resolved

内容的提问来源于stack exchange,提问作者Jonathan Deiss

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 12:58:19