Ubuntu – install a package moved to /var/cache/apt/archives manually

apt

I installed wkhtmltopdf, by sudo apt-get install wkhtmltopdf. Its version is 0.9.9.

http://wkhtmltopdf.org/downloads.html says its latest stable version is 0.12.2.1. So I download its deb for Ubuntu 14.04.

I want to use apt to install the downloaded deb for reasons stated in https://unix.stackexchange.com/a/159114/674 and related replies, so I move it to /var/cache/apt/archives, but still how can I install it using apt?

$ mv /tmp/wkhtmltox-0.12.2.1_linux-trusty-amd64.deb /var/cache/apt/archives

$ sudo apt-get install wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
E: Couldn't find any package by regex 'wkhtmltox-0.12.2.1_linux-trusty-amd64.deb'

$ sudo apt-get install wkhtmltox
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package wkhtmltox

$ sudo apt-get install wkhtmltopdf still installs the older version. Thanks.

Best Answer

Quick Summary

To install a manually downloaded .deb package and also automatically download and install the packages it depends on from your configured repositories:

  • You can run sudo apt-get -f install after installing your .deb with dpkg -i.
  • Or use gdebi to install a .deb package and automatically resolve its dependencies (apt-get will not do this, but gdebi and its graphical frontends will).

See below for details.

Why apt-get Won't Do This

apt-get checks your configured software sources (repositories) and automatically downloads and installs packages. Except in the case where a configured repository is inaccessible, this does not enable an apt-get install command to succeed that would not otherwise succeed. If the package isn't in one of your repositories, apt-get will not know to install it even if the .deb file happens to be in /var/cache/apt/archives.

Thus:

  • If you have a package already downloaded, and it is the same package apt-get would automatically download and install, then you can put it /var/cache/apt/archives and apt-get will not have to download it.

  • If you have a package already downloaded which is not the same package apt-get would automatically choose, but which is nonetheless available in a configured repository, then you can put it in /var/cache/apt/archives and force apt-get to attempt to install it instead of the package it prefers. For example:

    sudo apt-get install abiword=3.0.1-1
    
  • Neither of those situations applies to your case. The specific package version is not provided by any of the configured repositories, because it is instead an alpha testing version from the upstream project's download page. Because you have no repository that provides that version of that package, you cannot install your manually downloaded .deb file with apt-get.

Way 1: Install with dpkg and Resolve Dependencies with apt-get

Fortunately, it doesn't look like you need to install this package with apt-get. It appears your actual goal is

  1. to install the manually downloaded .deb package, which isn't provided by your repos (which dpkg can do, but apt-get cannot), and also
  2. to install any its dependencies that are provided by its repos (which dpkg cannot do, but apt-get can).

You can do this in two separate steps:

  1. Install the package with dpkg.

    sudo dpkg -i wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
    
  2. That created missing dependencies. apt-get can fix missing dependencies automatically.

    sudo apt-get -f install
    

    That should also automatically finish configuring the original package. (So you will not likely need to run sudo dpkg --configure -a yourself.)

Way 2: Use gdebi to Both Install and Resolve Dependencies

While apt-get won't attempt to automatically install an arbitrary .deb file and its dependencies, there is a tool made for this purpose: gdebi Install gdebi. From man gdebi:

gdebi lets you install local deb packages resolving and installing its dependencies. apt does the same, but only for remote (http, ftp) located packages.

To use gdebi in a terminal, run gdebi package.deb as root, e.g.:

sudo gdebi wkhtmltox-0.12.2.1_linux-trusty-amd64.deb

gdebi also has graphical frontends. You'll probably want to use gdebi-gtk, the GTK+ frontend:

gksudo gdebi-gtk wkhtmltox-0.12.2.1_linux-trusty-amd64.deb

But if you're running Kubuntu (or otherwise using KDE) you might prefer gdebi-kde, the KDE frontend (provided by the gdebi-kde Install gdebi-kde package):

kdesudo gdebi-kde wkhtmltox-0.12.2.1_linux-trusty-amd64.deb

The graphical frontends may also be called without arguments (e.g., gksudo gdebi-gtk), in which case you may click File > Open to browse for and select the .deb file from within the GUI.

Screenshot of the Open Software Package dialog in gdebi-gtk

Related Question