包管理_各种包管理器国内源或镜像源

摘要:简单来说,“ 包管理器(package manager)”(或“软件包管理器”)是一种工具,它允许用户在操作系统上安装、删除、升级、配置和管理软件包。软件包管理器可以是像“软件中心”这样的图形化应用,也可以是像 apt-get 或 pacman 这样的命令行工具。

什么是包管理器?

简单来说,“ 包管理器(package manager)”(或“软件包管理器”)是一种工具,它允许用户在操作系统上安装、删除、升级、配置和管理软件包。软件包管理器可以是像“软件中心”这样的图形化应用,也可以是像 apt-get 或 pacman 这样的命令行工具。

使用包管理可以大大降低引用和管理第三方库的成本,但是很多源都在国外,通过包管理安装的时候,容易超时;我们可以通过修改为国内源,或者使用代理来解决这个问题。


NPM (Nodejs)

npm依赖包官网(官方 NPM registry.npmjs.org)访问速度较慢,每次安装依赖需要等很久,因此将npm的注册表源设置为国内的镜像,可以大幅提升安装速度,常用的npm镜像有如下:

提供方源及使用方式
淘宝

https://registry.npm.taobao.org/

npm config set registry https://registry.npm.taobao.org
yarn config set registry https://registry.npm.taobao.org
-

http://r.cnpmjs.org/

npm config set registry http://r.cnpmjs.org/
yarn config set registry http://r.cnpmjs.org/

恢复官网源 

npm config set registry https://registry.npmjs.org/


Pip (Python)

国内用户在使用pip安装python包的时候,经常会因为连接原因而失败,出现超时错误,因为PyPi的主服务器在国外,访问起来非常不便。好在国内有多个镜像站点,如阿里云、科大和清华镜像。

提供方源及使用方式
豆瓣

https://pypi.doubanio.com/simple/

pip install -i https://pypi.doubanio.com/simple/
清华大学

https://pypi.tuna.tsinghua.edu.cn/simple

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
阿里云

https://mirrors.aliyun.com/pypi/simple/

pip install -i https://mirrors.aliyun.com/pypi/simple/


Gem (Ruby)

使用gems.ruby-china.com,请尽可能用比较新的 RubyGems 版本,建议 2.6.x 以上。

提供方源及使用方式
Ruby China

https://ruby.taobao.org/

gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
清华大学

https://mirrors.tuna.tsinghua.edu.cn/rubygems/

gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/


Composer(Php)

Composer 是 PHP 用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件。

提供方源及使用方式
-

https://packagist.phpcomposer.com/

composer config -g repo.packagist composer https://packagist.phpcomposer.com
-

https://php.cnpkg.org/

composer config -g repo.packagist composer https://php.cnpkg.org
阿里云

https://mirrors.aliyun.com/composer/

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
华为云

https://mirrors.huaweicloud.com/repository/php/

composer config -g repo.packagist composer https://mirrors.huaweicloud.com/repository/php/
上海交通大学

https://packagist.mirrors.sjtug.sjtu.edu.cn/

composer config -g repo.packagist composer https://packagist.mirrors.sjtug.sjtu.edu.cn
-

https://packagist.jp/

composer config -g repo.packagist composer https://packagist.jp


Maven(Java)

Maven 是一个项目管理工具,可以对 Java 项目进行构建、依赖管理。

Maven 也可被用于构建和管理各种项目,例如 C#,Ruby,Scala 和其他语言编写的项目。Maven 曾是 Jakarta 项目的子项目,现为由 Apache 软件基金会主持的独立 Apache 项目。

提供方源及使用方式
阿里云

http://maven.aliyun.com/nexus/content/groups/public/

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<id>offical</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>offical</activeProfile>
</activeProfiles>
</settings>


代理设置

包管理器代理方式使用方式
piphttp/https
https_proxy=http://ip:hort pip install
composerhttp/https
https_proxy=http://ip:hort composer install
npmhttp/https
npm config set proxy http://ip:port
npm config set https-proxy https://ip:port
yarn config set proxy http://ip:port
yarn config set https-proxy https://ip:port
gemhttp/https
http_proxy=http://ip:host https_proxy=https://ip:host gem install
gohttp/https
http_proxy=http://ip:host https_proxy=https://ip:host go get


本文内容仅供个人学习、研究或参考使用,不构成任何形式的决策建议、专业指导或法律依据。未经授权,禁止任何单位或个人以商业售卖、虚假宣传、侵权传播等非学习研究目的使用本文内容。如需分享或转载,请保留原文来源信息,不得篡改、删减内容或侵犯相关权益。感谢您的理解与支持!

链接: https://shenqiku.cn/article/FLY_10816