7

I know that when it comes to the RedHat distribution(correct me if I'm mistaken), I can use:

yumdownloader package_name #simply downloads a copy of the package without installing it
yum install package_name #installs the specific package that has to be downloaded in prior

is there an exact equivalent in ubuntu(that does both operations separately) or does the following command do both (download+ install):

apt-get install package_name

thank you for you're help, it is much appreciated and I do apologize if this question is supposed to be asked elsewhere, I just thought this is the right place.

3

Use the download feature of apt-get.

From man apt-get:

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

For example:

apt-get download chromium-browser

will download the deb file of chromium browser into the current directory. Note that this will not download any of the dependencies of the package so if you try to install the .deb by:

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

you'll get dependency errors.

apt-get install packageName does both the (download+install) jobs. The downloaded packages will be in the /var/cache/apt/archives folder

  • First of all, your answer require one to download all dependencies manually too. Second of all, I dislike this approach because dpkg is not as clever as apt. For example, if you download a package and its dependencies, you need to provide all packages to dpkg, and the package management marks the dependencies as manually installed. If you would have installed them with apt, they would be marked as automatically installed. This helps later removal with apt-get autoremove (and aptitude). – gertvdijk Dec 6 '15 at 11:48
  • (continued) I've -1 your answer mainly because the question is about the case in which the user wants to download AND install them. An apt-get download command is, in my opinion, useful only if you are not going to install it later or you need to inspect the file as a non-root user. Hence the reasons in my comment above. See my own answer for what I think fits better to this question. – gertvdijk Dec 6 '15 at 11:52
  • @gertvdijk FYI, this was a direct answer to the question as the OP did not mention anything about dependencies. AFAIK, apt-get download is the exact equivalent of yumdownloader(in that they do not download dependencies). The question was not about the best way to install, in which case your's is better. – Ron Dec 6 '15 at 11:56
7

Just add the -d (or --download) option to any apt-get command. This approach is simple and effective.

  • Don't worry about dependencies, they're downloaded as well.
  • Security is maintained, all integrity checks are still done just like a regular installation.

E.g.:

$ 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

At a later time when you're offline, you can run sudo apt-get dist-upgrade to complete the installation. (Note the Need to get 0 B/67,0 MB of archives.)

$ 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]

It also works with install or other commands:

$ 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

To clear the cache (stored in /var/cache/apt/archives):

sudo apt-get clean

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.