ubuntu札记1_更换阿里源

浏览: 1270

问题背景

最近在ubuntu18.04中通过 apt-get 安装软件的时候,总是提示:unable to locate package,究其原因是软件源没有更新造成的。


解决办法

一、备份ubuntu官方的源文件

最直接的办法就是更换软件源,通过root账户进行操作,本文中将软件源更新为阿里源,如若想更新为其他源,参考:ubuntu国内源更新

具体更新步骤如下:

  • 查看自己ubuntu版本的系统代号,每个系统的版本代号不同,在配置文件会使用到代号:
root@peter:/lsb_release -c   # 查看系统代号
Codename: bionic # ubuntu18.04代号为bionic

其他版本的系统代号:

Ubuntu 12.04 (LTS)代号为precise。

Ubuntu 14.04 (LTS)代号为trusty。

Ubuntu 15.04 代号为vivid。

Ubuntu 15.10 代号为wily。

Ubuntu 16.04 (LTS)代号为xenial。


  • 进入源文件 ,通过命令cd /etc/apt 切换到 sources.list 所在的目录
root@peter:~# cd /etc/apt
  • 执行备份命令 cp sources.list sources.list.bak 对源文件进行备份:
root@peter:/etc/apt# cp sources.list sources.list.bak

二、修改阿里源文件内容

  • 编辑源文件进行修改
root@peter:/etc.apt# vim sources.list
  • 直接将原来的源文件注释掉,添加阿里源文件,保存并退出: Esc + : + wq!
  • 关于vim具体使用方法,参考:Vim使用教程

注:ubuntu18.04的代号是bionic,根据自己的系统改为相应代号,常见系统代号见步骤1。

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

三、更新源和软件

  • 更新源

使用 sudo apt-get update命令进行更新,获取阿里源提供的软件列表

sudo apt-get update

image.png

  • 更新软件

使用命令 sudo apt-get upgrade 更新软件

sudo apt-get upgrade

image.png

  • 检验更新是否成功

需要检验下安装是否成功,下面通过安装tree来进行测试:

sudo apt install tree

image.png

  • 通过tree命令来查看,如下图:



推荐 0
本文由 皮大大 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册