翼度科技»论坛 云主机 LINUX 查看内容

小心! Ubuntu更换软件源/Ubuntu更换国内源, 如果随便修改了这个文件,你的Ub

5

主题

5

帖子

15

积分

新手上路

Rank: 1

积分
15
目录

参考资料

什么文件?

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

笔者自己也遇到过(好像是系统更新完了源没换),这次是帮人修复电脑问题(至少2个人遇到过这个问题),他好不容易折腾到能起界面
一看终端

1498个软件包未被升级就知道怎么回事了
看看 /etc/apt/sources.list
  1. ##阿里源
  2. deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  3. deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  4. deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  5. deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  6. deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  7. deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  8. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  9. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  10. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  11. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  12. ##163源
  13. # deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
  14. # deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
  15. # deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
  16. # deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
  17. # deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
  18. # deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
  19. # deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
  20. # deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
  21. # deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
  22. # deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
  23. ##清华源
  24. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
  25. deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
  26. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  27. deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  28. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  29. deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  30. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  31. deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  32. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  33. deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  34. ##中科大源
  35. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
  36. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
  37. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  38. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  39. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  40. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  41. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  42. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  43. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  44. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
复制代码
看上去没啥问题啊?
再看看原来的备份
  1. # deb cdrom:[Ubuntu 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted
  2. # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
  3. # newer versions of the distribution.
  4. deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
  5. # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
  6. ## Major bug fix updates produced after the final release of the
  7. ## distribution.
  8. deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
  9. # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
  10. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  11. ## team. Also, please note that software in universe WILL NOT receive any
  12. ## review or updates from the Ubuntu security team.
  13. deb http://cn.archive.ubuntu.com/ubuntu/ xenial universe
  14. # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial universe
  15. deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe
  16. # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe
  17. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  18. ## team, and may not be under a free licence. Please satisfy yourself as to
  19. ## your rights to use the software. Also, please note that software in
  20. ## multiverse WILL NOT receive any review or updates from the Ubuntu
  21. ## security team.
  22. deb http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
  23. # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
  24. deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
  25. # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
  26. ## N.B. software from this repository may not have been tested as
  27. ## extensively as that contained in the main release, although it includes
  28. ## newer versions of some applications which may provide useful features.
  29. ## Also, please note that software in backports WILL NOT receive any review
  30. ## or updates from the Ubuntu security team.
  31. deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
  32. # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
  33. ## Uncomment the following two lines to add software from Canonical's
  34. ## 'partner' repository.
  35. ## This software is not part of Ubuntu, but is offered by Canonical and the
  36. ## respective vendors as a service to Ubuntu users.
  37. # deb http://archive.canonical.com/ubuntu xenial partner
  38. # 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过去
  1. sudo busybox ping cn.archive.ubuntu.com
  2. PING cn.archive.ubuntu.com (45.125.0.6): 56 data bytes
  3. 64 bytes from 45.125.0.6: seq=0 ttl=47 time=266.571 ms
  4. 64 bytes from 45.125.0.6: seq=1 ttl=47 time=265.568 ms
  5. 64 bytes from 45.125.0.6: seq=2 ttl=47 time=257.845 ms
  6. 64 bytes from 45.125.0.6: seq=5 ttl=47 time=253.261 ms
  7. 64 bytes from 45.125.0.6: seq=7 ttl=47 time=259.055 ms
复制代码
确实要换源, 网络太差.那怎么改呢?
首先,
不要信百度,
不要信bing,
不要信百度!
一般讲不清楚, 像资料1里讲清楚的你也不一定看清楚.不懂内部原理都是瞎猫碰死耗子.
其次, 打开软件和更新:

  • 点开系统设置-软件和更新,
  • 或是在开始菜单输入software,在提示里打开软件和更新,
  • 或是在终端里输入software-properties-gtk

    提示都是位于中国的服务器就是默认的那个了
点击选项, 其他:

选择最佳服务器,系统会自动帮你选

我选的是腾讯,也可以是ustc(中科大),别的都行

注: 有发现选择服务器后在上面的菜单里还是选"中国的服务器", 这个情况不知道啥问题, 我是再点进列表再选择一次刚才选中的服务器.
选完了点选择服务器, 关闭菜单,会提示你更新软件仓库

在这里重新载入也可以, 点关闭的话,需要自己在终端执行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的就不确定要不要了
在意的话可以找一个默认文件把上面这几种补上
假如换了仓库,还装了软件,起不来怎么办?


  • 如果你的电脑, 个人数据有独立分区(比如/home), 重装Ubuntu还更快点, 系统还能顺带更新一下;
  • 如果你想尽量保留软件或者不想更新系统, 那这里只能简单给个方法,

    • 切换到ctrl+alt+f1-7 的文字终端里,
    • (可选)设置环境变量LANG=en_US, LANGUAGE=en_US防止apt打汉字变成菱形; 或者安装fbterm
    • 还原source.list(如果有备份), 或者上网找和自己电脑同版本ubuntu的apt仓库修改, 执行sudo apt update 将软件仓库改成正确的
    • 通过dpkg筛选装错的软件(比如过滤版本号18.04), 手动卸载重装;
      或者是安装aptitude工具, 用aptitude代替apt, 进行版本分析.

      • 如果你只是更换了python版本(16.04为3.5, 18.04为3.6), 可能还原python后重启桌面就能回来
      • 如果提示了upstart, systemd都更换了,那么 sudo aptitude install gnome(或者自己想用的桌面如kde, cinnamon等)的时候, 就需要确保aptitude的方案是所有软件都解决问题,不遗留未处理软件(有版本冲突的软件删除或者降级)
      • 如果dpkg里都看不到gdm3了, 干脆直接sudo aptitude install ubuntu-deskop

    • 重启, 然后在文字终端里反复尝试直到能进入UI
    • 也有出现都装好了重启还在文字终端的情况, 可能是启动流程有问题, 可以手动执行 sudo services gdm3 restart 或者 sudo systemctl restart gdm3 手动启动图形界面尝试

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

  • 如果没有任何冲突, 那么直接升级
  • 如果有冲突, 给出的方案应当不包含删除正常软件(如果有软件和你ubuntu版本不一致那可以删除), 不会提示某个软件的冲突保持不处理

    • 遇到了保留某个冲突不处理则按n拒绝方案让aptitude再找其他方案
    • 如果有冲突, 但是所有冲突都通过升级或者降级解决, 那么也可以同意方案进行升级


来源:https://www.cnblogs.com/SendBoringBackToNoWhere/p/17995479
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具