Ubuntu apt-get换源

一、参考资料

ubuntu16.04更换镜像源为阿里云镜像源

二、相关介绍

1. apt常用命令

sudo apt-get clean
sudo apt-get update

2. APT加速工具

轻量小巧的零配置 APT 加速工具:APT Proxy

GitHub项目地址:apt-proxy

三、换源关键步骤

1. 更新阿里源

  1. 备份源配置文件。
cd /etc/apt/
cp sources.list sources.list.old
  1. 打开阿里云镜像站:OPSX阿里云开源镜像站,找到Ubuntu,点击右边的帮助,查看对应版本的镜像源信息。

img

img
img 相关配置

  1. 修改 sources.list,更新镜像源,更新仓库信息。
# 修改sources.list配置文件
sudo gedit /etc/apt/sources.list 

# 更新源
sudo apt-get update 

# 更新仓库信息    
sudo apt-get upgrade 

2. 更新清华源(可选)

# 清华源地址
https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/

img

四、FAQ

Q:ubuntu16.0.4bug无法解析域名

错误:1 http://mirrors.aliyun.com/ubuntu xenial InRelease                       
  暂时不能解析域名“mirrors.aliyun.com”
错误:2 http://ppa.launchpad.net/fcitx-team/nightly/ubuntu xenial InRelease     
  暂时不能解析域名“ppa.launchpad.net”
错误:3 http://dl.google.com/linux/chrome/deb stable InRelease                  
  暂时不能解析域名“dl.google.com”
错误:4 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease       
  暂时不能解析域名“archive.ubuntukylin.com”
错误:5 http://packages.microsoft.com/repos/vscode stable InRelease             
  暂时不能解析域名“packages.microsoft.com”
错误:6 http://archive.ubuntu.com/ubuntu wily InRelease                         
  暂时不能解析域名“archive.ubuntu.com”
错误:7 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease               
  暂时不能解析域名“mirrors.aliyun.com”
错误:8 http://ppa.launchpad.net/notepadqq-team/notepadqq/ubuntu xenial InRelease
  暂时不能解析域名“ppa.launchpad.net”
0% [正在连接 mirrors.aliyun.com] [正在连接 ppa.launchpad.net]^C

参考博客: ubuntu16.0.4bug无法解析域名,注意查看网络是否连接。

Q:无法对目录 /var/lib/apt/lists/ 加锁

正在读取软件包列表... 完成
E: 无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用)
E: 无法对目录 /var/lib/apt/lists/ 加锁
# 错误原因
在更新源时中途中断了更新,系统给更新进程加锁,所以只要再安装软件或者再去更新的时候就会出来的错误提示。

# 解决方法
sudo rm /var/lib/apt/lists/lock
或者
ps -e | grep apt-get # 查看apt-get进程
sudo kill -9 端口号 # 杀死进程

Q:换源警告

已下载 2,965 B,耗时 1318(3 B/s)
正在读取软件包列表... 完成
W: 仓库 “http://ppa.launchpad.net/kazam-team/stable-series/ubuntu xenial Release” 没有 Release 文件。
N: 无法认证来自该源的数据,所以使用它会带来潜在风险。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
W: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial Release” 没有 Release 文件。
N: 无法认证来自该源的数据,所以使用它会带来潜在风险。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
W: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates Release” 没有 Release 文件。
N: 无法认证来自该源的数据,所以使用它会带来潜在风险。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
W: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-backports Release” 没有 Release 文件。
N: 无法认证来自该源的数据,所以使用它会带来潜在风险。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
W: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-security Release” 没有 Release 文件。
N: 无法认证来自该源的数据,所以使用它会带来潜在风险。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
# 错误原因:
具体原因尚不清楚,博主推测是清华源内部的原因。

# 解决办法:
换成阿里源,成功解决。

Q:dpkg: error processing package xxx (--configure) subprocess installed post-installation script returned error exit status 127

dpkg: error processing package *** (–configure)错误解决办法

在 Ubuntu 执行 sudo apt-get upgradesudo apt-get install 时,出现如上错误。这主要是由于不完全安装导致的。解决方式是删除或编辑安装信息文件。

方法一(粗暴方法)

删除所有信息,重新update。

sudo mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/
sudo mkdir /var/lib/dpkg/info/
sudo apt-get update

# 安装修复
sudo apt-get install -f 

方法二(精细方法)

查看出错信息,定向删除或编辑。

扫描二维码关注公众号,回复: 17214638 查看本文章

出错信息 subprocess installed post-installation script returned error exit status 127 中,可以看到这里的提示post-installation的问题。

# 编辑该文件,具体在 `/var/lib/dpkg/info/[package_name].postinst`

# 或者删除问题文件。例如:
sudo rm /var/lib/dpkg/info/[package_name].postinst
# 更狠一点
sudo mv /var/lib/dpkg/info /var/lib/dpkg/info.bak

sudo dpkg --configure -a
sudo apt-get update

Q:W: Failed to fetch xxx Could not handshake: A TLS fatal alert has been received. [IP: x.x.x.x 443]

W: Failed to fetch https://apt.repos.intel.com/mkl/dists/all/InRelease  Could not handshake: A TLS fatal alert has been received. [IP: 219.76.10.117 443]
W: Some index files failed to download. They have been ignored, or old ones used instead.
# 错误原因:
外国源,无法访问

# 解决办法:
删除外国源,重新update
sudo mv /var/lib/apt/lists /var/lib/apt/lists.bak
sudo apt-get update

Q:Certificate verification failed: The certificate is NOT trusted.

更换 Ubuntu 系统 apt 命令安装软件源

Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.  Could not handshake: Error in the certificate verification.
# 解决办法:
1. 编辑 /etc/apt/sources.list 文件,将 https 源修改为 http 源
https 是加密传输,需要证书认证。去掉 s,将 https 源修改为 http 源。


2. 更新证书 ca-certificates

sudo apt install ca-certificates
sudo apt-get install --reinstall ca-certificates
sudo apt install apt-transport-https ca-certificates

sudo apt-get update

3. 编辑 /etc/apt/sources.list 文件,将 http 源修改回 https 源

猜你喜欢

转载自blog.csdn.net/m0_37605642/article/details/134527902
今日推荐