小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!

  • 小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!已关闭评论
  • 69 次浏览
  • A+
所属分类:linux技术
摘要

如参考资料所写,就是不要随便修改/etc/apt/sources.list笔者自己也遇到过(好像是系统更新完了源没换),这次是帮人修复电脑问题(至少2个人遇到过这个问题),他好不容易折腾到能起界面
一看终端

1498个软件包未被升级就知道怎么回事了
看看 /etc/apt/sources.list

参考资料

什么文件?

如参考资料所写,就是不要随便修改/etc/apt/sources.list

为什么?

笔者自己也遇到过(好像是系统更新完了源没换),这次是帮人修复电脑问题(至少2个人遇到过这个问题),他好不容易折腾到能起界面
一看终端
小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!
1498个软件包未被升级就知道怎么回事了
看看 /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  ##163源 # deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse # deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse # deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse # deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse # deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse # deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse # deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse # deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse # deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse # deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse  ##清华源 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  ##中科大源 deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 

看上去没啥问题啊?
再看看原来的备份

# deb cdrom:[Ubuntu 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted  # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted  ## Major bug fix updates produced after the final release of the ## distribution. deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted  ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ xenial universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial universe deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe  ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu  ## team, and may not be under a free licence. Please satisfy yourself as to  ## your rights to use the software. Also, please note that software in  ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse  ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse  ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu xenial partner # deb-src http://archive.canonical.com/ubuntu xenial partner 

对, 系统是16.04(xenial xerus)的 而非18.04(bionic beaver)的

ubuntu的软件仓库有版本概念, 如果16.04的系统用了18.04的仓库 软件能起来是幸运, 但是就会有一堆报错了
但是多数百度的资料没讲这点; 参考资料1有讲到

正确的换源方法

多数人没修改源,用的默认的, 这个服务器是 cn.archive.ubuntu.org.cn, 以前有段时间是指向阿里云好像, ping过去

sudo busybox ping cn.archive.ubuntu.com PING cn.archive.ubuntu.com (45.125.0.6): 56 data bytes 64 bytes from 45.125.0.6: seq=0 ttl=47 time=266.571 ms 64 bytes from 45.125.0.6: seq=1 ttl=47 time=265.568 ms 64 bytes from 45.125.0.6: seq=2 ttl=47 time=257.845 ms 64 bytes from 45.125.0.6: seq=5 ttl=47 time=253.261 ms 64 bytes from 45.125.0.6: seq=7 ttl=47 time=259.055 ms 

确实要换源, 网络太差.那怎么改呢?
首先,
不要信百度,
不要信bing,
不要信百度!
一般讲不清楚, 像资料1里讲清楚的你也不一定看清楚.不懂内部原理都是瞎猫碰死耗子.

其次, 打开软件和更新:

  • 点开系统设置-软件和更新,
  • 或是在开始菜单输入software,在提示里打开软件和更新,
  • 或是在终端里输入software-properties-gtk
    小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!
    提示都是位于中国的服务器就是默认的那个了

点击选项, 其他:
小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!
选择最佳服务器,系统会自动帮你选
小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!
我选的是腾讯,也可以是ustc(中科大),别的都行
小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!

注: 有发现选择服务器后在上面的菜单里还是选"中国的服务器", 这个情况不知道啥问题, 我是再点进列表再选择一次刚才选中的服务器.

选完了点选择服务器, 关闭菜单,会提示你更新软件仓库
小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ubuntu可能会起不来!
在这里重新载入也可以, 点关闭的话,需要自己在终端执行sudo apt update更新

更新仓库后才能安装软件哦! 所以推荐在这里重新载入以免忘记.
更新后, 1498的软件未被升级的提示就会减少了

修改sources.list的方法

如果需要直接修改sources.list, 确保你知道你在干什么, 并且在修改前备份文件
然后要搜索和你电脑同版本的软件源更新, 或者直接搜索如"Ubuntu 20.04 source.list"找这个文件的默认内容

注: 也有发现"软件和更新"选择的服务器, 选择了所有的更新内容后, 在sources.list里面只看到了如 focal main universe multiverse restricted的服务器
focal-updates的main universe multiverse restricted的服务器, 还有focal-security的main universe multiverse restricted的服务器这些都没加上, focal-backports的就不确定要不要了
在意的话可以找一个默认文件把上面这几种补上

假如换了仓库,还装了软件,起不来怎么办?

  1. 如果你的电脑, 个人数据有独立分区(比如/home), 重装Ubuntu还更快点, 系统还能顺带更新一下;
  2. 如果你想尽量保留软件或者不想更新系统, 那这里只能简单给个方法,
    1. 切换到ctrl+alt+f1-7 的文字终端里,
    2. (可选)设置环境变量LANG=en_US, LANGUAGE=en_US防止apt打汉字变成菱形; 或者安装fbterm
    3. 还原source.list(如果有备份), 或者上网找和自己电脑同版本ubuntu的apt仓库修改, 执行sudo apt update 将软件仓库改成正确的
    4. 通过dpkg筛选装错的软件(比如过滤版本号18.04), 手动卸载重装;
      或者是安装aptitude工具, 用aptitude代替apt, 进行版本分析.
      1. 如果你只是更换了python版本(16.04为3.5, 18.04为3.6), 可能还原python后重启桌面就能回来
      2. 如果提示了upstart, systemd都更换了,那么 sudo aptitude install gnome(或者自己想用的桌面如kde, cinnamon等)的时候, 就需要确保aptitude的方案是所有软件都解决问题,不遗留未处理软件(有版本冲突的软件删除或者降级)
      3. 如果dpkg里都看不到gdm3了, 干脆直接sudo aptitude install ubuntu-deskop
    5. 重启, 然后在文字终端里反复尝试直到能进入UI
    6. 也有出现都装好了重启还在文字终端的情况, 可能是启动流程有问题, 可以手动执行 sudo services gdm3 restart 或者 sudo systemctl restart gdm3 手动启动图形界面尝试

aptitude 版本分析的方法, 简单的就是看它给的方案:

  • 如果没有任何冲突, 那么直接升级
  • 如果有冲突, 给出的方案应当不包含删除正常软件(如果有软件和你ubuntu版本不一致那可以删除), 不会提示某个软件的冲突保持不处理
    • 遇到了保留某个冲突不处理则按n拒绝方案让aptitude再找其他方案
    • 如果有冲突, 但是所有冲突都通过升级或者降级解决, 那么也可以同意方案进行升级