How to Install a deb File, by dpkg -i or by apt?

In Linux, the “.deb” refers to the Debian package file usable on Debian-based distributions. To install the packages using the “.deb” files, either the two package managers, i.e., “dpkg” and “apt”, is used. In earlier versions of Debian-based distros, the “dpkg” was supported for “deb” files. However, the recent releases support “apt” to install “.deb” files.

In this write-up, two different package managers are used to install the Debian packages on Ubuntu. The outcomes of this post are:

Let’s start!

How to Install a deb File by dpkg Package Manager?

To install the packages using their deb files, the most convenient approach is to use the dpkg package manager.  Let’s see how it is used:

To understand the usage of the dpkg package manager, we have already downloaded the Debian file of the “Visual Studio Code” from its official website and saved it in the “Downloads” directory with the name “code.deb”. To confirm the download, we will navigate to the “Downloads” directory using the cd command and list its contents with the ls command:

$ cd Downloads && ls

The deb file is downloaded, which can be installed using the dpkg package manager. We will follow the general syntax for the package installation using the dpkg manager:

$ sudo dpkg -i [package name.deb]

To install the Deb file of visual studio code, we will use the “-i” option of the dpkg package manager:

$ sudo dpkg -i code.deb

The package is installed after the successful execution of the above command, and the “i” option is used for the installation in the above command. To confirm the installation of the Visual Studio Code, we will launch the installed application using the command:

$ code

The package of Visual Studio Code has been installed successfully using the Debian files with the dpkg package manager.

How to Remove a deb File by dpkg Package Manager?

After installing the Debian package, we can also remove the installed package by using the dpkg package manager. For the general syntax of removing the Debian package using the dpkg manager, we will use the syntax:

$ sudo dpkg -r [package name.deb]

The “-r” option of the dpkg package manager is used to removing the package. For example, we will remove the installed package of the “Visual Studio Code” using the command:

$ sudo dpkg -r code

The package of the Visual Studio code has been removed.

How to Install a deb File by apt Package Manager?

Another method to install the Debian files is using the apt package manager, the default package manager used to manage the packages in Ubuntu.

The syntax of the command to install the deb file using the apt package manager will be:

$ sudo apt install ./[package name.deb]

Considering the above example of the deb file of Visual Studio Code, we will install it using the apt package manager:

$ sudo apt install ./code.deb -y

The “Visual Studio Code” package has been installed using the apt package manager. In the above command, the “./” is used to locate the deb file of code.deb in the “Downloads” directory.  To confirm the installation of the “Visual Studio Code”, use the command:

$ code

The Visual Studio Code’s screen is a confirmation of the execution of the installation command. 

How to Remove a deb File by apt Package Manager in Ubuntu?

For uninstalling the package installed using the Debian package, we can use the purge option with the apt package manager. For example, to remove the installed package of “Visual Studio Code”, we will run the command:

$ sudo apt purge code -y

The package has been uninstalled from Ubuntu using the apt package manager. Also, if you want to remove only the executables of the package, we will use the “remove” option of the apt package manager:

$ sudo apt remove [package name]

And if you want to remove the configuration files of the installed package using the apt package manager, then we will follow the below-mentioned syntax:

$ sudo apt auto-remove [package name]

The package’s configuration files will be removed.

That’s all from this post!

Conclusion

To install a deb file, either we can use the dpkg package manager with its “-i” option or the apt package manager with its “install” option. Both the package manager can be used to install the Debian packages. Among these, the “apt” is considered an effective package manager compared to “dpkg”. In this write-up, the usage of “dpkg -i” and “apt” is exercised to install a deb file.