![使用 apt 获取已安装软件包的 URL](https://linux22.com/image/894319/%E4%BD%BF%E7%94%A8%20apt%20%E8%8E%B7%E5%8F%96%E5%B7%B2%E5%AE%89%E8%A3%85%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%9A%84%20URL.png)
您可能知道我们可以使用它apt-get install --print-uris -y package-name
,它会向我们显示 URL、哈希值等的列表。
但是如果我们将它用于系统上已经安装的包,它就不起作用:
Reading package lists... Done
Building dependency tree
Reading state information... Done
package is already the newest version (x.x-x).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
apt
那么如何使用或其他 CLI 工具获取必要的 URL 列表aptitude
?
附言: 我不想使用packages.ubuntu.com。
答案1
当然,并非所有已安装的软件包都有与之关联的 URL。但是,您可以使用apt-get dowload
:
$ apt-get download --print-uris wget
'http://archive.ubuntu.com/ubuntu/pool/main/w/wget/wget_1.15-1ubuntu1.14.04.2_amd64.deb' wget_1.15-1ubuntu1.14.04.2_amd64.deb 270522 SHA256:a3f3b049ea373402236a804a5a0952c6ef9b356ba8cc19fbc1f257db6e8f3052
这是所示的候选版本apt-cache policy
,不一定是已安装的版本。
答案2
添加标志似乎就足够了--reinstall
(至少在我的 16.04 系统上)例如
$ sudo apt-get install --print-uris wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
wget is already the newest version (1.17.1-1ubuntu1.2).
wget set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 73 not upgraded.
但
$ sudo apt-get install --reinstall --print-uris wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 73 not upgraded.
Need to get 298 kB of archives.
After this operation, 0 B of additional disk space will be used.
'http://ca.archive.ubuntu.com/ubuntu/pool/main/w/wget/wget_1.17.1-1ubuntu1.2_amd64.deb' wget_1.17.1-1ubuntu1.2_amd64.deb 298270 MD5Sum:09a54f8d74c78598f91c4b376f3d2f0e
注意:如果包当前已被缓存,则此方法不起作用:
$ sudo apt-get install --reinstall --download-only wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 73 not upgraded.
Need to get 298 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://ca.archive.ubuntu.com/ubuntu xenial-updates/main amd64 wget amd64 1.17.1-1ubuntu1.2 [298 kB]
Fetched 298 kB in 0s (382 kB/s)
Download complete and in download only mode
$ sudo apt-get install --reinstall --print-uris wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 73 not upgraded.
Need to get 0 B/298 kB of archives.
After this operation, 0 B of additional disk space will be used.
但清除缓存后
$ sudo apt-get clean
$ sudo apt-get install --reinstall --print-uris wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 73 not upgraded.
Need to get 298 kB of archives.
After this operation, 0 B of additional disk space will be used.
'http://ca.archive.ubuntu.com/ubuntu/pool/main/w/wget/wget_1.17.1-1ubuntu1.2_amd64.deb' wget_1.17.1-1ubuntu1.2_amd64.deb 298270 MD5Sum:09a54f8d74c78598f91c4b376f3d2f0e