Apt Get DPKG
Apt Get DPKG
We use the dpkg command to interact with packages on our system. It is controlled fully
with the help of command-line parameters and the first parameter is referred to as the
action parameter that is used to direct what to do. This parameter may or may not be
followed by any other parameter.
Later, a new tool named aptitude was designed to provide a more user-friendly,
interactive front-end for the users to manage packages without the complexity of
the dpkg command. It interacts with the dpkg interface on behalf of the user. Now, let’s
try and understand the dpkg command in Linux.
The Basics of the dpkg Command in Linux
Here’s what the basic syntax of the dpkg command looks like:
dpkg [options] [.deb package name]
The dpkg command provides a long list of options to customise the data we receive
while analyzing our network. Here is a list of some of the most popular dpkg options.
Option Function
Install a package using the dpkg command. The command will extract all control files for the specified
-i OR --
package, remove any previously installed older instance of the package, and install the new package on
install
our system.
-r OR -- Remove an installed package from our system. It removes every file belonging to the specific package
remove except the configuration files. This can be seen as the uninstallation option.
-P OR -- An alternative way to remove an installed package from our system. It completely removes every fie
purge belonging to the specific package, including the configuration files. This can be seen as the ‘complete
uninstallation’ option.
--update- Uhe information of the dpkg command about available packages in its repositories. If new packages are
avail available, they are synced from the official repositories.
--merge- Merge the information of the dpkg command about available packages in its repositories with
avail previously available information. It is usually run right after the previous command.
--help Display the help page for the dpkg command and exit.
These are some of the most commonly used options for the dpkg command and you
can explore more by displaying the help options in your terminal.
Let us explore the common uses of the dpkg command. As the command works the
same for both Debian and Ubuntu systems, we will only mention Ubuntu in this tutorial
from now on.
1. Installing a package
The most basic use of the dpkg command in Ubuntu is a package installation. We can
install a deb package in Ubuntu or Debian using the dpkg -i command option.
We’re installing the VLC player on our Ubuntu system. Have a look at the below
screenshot for what the installation looks like on screen.
Dpkg Command
You can also install multiple packages at the same time by specifiying the package
names separated by spaces.
2. Removing a package
When you no longer need a program or service on your system, there is no use keeping
it.
We can uninstall a program or service from our system using the dpkg -r option.
Let’s remove the VLC player that we installed for this demonstration.
sudo dpkg -r [package name]
Copy
Look at the below screenshot to see how dpkg triggers changes for all the dependent
menus, desktop icons, etc similar to the apt command.
Dpkg R
Vlc
The dpkg repository stores all the packages available for installation on your Ubuntu or
Debian Linux distribution.
However, as these packages are stored locally you can often end up having old
versions of packages for a program when newer versions have already been released.
This causes a need for a method to update your repositories.
It checks the online repositories and downloads all the updated packages to your local
repository.
Let’s update our local repositories to the latest version:
sudo dpkg --update-avail
repositories.
This command
performs the function
of upgrade, and also
handles changing
dependencies with
new versions of
packages. If necessary, sudo apt-get
sudo apt-get dist-upgrade
the apt-get command dist-upgrade
will try to upgrade
important packages at
the expense of less
important ones. It may
also remove some
dist- packages in this
upgrade process.
install This command is used sudo apt-get sudo apt-get install vim
to install or upgrade install
packages. It is followed [package_nam
by one or more e]
package names the
user wishes to install.
All the dependencies of
the desired packages
will also be retrieved
and installed. The user
can also select the
desired version by
following the package
name with an ‘equal’
and the desired version
Command
s Description Syntax Example
sudo apt-get
If we already have a
install –
package but we want sudo apt-get install –reinstall
reinstall
to reset it to its default firefox
[package_nam
state, we can re-install
e]
that package.
reinstall
remove This is similar to install, sudo apt-get sudo apt-get remove vim
with the difference remove
being that it removes [package_nam
the packages instead of e]
installing. It does not
remove any
configuration files
Command
s Description Syntax Example
created by the
package.
This command
sudo apt-get
removes the packages,
purge
and also removes any sudo apt-get purge vim
[package_nam
configuration files
e]
related to the
purge packages.
sudo apt-get
This command is used
download
to download the given sudo apt-get download firefox
[package_nam
binary package in the
e]
current directory.
download
get`.
Sometimes the
packages which are
automatically installed
to satisfy the
sudo apt-get
dependencies of other sudo apt-get autoremove
autoremove
packages, are no
longer needed then the
autoremove command
autoremov is used to remove this
e kind of packages.
If we want to
recompile or modify sudo apt-get
the source code of a source
sudo apt-get source firefox
package. Source code [package_nam
will be downloaded in e]
current directory in
source tarball format.
If we want to know
more about a package, sudo apt-get
verify its installation show
sudo apt-get show firefox
status, version, [package_nam
description, other e]
metadata and
show dependencies.
Command
s Description Syntax Example
It will avoid
downloading any
kind of
recommended
packages that are
sudo apt-get –
not strictly
no-install-
required by the sudo apt-get –no-install-
recommends
package recommends install
[Command]
(installed/upgrade firefox
[package_name
d/reinstalled/inst
]
alled). One must
be caution while
using this because
there may be
some package
–no-install- needed for your
recommends requirement.
of `–no-install-
recommends`. It install-suggests
downloads all the [Command]
suggests install firefox
suggested [package_name
packages that are ]
not required
much.
In this package is
only downloaded
in the location sudo apt-get -d
(`/var/cache/apt/ [command]
sudo apt-get -d install vlc
archives/`) by [package_name
default, it is not ]
installed, we can
-d or –download- further in future
only install it.
By passing this
option, the user
specifies that apt-
get should sudo apt-get -f
sudo apt-get -f install
attempt to correct install
the system with
broken
dependencies in
-f or –fix-broken place.
In this `apt-get` is
instructed to
sudo apt-get –
download
no-download
packages already sudo apt-get –no-
install
available in cache, download install vim
[package_name
not to download
]
any package from
configured
–no-download package sources.
This is used to
silence the output
sudo apt-get -q
errors or
install sudo apt-get -q install
displaying
[package_name apache2
warning
]
messages. It is
useful while
-q or –quiet writing scripts.
installed, it just
shows what
[package_name
operations it will
just-print or –dry- ]
perform while
run or –recon or – installing that
no-act package.
It automatically
promotes yes
while installing a
package if there is sudo apt-get -y
any request or [command]
sudo apt-get -y install vim
conformation that [package_name
has to be taken ]
from user, but
one should be
-y or –yes or – careful while
assume-yes using this.
displayed at the
end of the
upgrade process.
(Only works on
upgrade
command don’t
work on install,
remove or purge
etc).
Used to display
the version
number of all the
available
packages
including those
sudo apt-get -V
that are not even sudo apt-get -V update
update
installed. (Only
work on update
command, not on
any other like
upgrade, install,
-V or –verbose- remove or purge
versions etc)
no effect on
commands like
upgrade, install,
remove or purge
etc)
build-dep is used
to install the build sudo apt-get
dependencies of build-dep
sudo apt-get build-dep
[package_name]
the specified firefox
“or”
packages and `-b` “or”
sudo apt-get -b
is used to build a sudo apt-get -b source vlc
source
-b or –compile or – package from [package_name]
build source.
It is to install a
sudo apt-get
package without
install sudo apt-get install vim –
upgrading to a
[package_name no-upgrade
new version.
] –no-upgrade
(Only works with
–no-upgrade install command)
process.
sudo apt-get
It reinstalls the
install –reinstall sudo apt-get install –
package, even if
[package_name reinstall firefox
the package is
]
installed.
–reinstall
It is used to
apt-get –help apt-get –help
display a help
-h or –help manual.