当我运行 sudo apt upgrade 命令以更新 Ubuntu 子系统(WSL)中的软件包时,出现了以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
ant ant-optional gdisk gir1.2-packagekitglib-1.0 jruby-openssl junit4 libappstream4 libasm-java libatasmart4 libbcpkix-java libbcprov-java libblockdev-crypto2
libblockdev-fs2 libblockdev-loop2 libblockdev-part-err2 libblockdev-part2 libblockdev-swap2 libblockdev-utils2 libblockdev2 libbsf-java libbytelist-java
libdirgra-java libglib2.0-bin libhamcrest-java libhawtjni-runtime-java libheadius-options-java libinvokebinder-java libjansi-java libjansi-native-java
libjcodings-java libjffi-java libjffi-jni libjitescript-java libjna-java libjna-jni libjna-platform-java libjnr-constants-java libjnr-enxio-java libjnr-ffi-java
libjnr-netdb-java libjnr-posix-java libjnr-unixsocket-java libjnr-x86asm-java libjoda-time-java libjruby-joni-java libjzlib-java libmodulator-java
libosgi-annotation-java libosgi-core-java libpackagekit-glib2-18 libparted-fs-resize0 libplymouth5 libpsych-java libstemmer0d libudisks2-0 libunsafe-fences-java
libunsafe-mock-java libvolume-key1 libyaml-snake-java nailgun python-apt-common python3-apt python3-certifi python3-chardet python3-distro-info python3-idna
python3-requests python3-requests-unixsocket python3-six python3-software-properties python3-urllib3 ruby-diff-lcs ruby-jar-dependencies ruby-rspec ruby-rspec-core
ruby-rspec-expectations ruby-rspec-mocks ruby-rspec-support unattended-upgrades
Use 'apt autoremove' to remove them.
E: Could not read response to hello message from hook [ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook || true: Success
E: Could not read response to hello message from hook [ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook || true: Success

为了修复这个问题,我根据错误提示(apt-esm-json-hook)将 /etc/apt/apt.conf.d 目录下名为 20apt-esm-hook.conf 的文件先移动到其他目录(在本例中是 /home/johnson 目录):

1
mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /home/johnson

然后再运行 sudo apt upgrade 命令,这次成功了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
libnss-systemd libpam-systemd libpolkit-agent-1-0 libxmlb2 policykit-1 systemd-sysv
The following packages have been kept back:
mysql-client mysql-server
The following packages will be upgraded:
alsa-ucm-conf apt apt-utils base-files bash bind9-dnsutils bind9-host bind9-libs binutils binutils-common binutils-x86-64-linux-gnu bolt ca-certificates
curl dirmngr distro-info-data dpkg dpkg-dev e2fsprogs fwupd fwupd-signed git git-man gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client
gpg-wks-server gpgconf gpgsm gpgv gzip isc-dhcp-client isc-dhcp-common klibc-utils kmod kpartx krb5-locales libapparmor1 libapt-pkg6.0 libarchive13
libasn1-8-heimdal libbinutils libc-ares2 libc-bin libcom-err2 libctf-nobfd0 libctf0 libcurl3-gnutls libcurl4 libdpkg-perl libext2fs2 libflac8
libfreetype6 libfribidi0 libfwupd2 libfwupdplugin5 libgnutls30 libgs9 libgs9-common libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal
libheimbase1-heimdal libheimntlm0-heimdal libhttp-daemon-perl libhx509-5-heimdal libjavascriptcoregtk-4.0-18 libk5crypto3 libkeyutils1 libklibc libkmod2
libkrb5-26-heimdal libkrb5-3 libkrb5support0 libksba8 libldap-common liblzma5 libmbim-glib4 libmbim-proxy libmm-glib0 libnss3 libntfs-3g883
libpam-modules libpam-modules-bin libpam-runtime libpam0g libpcre2-8-0 libpcre3 libperl5.30 libpython2.7-minimal libpython2.7-stdlib libpython3.8
libpython3.8-dev libpython3.8-minimal libpython3.8-stdlib libqmi-glib5 libqmi-proxy libroken18-heimdal libsensors-config libsensors5 libsepol1
libsqlite3-0 libss2 libssl-dev libssl1.1 libtdb1 libtiff5 libtss2-esys0 libudev1 libunwind8 libwayland-client0 libwebkit2gtk-4.0-37 libwind0-heimdal
libxml2 libxpm4 linux-libc-dev locales login logsave logstash modemmanager motd-news-config multipath-tools mysql-common ntfs-3g openssh-client
openssh-server openssh-sftp-server openssl passwd perl perl-base perl-modules-5.30 python-pip-whl python-pkg-resources python2.7 python2.7-minimal
python3-pip python3-pkg-resources python3-setuptools python3-wheel python3.8 python3.8-dev python3.8-minimal rsync rsyslog sbsigntool sudo tar tcpdump
tmux tzdata udev unzip vim vim-common vim-runtime vim-tiny xxd xz-utils
163 upgraded, 6 newly installed, 0 to remove and 2 not upgraded.
Need to get 435 MB of archives.
After this operation, 4070 kB of additional disk space will be used.
Do you want to continue? [Y/n]

输入 Y 后系统就会开始下载最新的软件包并安装。

注:我是在 Windows Subsystem for Linux 的第一个版本(WSL1)模式下运行 Ubuntu WSL 实例。如果你也遇到了类似的问题,希望这篇文章能帮助你解决在 apt 命令下升级软件包的问题。

(END)