0% found this document useful (0 votes)
25 views17 pages

Apt Get DPKG

Linux and Shell programming B.tech sem 3rd

Uploaded by

Atul Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views17 pages

Apt Get DPKG

Linux and Shell programming B.tech sem 3rd

Uploaded by

Atul Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

The dpkg Command

What is the dpkg command?


Essentially, the man page describes it like this: “dpkg is a tool to install, build, remove
and manage Debian packages.”

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.

Using the dpkg command

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.

Here’s how you’d install a package.


sudo dpkg -i [package name]
Copy

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.

The dpkg command has got us covered here as well.

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

3. Updating your repositories

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.

The dpkg --update-avail option has got you covered.

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

apt-get command in Linux with Examples


Last Updated : 17 Jul, 2024



The command-line tool `apt-get` is the most popular package


management tool used in our Debian-based Linux operating system.
This article provides an overview of `apt-get` and its basic syntax. It
will include the most commonly used commands, their syntax,
description, and examples. It also gives an explanation of the
contrast to other Linux distributions such as CentOS and Fedora,
which use different package managers, and Debian-based Linux
distributions use APT (Advanced Packaging Tool).
What is apt-get?
apt-get is a command-line tool that helps in handling packages in
Linux. Its main task is to retrieve the information and packages from
the authenticated sources for installation, upgrade, and removal of
packages along with their dependencies. Here APT stands
for Advanced Packaging Tool. It is a Debian-based Linux operating
system, for example, Ubuntu and Debian itself. It is an APT (Advance
Packaging Tool) system. Which manages packages for Debian-
based Linux distributions.
What is Debian-based Linux distributions?
A family of operating systems that are built on the Debian operating
system. They use the same APT (Advance Packaging Tool) for
package management system. Some of the most popular Debian-
based Linux distributions have different features but come under the
same underlying Debian system and package management tools are
Linux Mint, Ubuntu and kali Linux.
One must know when we talk about Red Hat-based distributions like
CentOS and Fedora, they are Linux distributions but not Debian-
based Linux distributions. Red Hat-based Linux distributions are
often preferred for enterprise environments and servers, focusing on
stability and security. Whereas Debian-based Linux distributions
moreover focus on long-term support and stability.
Note: apt-get (package manager) is used in Debian-based Linux
distributions but in Linux distributions like CentOS and Fedora uses
different package manager.
APT-GET Command in Linux
Basic Syntax:
sudo apt-get [options] [command] [package(s)]
Breakdown of each component:
 ` sudo `: We will be using ‘sudo’ before every ‘apt-get’ command
because ‘sudo’ in Linux system is used to execute command with
the administrative privileges (root privileges). In the case of ‘apt-
get’ which is used to manage software packages on Debian-based
Linux systems, we need administrative privileges to install,
remove, update and make other changes.
 `apt-get`: The command itself.
 `[options]`: This is an optional parameter in this we can use `-y`
or `-s` for modifying the behavior of `apt-get` command. `-y` is
for automatically answering “yes” and `-s` is for simulating a
command without making any changes.
 ` [Packages] `: In this we specify the package that we want to
remove, upgrade or install. If we want to mention multiple
packages at same time, specify them by separated spaces
between them.
Most Used Commands [APT-GET]
You need to provide one of the commands below, if the -h option is
not used.
Command
s Description Syntax Example

update Used in Linux-based sudo apt-get sudo apt-get update


operating systems to update
update the package
lists for available
software packages
from the configured
Command
s Description Syntax Example

repositories.

This command is used


to install the latest
versions of the
packages currently
installed on the user’s
system from the
sources enumerated
in /etc/apt/sources.list.
The installed packages sudo apt-get
sudo apt-get upgrade
which have new upgrade
packages available are
retrieved and installed.
You need to perform
an update before the
upgrade so that apt-get
knows that new
versions of packages
upgrade are available.

The command used in


Linux-based operating
systems to upgrade the
sudo apt-get
system by installing
dselect- sudo apt-get dselect-upgrade
and removing packages
upgrade
according to the
dselect- selections made in the
upgrade `dselect`.
Command
s Description Syntax Example

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

number. Also, the user


can select a specific
distribution by
following the package
name with a forward
slash and the version
or the archive name
(e.g., ‘stable’, ‘testing’,
or ‘unstable’). Both of
these version selection
methods have the
potential to downgrade
the packages, so they
must be used with
care.

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.

This command is used


sudo apt-get
to update the package sudo apt-get check
check
cache and check for
check broken dependencies.

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

clean This command is used sudo apt-get sudo apt-get clean


to keep our system clean
clean and tidy. It
removes all the cached
package files that were
downloaded due to the
downloading of recent
packages using `apt-
Command
s Description Syntax Example

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 also gives details


sudo apt-get
(version, architecture list
and repository source) “or”
sudo apt-get list firefox
about package but only sudo apt-get
if package is available list
[package_name
or installed in our
]
list system.

Options Available in `apt-get`:

Options 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.

–install-suggests It works opposite sudo apt-get – sudo apt-get –install-


Options Description Syntax Example

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.

-m or –ignore- By passing this sudo apt-get -m sudo apt-get -m install


missing or –fix- option, the user install apache2
specifies that apt- [package_name
Options Description Syntax Example

get should ignore


the missing
packages
(packages that
]
cannot be
retrieved or fail
the integrity
check) and handle
missing the result.

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.

-s or –simulate or – In this package in sudo apt-get -s sudo apt-get -s install


not actually install firefox
Options Description Syntax Example

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.

It automatically sudo apt-get –


passes no to any assume-no
sudo apt-get –assume-no
question that will install
install apache2
arise during the [package_name
installation of any ]
–assume-no package.

–no-show-upgraded Used to suppress sudo apt-get – sudo apt-get –no-show-


the list of no-show- upgraded upgrade
upgraded upgraded
packages that is upgrade
normally
Options Description Syntax Example

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)

–show-progress Used to display a sudo apt-get – sudo apt-get –show-


bar for the show-progress progress update
progress of the update
command. (Only
used for update
command and has
Options Description Syntax Example

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)

–only-upgrade It upgrades the sudo apt-get sudo apt-get install –only-


package to the install –only- upgrade firefox
newer version upgrade
while stopping the [package_name
installation of ]
other packages
from being
upgraded during
the update
Options Description Syntax Example

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.

You might also like