我如何下载然后安装包?

我如何下载然后安装包?

我知道,当谈到 Red Hat 发行版时,我可以使用以下命令下载该软件包的副本,然后单独安装它。

yumdownloader package_name
yum install package_name

Ubuntu 中是否存在完全等效的命令可以分别执行这两项操作,或者以下命令可以同时执行这两项操作?

apt-get install package_name

答案1

只需在任何命令中添加-d(或)选项即可。这种方法简单而有效。--downloadapt-get

  • 不要担心依赖关系,它们也会被下载。
  • 安全性得到维护,所有完整性检查仍像常规安装一样进行。

例如:

$ sudo apt-get dist-upgrade -d
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  linux-headers-3.19.0-39 linux-headers-3.19.0-39-generic linux-image-3.19.0-39-generic linux-image-extra-3.19.0-39-generic
  linux-signed-image-3.19.0-39-generic
The following packages will be upgraded:
  keepassx linux-headers-generic linux-libc-dev linux-signed-generic linux-signed-image-generic
5 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 67,0 MB of archives.
After this operation, 289 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://nl.archive.ubuntu.com/ubuntu/ vivid-updates/main linux-image-3.19.0-39-generic amd64 3.19.0-39.44 [16,9 MB]
[...]
Fetched 67,0 MB in 4s (13,5 MB/s)       
Download complete and in download only mode

稍后当您处于离线状态时,您可以运行sudo apt-get dist-upgrade以完成安装。(注意需要获取 0 B/67,0 MB 的档案。

$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  linux-headers-3.19.0-39 linux-headers-3.19.0-39-generic linux-image-3.19.0-39-generic linux-image-extra-3.19.0-39-generic
  linux-signed-image-3.19.0-39-generic
The following packages will be upgraded:
  keepassx linux-headers-generic linux-libc-dev linux-signed-generic linux-signed-image-generic
5 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/67,0 MB of archives.
After this operation, 289 MB of additional disk space will be used.
Do you want to continue? [Y/n]

它还可以与install其他命令一起使用:

$ sudo apt-get install -d libpcap-dev 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libpcap0.8-dev
The following NEW packages will be installed:
  libpcap-dev libpcap0.8-dev
0 upgraded, 2 newly installed, 0 to remove and 5 not upgraded.
Need to get 214 kB of archives.
After this operation, 749 kB of additional disk space will be used.
Do you want to continue? [J/n] 
Get:1 http://nl.archive.ubuntu.com/ubuntu/ vivid/main libpcap0.8-dev amd64 1.6.2-2 [210 kB]
Get:2 http://nl.archive.ubuntu.com/ubuntu/ vivid/main libpcap-dev all 1.6.2-2 [3448 B]
Fetched 214 kB in 0s (1776 kB/s)     
Download complete and in download only mode

要清除缓存(存储在/var/cache/apt/archives):

sudo apt-get clean

答案2

使用download的功能apt-get

man apt-get

download
    download will download the given binary package into the current directory.

例如:

apt-get download chromium-browser

会将debChromium 浏览器的文件下载到当前目录中。请注意,这不会下载软件包的任何依赖项,因此如果您尝试.deb通过以下方式安装:

sudo dpkg -i path/to/downloaded/deb/file

您将收到依赖性错误。

apt-get install packageName执行(下载+安装)两项工作。下载的软件包将位于/var/cache/apt/archives文件夹中

相关内容