带有版本限制的 apt-get 下载

mik*_*osz 18 linux ubuntu

我需要用来apt-get download获取.deb文件的特定版本,但不一定是确切的版本。.deb允许依赖项使用表达式,例如>=0.3.0,我想apt-get download获取与使用此类依赖项下载的版本相同的版本。

总结一下,我想要的工作是这样的:

$ apt-get download package='>=0.3.0'
Run Code Online (Sandbox Code Playgroud)

知道我如何获得该功能吗?

小智 0

由于您想要的正是能够给您的内容,因此使用自定义存档目录在“仅下载模式”下apt-get install运行可能是值得的:apt-get install

-d, --download-only
  Download only; package files are only retrieved, not unpacked or installed.
  Configuration Item: APT::Get::Download-Only.
Run Code Online (Sandbox Code Playgroud)

如何更改存档目录?这是一个配置选项:

FILES
  [...]

  /var/cache/apt/archives/
  Storage area for retrieved package files. Configuration Item: Dir::Cache::Archives.
Run Code Online (Sandbox Code Playgroud)

这些可以使用--option参数临时更改:

-o, --option
  Set a Configuration Option; This will set an arbitrary configuration option. 
  The syntax is -o Foo::Bar=bar.  -o and --option can be used multiple times 
  to set different options.
Run Code Online (Sandbox Code Playgroud)

总结一下:

apt-get install -d -o dir::cache::archives="/some/cache/dir" <package>
Run Code Online (Sandbox Code Playgroud)

此命令将下载(并且仅下载,而不安装)到的相关.deb文件。该目录将包含包的文件、其依赖项、锁定文件和“部分”目录(应该为空)。过滤出您需要的确切文件应该很简单。<package>/some/cache/dir.deb.deb