ubuntu更换apt源

一、备份apt源的配置文件

我们要修改的文件是sources.list,它在目录/etc/apt/下,sources.list是包管理工具apt所用的记录软件包仓库位置的配置文件,同样类型的还有位于 同目录下sources.list.d文件下的各种.list后缀的各文件。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

二、编辑apt源的配置文件

关于Vim介绍以及使用:https://blog.csdn.net/weixin_43438052/article/details/108743013

vim /etc/apt/sources.list

如果报错 sudo:vim:command not found 说明没装vim编辑器。

安装命令:

sudo apt-get install vim

三、查看Ubuntu版本代号

  1. 使用命令查看Ubuntu的版本代号Codename
lsb_release -c
# Codename:		bionic
  • 我用的是Ubuntu18.04(LTS),其代号为bionic

Ubuntu 12.04 (LTS)代号为precise

Ubuntu 14.04 (LTS)代号为trusty

Ubuntu 15.04代号为vivid

Ubuntu 15.10代号为wily

Ubuntu 16.04 (LTS)代号为xenial

Ubuntu 18.04 (LTS)代号为bionic

四、更换apt源

  • sources.list文件的条目都是有格式的,一般有如下形式:
# deb包
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
# 源码  
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  • Ubuntu中软件包的分类是mainrestricteduniverse multiverse

快速切换源配置文件

  1. 建议备份保存为多个源(当网络出现问题时,可以换上切换!)
# 官方的源
/etc/apt/sources.list
# 阿里云
/etc/apt/sources.list.aliyun
# 清华
/etc/apt/sources.list.qinghua
  1. 当需要时,用命令切换
# 重命名
mv sources.list.aliyun sources.list

1. 阿里云

#deb包
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-backports main restricted universe multiverse
##测试版源  
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed 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-backports main restricted universe multiverse
##测试版源  
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# Canonical 合作伙伴和附加  
deb http://archive.canonical.com/ubuntu/ bionic partner
deb http://extras.ubuntu.com/ubuntu/ bionic main

2. 清华大学镜像站

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

五、执行更新

sudo apt-get update

六、更新软件

sudo apt-get upgrade

参考资料

  1. /etc/apt/sources.list 详解

  2. ubuntu sudo update与upgrade的作用及区别

上一篇:ARM、MCU、DSP、FPGA、SOC各是什么?区别是什么?(转)


下一篇:Ubuntu 更新国内原