ubuntu软件未完全安装带来的问题及解决方案

问题发生在我在安装pip的时候:

1
~/$sudo apt-get install python-pip

报错如下:

1
2
3
4
5
6
7
8
9
10
11
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
ethereum : Depends: ethereum-swarm but it is not going to be installed
python-pip : Depends: python-pip-whl (= 9.0.1-2.3~ubuntu1) but it is not going to be installed
Recommends: python-all-dev (>= 2.6) but it is not going to be installed
Recommends: python-setuptools but it is not going to be installed
Recommends: python-wheel but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

大概意思是之前有个包没安装完(我这里是ethereum-swarm这个包)
按照提示看能否解决:

1
~/$sudo apt --fix-broken install

报错:

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
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
amule-common amule-utils libcrypto++6 libtorrent-rasterbar9 libwxbase3.0-0v5
libwxgtk3.0-0v5 swarm ttf-dejavu-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
ethereum-swarm
The following NEW packages will be installed:
ethereum-swarm
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
1 not fully installed or removed.
Need to get 0 B/5,561 kB of archives.
After this operation, 22.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 209881 files and directories currently installed.)
Preparing to unpack .../ethereum-swarm_0.3.1+build14601+bionic_amd64.deb ...
Unpacking ethereum-swarm (0.3.1+build14601+bionic) ...
dpkg: error processing archive /var/cache/apt/archives/ethereum-swarm_0.3.1+build14601+bionic_amd64.deb (--unpack):
trying to overwrite '/usr/bin/swarm', which is also in package swarm 2.2.2+dfsg-1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/ethereum-swarm_0.3.1+build14601+bionic_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

按照网上的方法:

1
~/$sudo apt install -f

报同样的错
我们分析一下错误是什么意思,到下载这步都没有问题,问题出在解压这步

1
2
3
4
Unpacking ethereum-swarm (0.3.1+build14601+bionic)
dpkg: error processing archive /var/cache/apt/archives/ethereum-swarm_0.3.1+build14601+bionic_amd64.deb (--unpack):
trying to overwrite '/usr/bin/swarm', which is also in package swarm 2.2.2+dfsg-1
...

大概就是ethereum-swarm这个包想要overwrite一个文件/usr/bin/swarm,而这个文件已经被一个已安装的包使用了,我尝试删掉这个文件(人混胆子大,可以先备份)

1
~/$sudo rm /usr/bin/swarm

再次安装

1
~/$sudo apt install -f

还是同样的错误
我们再使用dpkg -i —force-overwrite 试试:

1
2
3
4
5
6
7
~/$sudo dpkg -i --force-overwrite /var/cache/apt/archives/ethereum-swarm_0.3.1+build14601+bionic_amd64.deb
(Reading database ... 209881 files and directories currently installed.)
Preparing to unpack .../ethereum-swarm_0.3.1+build14601+bionic_amd64.deb ...
Unpacking ethereum-swarm (0.3.1+build14601+bionic) ...
dpkg: warning: overriding problem because --force enabled:
dpkg: warning: trying to overwrite '/usr/bin/swarm', which is also in package swarm 2.2.2+dfsg-1
Setting up ethereum-swarm (0.3.1+build14601+bionic) ...Ok

没有报错,再次输入

1
~/$sudo apt-get install -f

发现ethereum-swarm 安装成功了。
后面就可以安装你想要的软件了:

1
~/$sudo apt-get install python-pip

最后我去了解了下 dpkg -i —force-overwrite 这个命令,这篇文章讲的很好
https://www.techtimejourney.net/for-sudo-and-root-usersdealing-with-apt-errors/#more-1759