Ubuntu18.04 apt update报错解决分享

报错

Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
 

sam@ubuntu:~$ sudo apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                            
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                      
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease                                         
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease                                       
Hit:5 https://download.sublimetext.com apt/stable/ InRelease                    
Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 8, in <module>
    from CommandNotFound.db.creator import DbCreator
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code

解决方法(from: https://itectec.com/ubuntu/ubuntu-problem-with-sudo-apt-update-in-ubuntu-18-04-post-invoke-success-if-usr-bin-test-w-var-lib-command-not-found/):

apt download python3-minimal
sudo apt install --reinstall ./python3-minimal_*.deb
sudo apt install -f

Execution:

sam@ubuntu:~$ apt download python3-minimal
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-minimal amd64 3.6.7-1~18.04 [23.7 kB]
Fetched 23.7 kB in 1s (16.8 kB/s)          
sam@ubuntu:~$ sudo apt install --reinstall ./python3-minimal_*.deb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'python3-minimal' instead of './python3-minimal_3.6.7-1~18.04_amd64.deb'
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 28 not upgraded.
Need to get 23.7 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-minimal amd64 3.6.7-1~18.04 [23.7 kB]
Fetched 23.7 kB in 1s (17.0 kB/s)          
(Reading database ... 180143 files and directories currently installed.)
Preparing to unpack .../python3-minimal_3.6.7-1~18.04_amd64.deb ...
Unpacking python3-minimal (3.6.7-1~18.04) over (3.6.7-1~18.04) ...
Setting up python3-minimal (3.6.7-1~18.04) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
sam@ubuntu:~$ sudo apt install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
sam@ubuntu:~$ sudo apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                            
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                      
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease                                         
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease                                       
Hit:5 https://download.sublimetext.com apt/stable/ InRelease                    
Reading package lists... Done

### 解决Ubuntu 18.04 LTS中安装SSH服务器时出现的错误 当遇到在Ubuntu 18.04 LTS上安装SSH服务出现问题的情况,可以通过一系列方法来排查并解决问题。确保系统处于最新状态有助于减少因过期或不兼容包引起的冲突。 #### 确认网络连接正常 确认机器能够访问互联网是非常重要的一步,因为这决定了能否成功下载必要的文件和更新。如果存在网络配置问题,则应先解决这些问题[^1]。 #### 更新软件源列表 为了防止由于本地缓存中的旧数据而导致的问题,在尝试任何新的安装之前应该刷新APT数据库: ```bash sudo apt update ``` #### 安装OpenSSH Server 使用官方仓库提供的稳定版OpenSSH server来进行安装是最推荐的方式之一。命令如下所示: ```bash sudo apt install openssh-server ``` 若上述操作返回依赖关系解析失败或其他类似的报错信息,可能是因为某些必需组件缺失或者是已有损坏的包阻止了新程序的成功部署。此时可考虑清理已有的残留项再重试: ```bash sudo apt clean && sudo apt autoclean sudo apt autoremove sudo dpkg --configure -a sudo apt install -f ``` 对于特定类型的错误消息,比如找不到指定版本号的资源,可能是官方镜像站同步延迟所致;这时更换国内较快的速度节点会有所帮助。编辑`/etc/apt/sources.list`文件替换默认地址为阿里云等第三方加速器链接即可加快获取速度[^2]。 另外需要注意防火墙设置,默认情况下UFW(Uncomplicated Firewall)可能会阻挡外部请求到达SSHD端口22。因此要允许该通信端口通过安全策略规则集: ```bash sudo ufw allow ssh ``` 最后重启服务使更改生效,并验证其运行状况: ```bash sudo systemctl restart sshd.service systemctl status sshd.service ```
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值