Install and Remove Standalone .deb Files




Install and Remove Standalone .deb Files

Use command-line tools to install individual .deb files when other automated tools aren't an option.

The package management for Debian-based distributions like Ubuntu is very powerful and saves a lot of effort that could be wasted finding the latest packages and tracking down dependencies. Automated tools like apt-get, Synaptic, and Adept should serve most users' needs almost all of the time, and you should stick to those tools whenever possible. However, there are some circumstances when you need to install a .deb package directly.

Ubuntu has automated tools for package installation for good reason. These tools provide you with a safety net that ensures packages stay compatible and have the libraries they require. If you install standalone .deb files (especially ones that aren't packaged for your particular Ubuntu release), you not only lose a lot of these advantages, you might also break parts of your system due to incompatible libraries, overwrite files other Ubuntu programs depend on, or add unique versions that make it more difficult to upgrade your system down the road. Before you install a standalone .deb package, especially if you are new to Ubuntu, please exhaust all other available resources, including the universe and multiverse Ubuntu respositories [Hack #60].



You have built your own kernel "the Ubuntu way"

If you have compiled your own kernel source using make-kpkg, you will end up with a .deb package for the kernel binaries, along with .debs for any extra modules you may have built (see "Build Kernels the Ubuntu Way" [Hack #78] for the specific steps in this procedure).


You have compiled your own package from Ubuntu source

As when compiling a kernel, when you compile from Ubuntu source using the dpkg tools, you end up with a standalone .deb that you will need to install manually.


You want to roll back to an older version of a program

This circumstance might show up particularly if you are using a development release of Ubuntu. Sometimes the latest version of a package in a development release has bugs. In these circumstances, you might want to roll back to the previous version of a package. One of the simplest ways to do so is to track down the older .deb (possibly in your local package cache at /var/cache/apt/archives/) and install it manually.


A program you want to install has a .deb but isn't in Ubuntu repositories

There might be some circumstances where a .deb you want to install doesn't appear in your Ubuntu repositories, possibly because it's a newer version than Ubuntu provides, because you have found a generic .deb file you want to install, or because a third party has provided a .deb for Ubuntu but hasn't created its own package repository (such as how the Opera web browser is currently packaged).

Nine times out of 10, if you find a program packaged as a .deb, there's a good chance Ubuntu has already packaged it in one of its repositories. Read "Modify the List of Package Repositories" [Hack #60] for more information about the extra repositories that are available from Ubuntu and third parties.



A program you have installed or upgraded won't fully install due to another package installing the same files

We have seen relatively rare circumstances where two packages provide the same file and when one is upgraded, it errors out with the message that it would overwrite files from another package. In these cases, you need to manually install that package using some of the --force options available to dpkg.

Install a .deb

Whatever the reason, when you find yourself with a .deb to install, it's time to turn to dpkg. dpkg is the tool that Debian-based distributions like Ubuntu use to install .deb files. (Even when you use an automated package-management tool, dpkg is used behind the scenes to actually install the packages to the system.) If you are familiar with the rpm tool for RPM-based distributions, you'll find dpkg has similar syntax. To install an ordinary .deb from the command line, type:

whiprush@ubuntu:~$ sudo dpkg -i 
               
                  packagename
               
               .deb
            

Replace packagename .deb with the .deb file you wish to install. If you have multiple files you want to install at the same time, you can either list them one after another on the command line:

whiprush@ubuntu:~$ sudo dpkg -i 
               
                  package1
               
               .deb
               
                   package2
               
               .deb
               
                   package3
               
               .deb
            

or use a file glob [Hack #13] to install all .deb files in the current directory:

whiprush@ubuntu:~$ sudo dpkg -i 
               *.deb
            

dpkg also has a recursive option (-R). If you have a directory full of debs you want to install, type:

whiprush@ubuntu:~$ sudo dpkg -i -R 
               
                  /path/to/directory
               
            

and dpkg will recursively find and install all .deb files within that directory and its subdirectories.

Occasionally, when you install a package with dpkg, it might abort because a package is marked hold, it conflicts with another package, it depends on other packages that aren't installed, installing the package would overwrite files from another package, or a number of other reasons. dpkg provides a number of --force options you can use to ignore these problems and proceed with package installation.

The --force options are intended only for experts who are extremely familiar with .deb packaging and dependencies within the system. Usually, packages refuse to install for good reasons, and if you are a new user and force the installation anyway, you will more likely than not end up with a broken system. Proceed with caution.


To see the complete list of --force options, type:

whiprush@ubuntu:~$ dpkg --force-help
            

Some of the more useful options include:


--force-hold

Install a package even if it is marked hold.


--force-overwrite

Install a package even if it might overwrite files from another package.


--force-depends

List any missing dependency errors as warnings and proceed anyway.


--force-conflicts

Even if a package conflicts with another package, install anyway.

So if you have a .deb you need to install that overwrites files from another package, and you have done your homework and confirmed that it is OK to proceed, type:

whiprush@ubuntu:~$ sudo dpkg -i --force-overwrite 
               
                  packagename
               
               .deb
            

Remove a Package

Occasionally, you may need to remove a standalone package manually. dpkg provides the -r and -P options to remove and purge packages, respectively. To remove a package, type:

whiprush@ubuntu:~$ sudo dpkg -r 
               
                  packagename
               
            

Note that you don't specify the name of the complete .deb file you might have installed previously, only the name of the package itself. When given the -r option, dpkg will find and remove all of the files for this package except for configuration files, which it leaves behind in case you install the program again. If you want to purge the system of all files, including configuration files, use -P instead:

whiprush@ubuntu:~$ sudo dpkg -P 
               
                  packagename