How to install latest HPLIP on my Ubuntu to support my HP printer and/or scanner?

Installation

Currently there are no PPAs with newer hplip packages.

But user can download and install binary from HP as described in their manual.

Before you proceed you should remove any hplip related packages to avoid possible future conflicts.

HP have note about this problem on support page:

Warning: If you are upgrading HPLIP and HPLIP is already preinstalled with your distribution, or you if you installed HPLIP using an RPM, DEB, or other package, please uninstall the previous version using the method specific for your distribution. If you do not do this, you may have package conflict issues or functionality problems.

I have experimentally determined the list of packages (tested on 16.04 LTS and 18.04 LTS) and below are commands:

sudo apt-get purge hplip hplip-data hplip-doc hplip-gui hpijs-ppds \
libsane-hpaio printer-driver-hpcups printer-driver-hpijs
sudo rm -rf /usr/share/hplip/

sudo apt-get autoremove

Then you should perform the following steps:

  1. Step 1: Download the Automatic Installer (.run file) from official link for the Ubuntu or as for today using wget

    wget https://download.sourceforge.net/project/hplip/hplip/3.21.2/hplip-3.21.2.run
    
  2. Step 2: Run the Automatic Installer

    sh hplip-3.21.2.run
    

    Then follow instructions on screen (it should ask password of your sudo-capable user to run apt, and remove hplip-gui files if they were installed). The installation process is already well-documented on HPLIP site.

    After installation it will show printer installation wizard and you can add printer to the system.


Uninstallation

Here we start with binary HPLIP installation (so we do not have HPLIP-related deb-packages installed).

Let's consider that we have installation file hplip-3.21.2.run in the current directory. We need to extract archive from it and then run uninstallation script.

sh hplip-3.21.2.run --noexec
cd hplip-3.21.2
sudo python3 ./uninstall.py
sudo rm -rf /usr/share/hplip/

Afterwards we install official Ubuntu packages instead (optionally):

sudo apt-get install hplip-gui

Note: I have reported bug 1782137 to HPLIP's LaunchPad account asking developers to include uninstallation feature of deb-packages HPLIP components from Ubuntu.


Until a few weeks ago, the latest HPLIP driver version, available at HP Developers - HP Linux Imaging and Printing, was 3.18.12. At Ubuntu 16.04 official repository, the available version was 3.16.3.

First I tried to install the latest version, downloaded from the website. However, a compatibility issue raised with the package python-gobject. As noted by N0rbert (main answer), you need to completely uninstall the actual version of HPLIP before you install another version. Do it manually, as described by N0rbert. After that, ensure that the following files are not present any more (or that the respective folders are empty):

/etc/hp/hplip.conf
/var/lib/hp/hplip.state
/usr/share/hplip/
/usr/share/ppd/hplip
~/.hplip/hplip.conf
/etc/cups/ppd/HP-....ppd

I am not sure if all the files listed above absolutely need to be removed. However, with them gone, I could proceed with the new installation without problems.

Although the repo doesn't have the latest version of the driver, I decided to install it, via apt, because it works without crashing with other preinstalled packages. I did as follows:

  1. sudo apt install hplip (Linux driver for most HP's printers and scanners).

  2. sudo apt install hplip-gui (required by hp-plugin).

  3. hp-plugin (as normal user).

    This plugin is a proprietary "part" of the driver which HP doesn't open-source. The device won't work without it. You will be prompted to accept the terms and install the required plugin for the exact version of the driver you have installed.

  4. hp-doctor (to ensure everything is installed properly, especially the plugin).

  5. hp-setup to add the connected device, or use the HP's software (with graphical interface), already installed at this point.

  6. Go to Ubuntu System Settings and add a new printer/scanner with HPLIP.

PS: By January 2019, the latest version is 3.19.1, which I have not tested.

In general, if you don't really need the latest version of a package, prefer installing the one offered at the official repository. It's much more likely you won't have problems afterwards.