快乐随行

导航

统计

npm 及 yarn 代理设置及更换为国内下载源

1.出错情况

npm安装完成默认不走代理,所在如果公司内网是通过代理访问外部网站,npm则会出现安装插件失败情况

2.设置代理

  • 命令行窗口输入:
npm config set proxy http://server:port
  • 如果需要设https_proxy:
npm config set https-proxy http://server:port
  • 设置了proxy就不需要设置https-proxy了。
  • 如果需要代理用户名和密码
npm config set proxy http://username:password@server:port
npm confit set https-proxy http://username:password@server:port

3.取消代理

npm config delete proxy
npm config delete https-proxy
或者
npm config set proxy null
npm config set https-proxy null

4.修改源

国外源速度不稳定,可设置国内淘宝源。

  • 查看现有源:
npm config get registry
  • 设置淘宝源:
npm config set registry https://registry.npmjs.org/

yarn config set registry https://registry.npmjs.org/
  • 查看npm的设置
npm config list
或者
npm config ls -l
  • 用新源更新一波package:
npm update

5.其他

  • 在设置配置属性时属性值默认是被存储于用户配置文件中,如果加上--global,则被存储在全局配置文件中
  • 如果要查看npm的所有配置属性(包括默认配置),可以使用npm config ls -l
  • 如果要查看npm的各种配置的含义,可以使用npm help config
  • 如果不能通过https fetch,可以使用npm config set strict-ssl false

6.YARN设置代理:

yarn config set proxy <http_proxy>
yarn config set https-proxy <https_proxy>

7. YARN删除代理:

yarn config delete proxy  
yarn config delete https-proxy

posted on   快乐随行  阅读(10402)  评论(0编辑  收藏  举报

编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示