成功解决WSL1下用apt install命令报错:Failed to take /etc/passwd lock: Invalid argument
WSL(尤其是 WSL1)对 Linux 的部分系统功能并不完全支持,像 polkitd 这样的系统服务需要对用户和权限做底层管理,但 WSL 没有完整实现这些机制,因此 polkitd 的 post-installation 脚本会失败。这个问题在 WSL2 也可能出现。apt list --installed | grep [你要安装的包]2.如果只是想用 httpie,可以用 pip 安装。
说明:我是小白,这篇文章写给自己以后遇到同样的问题时用的,避免再到处找解决方法。虽然不懂具体原理,但是当时操作是可行的。省时间可直接到终章依次执行4条命令解决。
缘起:
在wsl1 Ubuntu 24.04.2终端运行sudo apt install httpie 报错:
Failed to take /etc/passwd lock: Invalid argument
具体报错内容如下:
Setting up polkitd (124-2ubuntu1.24.04.2) ...
Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package polkitd (--configure):
installed polkitd package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of packagekit:
packagekit depends on polkitd; however:
Package polkitd is not configured yet.
dpkg: error processing package packagekit (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of packagekit-tools:
packagekit-tools depends on packagekit (= 1.2.8-2ubuntu1.2); however:
Package packagekit is not configured yet.
dpkg: error processing package packagekit-tools (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of software-properties-common:
software-properties-common depends on packagekit; however:
Package packagekit is not configured yet.
dpkg: error processing package software-properties-common (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of ubuntu-wsl:
ubuntu-wsl depends on software-properties-comNo apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
mon; however:
Package software-properties-common is not configured yet.
dpkg: error processing package ubuntu-wsl (--configure):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.12.0-4build2) ...
Errors were encountered while processing:
polkitd
packagekit
packagekit-tools
software-properties-common
ubuntu-wsl
E: Sub-process /usr/bin/dpkg returned an error code (1)
过程:
询问AI(需要给出运行的环境,我的是wsl1 Ubuntu 24.04.2,要不然AI再厉害也无法对症下药),给出出错原因(虽然不是很懂):
WSL(尤其是 WSL1)对 Linux 的部分系统功能并不完全支持,像 polkitd 这样的系统服务需要对用户和权限做底层管理,但 WSL 没有完整实现这些机制,因此 polkitd 的 post-installation 脚本会失败。这个问题在 WSL2 也可能出现。
尝试AI给的解决方法:
1. 直接忽略 polkitd 错误,单独安装 httpie
sudo apt install --no-install-recommends httpie
2.如果只是想用 httpie,可以用 pip 安装
sudo apt update
sudo apt install python3-pip -y
pip3 install --user httpie
都不行
于是在csdn上搜到一哥们的解决方法:
解决Failed to take /etc/passwd lock:Invalid argument的一种方法-CSDN博客
一通命令下去还是不行
又搜到另一个哥们的解决方法,成功解决:
WSL 更新软件 Failed to take /etc/passwd lock: Invalid argument – 亡灵的实验室
cd /bin && mv -f systemd-sysusers{,.org} && ln -s echo systemd-sysusers && cd -
AI说这条命令的作用是:
- 这条命令把原有的 systemd-sysusers 程序备份为 systemd-sysusers.org。
- 然后让 systemd-sysusers 变成一个 echo 的软链接(假装 systemd-sysusers 存在,但其实它什么都不做,只输出参数)。
- 常用于“欺骗”某些安装脚本绕过 systemd 相关校验,或者在不支持 systemd 的环境(如 WSL、Docker 等)防止一些服务安装时报错。
终章:
4条命令结束战斗(在root用户下操作)
- cd /bin && mv -f systemd-sysusers{,.org} && ln -s echo systemd-sysusers && cd -
- apt install [你要安装的包]
- apt --fix-broken install
- apt install [你要安装的包]
完事之后检查是否安装成功:
apt list --installed | grep [你要安装的包]
贴一个我当时运行的图片:
root@LAPTOP:/# cd /bin && mv -f systemd-sysusers{,.org} && ln -s echo systemd-sysusers && cd -
/
root@LAPTOP:/# apt install httpie
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
httpie is already the newest version (3.2.2-1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
systemd-sysv : Depends: systemd (= 255.4-1ubuntu8.6) but 255.4-1ubuntu8.8 is to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
root@LAPTOP:/# apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
libdrm-intel1 libpciaccess0 libsensors-config libsensors5
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
systemd-sysv
The following packages will be upgraded:
systemd-sysv
1 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
6 not fully installed or removed.
Need to get 0 B/11.9 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up systemd (255.4-1ubuntu8.8) ...
basic.conf systemd-journal.conf systemd-network.conf
(Reading database ... 48008 files and directories currently installed.)
Preparing to unpack .../systemd-sysv_255.4-1ubuntu8.8_amd64.deb ...
Unpacking systemd-sysv (255.4-1ubuntu8.8) over (255.4-1ubuntu8.6) ...
Setting up systemd-sysv (255.4-1ubuntu8.8) ...
Setting up libnss-systemd:amd64 (255.4-1ubuntu8.8) ...
Setting up systemd-timesyncd (255.4-1ubuntu8.8) ...
systemd-timesync.conf
Setting up udev (255.4-1ubuntu8.8) ...
debian-udev.conf
Setting up libpam-systemd:amd64 (255.4-1ubuntu8.8) ...
Setting up systemd-resolved (255.4-1ubuntu8.8) ...
systemd-resolve.conf
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for dbus (1.14.10-4ubuntu4.1) ...
Processing triggers for libc-bin (2.39-0ubuntu8.4) ...
root@LAPTOP:/# apt install httpie
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
httpie is already the newest version (3.2.2-1).
The following packages were automatically installed and are no longer required:
libdrm-intel1 libpciaccess0 libsensors-config libsensors5
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
更多推荐
所有评论(0)