linux换源操作合集
1.ubuntu 18.04 更换apt源
1.编辑sources源文件(通常做个备份)
# sudo vim /etc/apt/sources.list
# 先删除旧源
------
#添加阿里源,从使用来看阿里源稳定快速,相较清华源更好用
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
------
# 补充 20.04 换以下源
------
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#添加清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse multiverse
------
2.更新
# 更新源
# sudo apt update
# sudo apt upgrade
3.通过sed命令换源
# 更新软件源为阿里源并用它更新软件
# cp /etc/apt/sources.list /etc/apt/sources.list.bak_`date "+%y_%m_%d"`
# sed -i 's/http:\/\/.*.ubuntu.com/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list
# apt update
# apt upgrade
2.centos 7 换源
1.备份yum系统源
# cd /etc/yum.repos.d
# mkdir bak
# mv ./*.repo bak/
2.wget or curl 阿里源
如果是6/8的版本,自行替换版本号即可,通用链接
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.生成缓存
# yum makecache
# tips
1.先用yum list wget检查一下你的虚拟机有没有安装wget
没有安装就yum install -y wget安装一下
2.默认没有ifconfig命令,通过yum install -y net-tools安装ifconfig命令
3.python pip换源 | 多源
1.创建.pip文件夹,然后在该目录下创建pip.conf文件
# mkdir ~/.pip
# vim ~/.pip/pip.conf
2.pip.conf文件编写如下内容(更换为阿里云镜像源)
# 在conf文件中也可以指定包的安装目录,在[install]设置:install_lib = ~/usr/lib/pythonxxx/site-packages
# [global]
# index-url = http://mirrors.aliyun.com/pypi/simple/
# disable-pip-version-check = true #取消pip版本检查,排除每次都报最新的pip
# [install]
# trusted-host=mirrors.aliyun.com
---***---豆瓣源
[global]
timeout =6000
index-url =http://pypi.douban.com/simple/
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
---***---豆瓣源
--------------
源集合:
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
p.s. 如果需要用不同版本python,强烈建议用虚拟环境管理python版本,具体见我虚拟环境配置
# 同个文件中配置多源
-----------------------------
[global]
index-url = index1
extra-index-url = index2 index3 index4
trusted-host = host1 host2 host3
-----------------------------
先从index-url查找,找不到则从extra-index-url查找
还可以是如下格式:
-------------------------------
[global]
index-url = index1
extra-index-url =
index2
index3
index4
trusted-host =
host1
host2
host3
------------------------------
***临时使用源***
pip install python-package -i https://pypi.douban.com/simple/
***安装python及pip***
ubuntu下:
# 默认安装python2.7, 没有的话建议用安装包安装
# wget下包,tar解包,./configuration 指定安装路径,make && make install
apt-get install python-pip
# python3 版本是默认安装有pip3的
整理:https://www.cnblogs.com/xuegqcto/p/10395926.html
4.docker换源
1.创建编辑daemon.json文件
# cd /etc/docker
# cat daemon.json
# 阿里云源
------
{
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn,
"https://kfwkfulq.mirror.aliyuncs.com",
"https://2lqq34jg.mirror.aliyuncs.com",
"https://pee6w651.mirror.aliyuncs.com",
"https://registry.cn-hangzhou.aliyuncs.com", # 阿里云源
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com"
]
}
------
2.重启docker
# systemctl daemon-reload
# systemctl restart docker
# alpine
推荐使用如下的方式直接修改
# 阿里镜像
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 科大镜像
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
aliyun个人镜像加速器:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors