Linux 换源方法

通用方法

  1. 换国内源,最直接的就是上阿里、中科大的镜像官网。

  2. 根据选择自己的Linux发行版,点帮助help就有详细了,复制到sources.list,更新下源就好了。

    mirror

Ubuntu 换源方法

Xubunut、Kubuntu都是ubuntu发行版,只是桌面环境不同,换源也是一样。

如果你需要ubuntu cn国区源,请看Ubuntu cn国内源

  1. 备份原来的 sorces 文件

    $ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 修改 sources.list 文件

    $ sudo gedit /etc/apt/sources.list
    

    gedit 是 ubuntu 自带的图像界面编辑器,xubuntu、kubuntu自带的不是gedit,Kubuntu 自带 kate。

    同样你也可以用 vi/vim 去编辑:sudo vim /etc/apt/sources.list

  3. 将内容替换为阿里或中科大镜像源

    # 阿里镜像源
    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
    
    # 中科大镜像源
    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
    
  4. 替换后记得 保存

  5. 更新源:

    $ sudo apt-get update
    

Deepin 换源方法

  1. 备份原来的 sorces 文件

    $ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 修改 sources.list 文件

    $ sudo deepin-editor /etc/apt/sources.list
    

    deepin-editor 是 deepin 自带的图像界面编辑器,和 ubuntu 的 gedit 一样。你也可以用vim去编辑。看自己嘛。

    用 vi/vim 去编辑:sudo vim /etc/apt/sources.list

  3. 将内容替换为阿里或中科大镜像源

    阿里:

    # aliyun
    deb [by-hash=force] http://mirrors.aliyun.com/deepin panda main contrib non-free
    #deb-src http://mirrors.aliyun.com/deepin panda main contrib non-free
    

    中科大:

    # ustc
    deb [by-hash=force] http://mirrors.ustc.edu.cn/deepin panda main contrib non-free
    #deb-src http://mirrors.ustc.edu.cn/deepin panda main contrib non-free
    
  4. 替换后记得 保存

  5. 更新源:

    $ sudo apt-get update
    

遇到 lock 问题

这里以 deepin 为例,其他的都类似。

如果出现lock报错,删除lock文件就好了

lock1

lock2

删除上面提示的 lock 文件:

sudo rm -f /var/lib/apt/lists/lock

lock3

再更新源

$ sudo apt-get update

版权声明:

Anand's Blog文章皆为站长Anand Zhang原创内容,转载请注明出处。

包括商业转载在内,注明下方要求的文章出处信息即可,无需联系站长授权。

请尊重他人劳动成果,用爱发电十分不易,谢谢!

请注明出处:

本文出自:Anand's Blog

本文永久链接:https://anandzhang.com/posts/linux/2