由于依赖性问题,无法在 ubuntu 16.04.2 LTS(GNU/Linux 4.4.0-1087-aws x86_64)上升级软件

由于依赖性问题,无法在 ubuntu 16.04.2 LTS(GNU/Linux 4.4.0-1087-aws x86_64)上升级软件

我在 AWS EC2 t3a.nano 实例上运行 ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1087-aws x86_64)。当我通过 SSH 访问我的机器时,我看到了以下内容:

Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1087-aws x86_64)

 * Documentation:  [redacted]
 * Management:     [redacted]
 * Support:        [redacted]

  Get cloud support with Ubuntu Advantage Cloud Guest:
    [redacted]

132 packages can be updated.
3 updates are security updates.

为了使我的机器上的软件保持最新,我运行了:

sudo apt-get update
Hit:1 [redacted] xenial InRelease
Hit:2 [redacted] xenial-updates InRelease
Hit:3 http://us-east-2.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu xenial-security InRelease              
Reading package lists... Done

然后我输入:

sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
E: Unmet dependencies. Try using -f.

好的,我发现我有依赖性问题,因此我尝试:

sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  bzip2 libbz2-1.0
Suggested packages:
  bzip2-doc
The following packages will be upgraded:
  bzip2 libbz2-1.0
2 upgraded, 0 newly installed, 0 to remove and 126 not upgraded.
1 not fully installed or removed.
Need to get 63.2 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 [redacted] xenial-updates/main amd64 bzip2 amd64 1.0.6-8ubuntu0.2 [32.5 kB]
Get:2 [redacted] xenial-updates/main amd64 libbz2-1.0 amd64 1.0.6-8ubuntu0.2 [30.7 kB]
Fetched 63.2 kB in 0s (3,126 kB/s)    
Selecting previously unselected package bzip2.
E: Sub-process /usr/bin/dpkg exited unexpectedly

现在我看到 dpkg 意外退出,我尝试:

sudo dpkg --audit
The following packages are in a mess due to serious problems during
installation.  They must be reinstalled for them (and any packages
that depend on them) to function properly:
 bzip2                high-quality block-sorting file compressor - utilities

我尝试:

sudo apt-get install bzip2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 bzip2 : Depends: libbz2-1.0 (= 1.0.6-8ubuntu0.2) but 1.0.6-8ubuntu0.1 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

所以现在我尝试:

sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  bzip2 libbz2-1.0
Suggested packages:
  bzip2-doc
The following packages will be upgraded:
  bzip2 libbz2-1.0
2 upgraded, 0 newly installed, 0 to remove and 126 not upgraded.
1 not fully installed or removed.
Need to get 0 B/63.2 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Selecting previously unselected package bzip2.
E: Sub-process /usr/bin/dpkg exited unexpectedly

现在我陷入了困境。有什么想法吗?


编辑以解决来自的评论@fkraiem:当我转到 /etc/apt/sources.list 时,我看到:

## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us-east-2.ec2.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://us-east-2.ec2.archive.ubuntu.com/ubuntu/ xenial main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us-east-2.ec2.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb-src http://us-east-2.ec2.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
[...]

您是否建议我用 packages.ubuntu.com 替换 us-east-2.ec2.archive.ubuntu.com 并重试更新命令?

答案1

感谢所有提出评论并试图提供帮助的人。

最后,我做了以下事情:

sudo apt-get -f install

并注意到内存不足的错误。我使用的是 t3a.nano,它只提供 0.5G 内存。我尝试添加 0.5G 交换空间,然后运行sudo dpkg --configure -a并再次尝试更新,现在一切都处于最佳状态。

对于任何可能正在使用 nano 实例的人来说,0.5G 内存并不多,因此您可能需要考虑添加交换以防止此类问题。以下是我的做法:

sudo fallocate -l 0.5G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

相关内容