各种包管理软件配置国内源或镜像源
npm依赖包官网(官方 NPM registry.npmjs.org)访问速度较慢,每次安装依赖需要等很久,因此将npm的注册表源设置为国内的镜像,可以大幅提升安装速度,常用的npm镜像有如下:
-
淘宝npm镜像(推荐) 搜索地址:
http://npm.taobao.org/
registry地址:http://registry.npm.taobao.org/
-
cnpmjs镜像 搜索地址:http://cnpmjs.org/ registry地址:http://r.cnpmjs.org/
-
使用方法
# 1、临时使用(如安装依赖 XXX)
npm --registry https://registry.npm.taobao.org install XXX
# 2、持久使用
npm config set registry https://registry.npm.taobao.org
# 配置后可通过下面方式来验证是否成功
npm config get registry #如果返回https://registry.npm.taobao.org,说明镜像配置成功。
# 或
npm info XXX
# 恢复官网源
npm config set registry https://registry.npmjs.org/
# 3、通过cnpm使用(推荐)
npm install -g cnpm --registry=https://registry.npm.taobao.org
#4、使用
cnpm install XXX
-
参考资源 淘宝 NPM 镜像 cnpm 镜像使用说明
Pip (Python)
国内用户在使用pip安装python包的时候,经常会因为连接原因而失败,出现超时错误,因为PyPi的主服务器在国外,访问起来非常不便。好在国内有多个镜像站点,如阿里云、科大和清华镜像。这里讲一下如何从镜像站安装python包。
普通情况下,只需要用以下命令来安装:
pip install <包名>
如果要从镜像站安装,需要带上镜像站地址,比如下面使用清华镜像站:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <包名>
如果要让pip缺省使用镜像站,需要修改配置文件。
在Linux/MacOS环境下,修改文件 ~/.pip/pip.conf (没有就创建一下):
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
或者
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
在Windows环境下,直接在用户目录中创建一个pip文件夹,如:在C:\Users\xxx\pip中,新建文件pip.ini,内容和其它系统一样:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
或者
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
之后,pip安装不需要使用 -i 参数来制定站点,缺省就是使用配置文件里的站点了。
更详细的说明可以参考官方网站:
User Guide - pip 20.1 documentationpip.pypa.io
常用的几个国内镜像站:
修改国内pip源的shell脚本
#!/usr/bin/env bash
mkdir -p ~/.pip
cat << EOF > ~/.pip/pip.conf
[global]
timeout = 8
index-url = http://mirrors.aliyun.com/pypi/simple/
extra-index-url = http://pypi.douban.com/simple/
[install]
trusted-host=
mirrors.aliyun.com
pypi.douban.com
EOF
Gem (Ruby)
使用gems.ruby-china.com,请尽可能用比较新的 RubyGems 版本,建议 2.6.x 以上。
$ gem update --system # 这里请FQ一下
$ gem -v
2.6.3
$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l
https://gems.ruby-china.com
# 确保只有 gems.ruby-china.com
如果你使用 Gemfile 和 Bundler (例如:Rails 项目)
你可以用 Bundler 的 Gem 源代码镜像命令。
$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com
这样你不用改你的 Gemfile 的 source。
source 'https://rubygems.org/'
gem 'rails', '4.2.5'
...
更新缓存:
// 更新缓存
$ gem sources -u
其中一定要注意,淘宝的那个源不在维护了,ruby-china的源的后缀是.com
,而不是.org
。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~