Linux中配置各种源

1. Python中给 pip 配置豆瓣源

(1)Windows

  windows下,在资源管理器的地址栏输入%appdata%后回车打开appdata文件夹,新建一个pip文件夹,在pip文件夹里面新建一个配置文件pip.ini ,写入以下内容后保存

[global]
timeout = 6000
index-url = https://pypi.douban.com/simple
trusted-host = pypi.douban.com

(2)Linux

修改 ~/.pip/pip.conf (没有就创建一个), 修改 index-url豆瓣源,内容如下:

[global]
index-url = https://pypi.douban.com/simple

(3)pip临时

临时使用:

可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:
pip
install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent
这样就会从清华这边的镜像去安装gevent库。
或者用豆瓣源-i https://pypi.douban.com/simple

2. Centos7中给 yum 配置阿里源 

cd /etc/yum.repos.d
先将其他源放入一个文件夹中mkdir repo.bak
mv * repo.bak/
在浏览器中输入以下网址找到阿里镜像站https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.128b1b115XQUr7
可以在这里找到CentOS7的yum源,复制
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
然后找到第三方源epel镜像,找到https://developer.aliyun.com/mirror/epel?spm=a2c6h.13651102.0.0.128b1b115XQUr7找到epel(RHEL 7)
复制
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
清除yum缓存,然后创建新的缓存
yum clean all
yum makecache

  

3. Ubuntu中给 apt 配置阿里源

(1)将以前的源文件复制备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list
(2)直接清空文档里面的内容,然后把下面的阿里源信息粘贴进去。
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
(3)保存当前文档,继续执行更新源操作
sudo apt-get update
(4)替换了镜像源以后如果出现以下错误:由于没有公钥,无法验证下列签名:NO_PUBKEY 78BD65473CB3BD13
这里事实上有部分的源信息已经替换了,但是在第10项源信息中更新的时候出现google提供的软件证书丢失公钥,所以是没有完整更新的。当然,此时我们如果忽略不管的话,其实对于后面安装其他软件是没有影响的,只是涉及到最后第10项源信息提供的软件,则在安装时还是会很慢,很卡而已。
(5)解决
# 先切换系统用户为root
sudo su
# 清除当前系统的源信息缓存
apt-get clean
# 进入源信息保存目录
cd /var/lib/apt
# 把现有的源信息备份一下
mv lists lists.back
# 在源信息下面创建一个partial目录
mkdir -p lists/partial
# 再次清除源环境信息
apt-get clean
# 更新源
apt-get update
# 上面这一步如果执行的时候依然报上面的错误,则继续往下操作,如果没有报错,则OK了。
接下来,要找到上面错误发生时的NO_PUBKEY 后面的签名,例如,我上面的是 78BD65473CB3BD13
则系统终端接下来继续把上面丢失的签名注册到ubuntu官方库下面。
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 78BD65473CB3BD13
# 再次更新源。(注意,上面如果报错的签名有多个,则需要在最后使用空格隔开,逐个加上)
apt-get update

 

猜你喜欢

转载自www.cnblogs.com/banbosuiyue/p/12615244.html
今日推荐