I have a deb package for installation.

Shall I install by dpkg -i my.deb, or by apt?

Will both handle the software dependency problem well?

If by apt, how can I install from the deb by apt?

  • You could use aptitude which removes unnecessary packages as well. – Ramesh Oct 3 '14 at 16:12
  • 2
    I recommend not to directly use dpkg. In case of single deb, go with gdebi and in case of multiple debs, go for APT local repository. – Pandya Apr 18 '15 at 10:53
  • 7
    why ......... @Pandya – Tim Apr 18 '15 at 10:57
  • 4
    @Tim because dpkg doesn't resolve dependencies. – Pandya Apr 18 '15 at 11:05
  • 4
    @Tim gdebi identifies missing dependencies, can download & install (using apt),can install & configure (using dpkg). – Pandya Apr 18 '15 at 11:12

When you use apt to install a package, under the hood it uses dpkg. When you install a package using apt, it first creates a list of all the dependencies and downloads it from the repository.

Once the download is finished it calls dpkg to install all those files, satisfying all the dependencies.

So if you have a .deb file, you can install it by:

  1. Using:

    sudo dpkg -i /path/to/deb/file
    sudo apt-get install -f
  2. Using:

    sudo apt install ./name.deb


    sudo apt install /path/to/package/name.deb

    With old apt-get versions you must first move your deb file to /var/cache/apt/archives/ directory. For both, after executing this command, it will automatically download its dependencies.

  3. First installing gdebi and then opening your .deb file using it (Right-click -> Open with). It will install your .deb package with all its dependencies.

    Note: APT maintains the package index which is a database of available packages available in repo defined in /etc/apt/sources.list file and in the /etc/apt/sources.list.d directory. All these methods will fail to satisfy the software dependency if the dependencies required by the deb is not present in the package index.

Why use sudo apt-get install -f after sudo dpkg -i /path/to/deb/file (as mentioned in method 1)?

From man apt-get:

 -f, --fix-broken
           Fix; attempt to correct a system with broken dependencies in place.

When dpkg installs a package and a package dependency is not satisfied, it leaves the package in an "unconfigured" state and that package is considered broken.

The sudo apt-get install -f command tries to fix this broken package by installing the missing dependency.

| improve this answer | |
  • 2
    @Tim, apt-get is designed to install packages from repository. It maintains packages list as well as their respective repository address. So just moving a .dev file, which is not present in the apt package list, in /var/cache/apt/archives directory will not work. Because whenever you try to install this package using apt-get, it searches for its repository, which is not present. For this you have to create local repository which I think is useless. – g_p May 6 '15 at 15:41
  • 1
    @g_p thank you! im a little confused in your answer above. you write: "(it will work if the .deb package is present in the apt package list)" - I do not understand what is meant here. How can one ensure that the .deb package is present in the apt package list? – BKSpurgeon Jan 28 '16 at 22:16
  • 2
    @BKSpurgeon, I have added bit information in my answer. To find-out if a package is present in the index or not run apt-cache search <package name>. You can also use apt-cache policy <package name>, which will give some additional information as well. – g_p Jan 29 '16 at 15:10
  • 1
    Will these methods still perform the signature checking usually performed by apt? Or is it possible for a tampered-with .deb file to be installed this way? – Boann Oct 11 '16 at 4:07
  • 14
    Modern apt-get can be uset to install a package simply with apt-get install /path/to/package/name.deb. It would be neat if the author of this answer decided to integrate that. If not, I'll go add that answer sometime when I have enough rep here – Sam Hartman May 31 '17 at 19:10

Install your foo.deb file with dpkg -i foo.deb. If there are some errors with unresolved dependencies, run apt-get install -f afterwards.

| improve this answer | |
  • I got Unable to locate package trying this way and got puzzled. I used as in Windows just name of package after switching to archive folder. Should be ./<file name> for Unix if in current folder or full path. That is if deb is not in folder present in PATH. – Alexei Martianov May 28 '18 at 4:18
  • For scripting, use apt update && dpkg -i foo.deb || apt install -f -y to make sure that foo.deb is not removed by apt install -y. – J P Oct 23 '19 at 13:38

Here's the best way to install a .deb file on Ubuntu on the command-line:

sudo gdebi skype.deb

If you don't have gdebi installed already, install it using sudo apt install gdebi-core.

Why gdebi?

gdebi will look for all the dependencies of the .deb file, and will install them before attempting to install the .deb file. I find this much preferable than sudo dpkg -i skype.deb && sudo apt install -f. The latter is much too eager to remove dependencies in certain situations. For instance, when I tried to install Skype, it attempted to remove 96 (!) packages, including packages like compiz and unity! gdebi gave a much clearer error message:

 $ sudo gdebi skype.deb
 Cannot install 'libqtgui:i386'

(Here is the solution to that particular issue, by the way.)

| improve this answer | |
  • worked great thx! btw, could be that the attempt to remove were about that transitional/temporary packages? or you think it would really break the system? – Aquarius Power Jul 2 '17 at 17:40
  • 1
    Dude I ran into an issue with your solution. I was trying to install Rstudio. It automatically found an old version of R for me. While using the solution by @g_p I was able to install Rstudio only. – Dr_Hope Jan 19 '19 at 0:34

You can install a local .deb package by:

sudo apt install ./foo.deb

Make sure to specify a local relative or absolute path (./ if in current dir), otherwise it will look for foo.deb in the remote repos and fail.

| improve this answer | |
  • 6
    This should be marked as the correct answer. – Rael Gugelmin Cunha Nov 17 '18 at 18:23
  • @RaelGugelminCunha not 100% correct. sudo apt install libstdc++6_8-20180414-1ubuntu2_amd64.deb apt: error while loading shared libraries: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: invalid ELF header – mvladk Jan 31 '19 at 8:17
  • 5
    @mvladk Please, pay attention to the syntax: you're missing the ./ before the deb file. – Rael Gugelmin Cunha Jan 31 '19 at 10:56
  • 2
    Absolutely the best / simplest answer. – gerardw Jul 14 '19 at 16:08

Check the dependencies with dpkg -I my.deb and apt-get install the dependencies before dpkg -i my.deb.

May be you can copy the my.deb in /var/cache/apt/archives and install it directly with apt-get but I never tried. Doesn't work, apt-get and dpkg are looking for packages listed in archives.

| improve this answer | |
  • Thanks. in your first sentenct, do you mean apt-get install my.deb by apt-get install? Is it to install from the deb file? Why do we need dpkg -i my.deb after that? – Tim Oct 3 '14 at 16:04
  • I always installed local .debs with dpkg -i, my understanding is that apt doesn't have an option to install them, apart the directory in /var/cache/... where are downloaded (I may be wrong) – Alex Oct 3 '14 at 16:08
  • It seems that apt-get install ./my.deb will do something, because it outputs a lot of things. What does it do? – Tim Oct 3 '14 at 16:11
  • It does too much :-) doesn't work, see @Igor_Dvoretskyi answer is just perfect, I forgot about -f – Alex Oct 3 '14 at 16:20

The simplest answer would be to use dpkg by running dpkg -i packagename.deb. You could then uninstall it by running dpkg -r packagename.deb.
apt-get is a higher level installer based off of dpkg, and as such you could apt-get install packagename.deb.
It would be beneficial for add it to your apt-get archives directory (/var/cache/apt/archives) so you could reference it as a package with dependencies and not a standalone .deb archive.
Also, by adding it to your apt-get archives directory, you have the opportunity to use dependencies with apt-get install packagename. This would let you install it with any manually added dependencies instead of dpkg's standalone archive-based system.

| improve this answer | |
  • Note: if you want to use apt-get install with a local package file, you must install it in /var/cache/apt/archives, otherwise apt-get may decide to download it anyway. – Anthony Williams Jan 15 at 11:58

Modern apt-get can be used to install a package simply with apt-get install /path/to/package/name.deb.

(should be done as edit to the top answer but it was rejected - see https://unix.stackexchange.com/posts/159114/edit)

| improve this answer | |
  • This did not work with apt for amd64 compiled on Dec 11 2016 09:48:19 – Bruno Bronosky Sep 28 '17 at 22:10

It is very simple if I want to install Chrome.

Install your Chrome file as:

dpkg -i googlechrome.deb.

Sometimes there is a chance of getting some dependency errors like the following:

dpkg: dependency problems prevent configuration of google-chrome-stable:
google-chrome-stable depends on libappindicator1; however:
Package libappindicator1 is not installed.

So to resolve above issues, you need to add dependencies; give the following command:

apt-get install -f

After giving the above command, dependencies will be added to your machine and your Debian package (.deb) file will be installed.

| improve this answer | |

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