Linux学习_ubuntu18.04更新阿里源

问题背景

最近在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
Linux学习_ubuntu18.04更新阿里源_第1张图片
image.png
  • 更新软件

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

sudo apt-get upgrade
Linux学习_ubuntu18.04更新阿里源_第2张图片
image.png
  • 检验更新是否成功

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

sudo apt install tree
image.png
  • 通过tree命令来查看,如下图:
    Linux学习_ubuntu18.04更新阿里源_第3张图片
    image.png

    完美解决Perfect
    Linux学习_ubuntu18.04更新阿里源_第4张图片
    图片发自App

你可能感兴趣的:(Linux学习_ubuntu18.04更新阿里源)