The Wayback Machine - https://web.archive.org/web/20241125044800/https://www.geeksforgeeks.org/apt-get-command-in-linux-with-examples/
Open In App

apt-get command in Linux with Examples

Last Updated : 17 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

Commands Description Syntax Example
update                                                                                                                           Used in Linux-based operating systems to update the package lists for available software packages from the configured repositories. sudo apt-get update                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        sudo apt-get update                                                                                                                                                                                                                                                                                                                                                                                                                                          
upgrade              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 which have new 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 are available. sudo apt-get upgrade sudo apt-get upgrade
dselect-upgrade The command used in Linux-based operating systems to upgrade the system by installing and removing packages according to the selections made in the `dselect`. sudo apt-get dselect-upgrade sudo apt-get dselect-upgrade
dist-upgrade This command performs the function of upgrade, and also handles changing dependencies with new versions of packages. If necessary, the apt-get command will try to upgrade important packages at the expense of less important ones. It may also remove some packages in this process. sudo apt-get dist-upgrade
 
sudo apt-get dist-upgrade
 
install This command is used to install or upgrade packages. It is followed by one or more 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 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 install [package_name]
 
sudo apt-get install vim
 
reinstall If we already have a package but we want to reset it to its default state, we can re-install that package.  sudo apt-get install –reinstall [package_name]
 
sudo apt-get install –reinstall firefox
 
remove This is similar to install, with the difference being that it removes the packages instead of installing. It does not remove any configuration files created by the package. sudo apt-get remove [package_name]
 
sudo apt-get remove vim
 
purge This command removes the packages, and also removes any configuration files related to the packages. sudo apt-get purge [package_name]
 
sudo apt-get purge vim
 
check This command is used to update the package cache and check for broken dependencies. sudo apt-get check
 
sudo apt-get check
 
download This command is used to download the given binary package in the current directory. sudo apt-get download [package_name]
 
sudo apt-get download firefox
 
clean This command is used to keep our system clean and tidy. It removes all the cached package files that were downloaded due to the downloading of recent packages using `apt-get`. sudo apt-get clean
 
sudo apt-get clean
 
autoremove Sometimes the packages which are automatically installed to satisfy the dependencies of other packages, are no longer needed then the autoremove command is used to remove this kind of packages. sudo apt-get autoremove
 
sudo apt-get autoremove
 
source If we want to recompile or modify the source code of a package. Source code will be downloaded in current directory in tarball format. sudo apt-get source [package_name]
 
sudo apt-get source firefox
 
show If we want to know more about a package, verify its installation status, version, description, other metadata and dependencies.  sudo apt-get show [package_name]
 
sudo apt-get show firefox
 
list It also gives details (version, architecture and repository source) about package but only if package is available or installed in our system. 

sudo apt-get list
             “or”

 sudo apt-get list [package_name]
 

sudo apt-get list firefox
 

Options Available in `apt-get`:

Options Description  Syntax Example
–no-install-recommends                                                                                                                                                                                                                                                                                                                                                                                                        It will avoid downloading any kind of recommended packages that are not strictly required by the package (installed/upgraded/reinstalled/installed). One must be caution while using this because there may be some package needed for your requirement.                                               sudo apt-get –no-install-recommends [Command] [package_name]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                     
sudo apt-get –no-install-recommends install firefox                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
 
–install-suggests It works opposite of `–no-install-recommends`. It downloads all the suggested packages that are not required much.  sudo apt-get –install-suggests [Command] [package_name]
 
sudo apt-get –install-suggests install firefox
 
-d or –download-only In this package is only downloaded in the location (`/var/cache/apt/archives/`) by default, it is not installed, we can further in future install it. sudo apt-get -d [command] [package_name]
 
sudo apt-get -d install vlc
 
-f or –fix-broken By passing this option, the user specifies that apt-get should attempt to correct the system with broken dependencies in place. sudo apt-get -f install
 
sudo apt-get -f install
 
-m or –ignore-missing or –fix-missing By passing this option, the user specifies that apt-get should ignore the missing packages (packages that cannot be retrieved or fail the integrity check) and handle the result. sudo apt-get -m install [package_name]
 
sudo apt-get -m install apache2
 
–no-download In this `apt-get` is instructed to download packages already available in cache, not to download any package from configured package sources. sudo apt-get –no-download install [package_name]
 
sudo apt-get –no-download install vim
 
-q or –quiet This is used to silence the output errors or displaying warning messages. It is useful while writing scripts. sudo apt-get -q install [package_name]
 
sudo apt-get -q install apache2
 
       
-s or –simulate or –just-print or –dry-run or –recon or –no-act In this package in not actually installed, it just shows what operations it will perform while installing that package. sudo apt-get -s install [package_name]
 
sudo apt-get -s install firefox
 
-y or –yes or –assume-yes It automatically promotes yes while installing a package if there is any request or conformation that has to be taken from user, but one should be careful while using this. sudo apt-get -y [command] [package_name]
 
sudo apt-get -y install vim
 
–assume-no It automatically passes no to any question that will arise during the installation of any package. sudo apt-get –assume-no install [package_name]
 
sudo apt-get –assume-no install apache2
 
–no-show-upgraded Used to suppress the list of upgraded packages that is normally displayed at the end of the upgrade process. (Only works on upgrade command don’t work on install, remove or purge etc). sudo apt-get –no-show-upgraded upgrade
 
sudo apt-get –no-show-upgraded upgrade
 
-V or –verbose-versions Used to display the version number of all the available packages including those that are not even installed. (Only work on update command, not on any other like upgrade, install, remove or purge etc) sudo apt-get -V update
 
sudo apt-get -V update
 
–show-progress Used to display a bar for the progress of the command. (Only used for update command and has no effect on commands like upgrade, install, remove or purge etc) sudo apt-get –show-progress update
 
sudo apt-get –show-progress update
 
-b or –compile or –build build-dep is used to install the build dependencies of the specified packages and `-b` is used to build a package from source.

sudo apt-get build-dep [package_name]

              “or”
sudo apt-get -b source [package_name]
 

sudo apt-get build-dep firefox

                     “or”
sudo apt-get -b source vlc
 

–no-upgrade It is to install a package without upgrading to a new version. (Only works with install command) sudo apt-get install [package_name] –no-upgrade
 
sudo apt-get install vim –no-upgrade
 
–only-upgrade It upgrades the package to the newer version while stopping the installation of other packages from being upgraded during the update process. sudo apt-get install –only-upgrade [package_name]
 
sudo apt-get install –only-upgrade firefox
 
–reinstall It reinstalls the package, even if the package is installed.  sudo apt-get install –reinstall [package_name]
 
sudo apt-get install –reinstall firefox
 
-h or –help It is used to display a help manual. apt-get –help
 
apt-get –help
 

Note: apt-get command will return 0 for successful executions, and decimal 100 in case of errors.

apt-get command in Linux with Examples – FAQs

Difference between apt-get remove and apt-get purge?

Both of `apt-get remove` and `apt-get purge` are used for similar purposes, that is to remove or uninstall the packages from our system. But still, they have a different use case.

`apt-get remove` this command only removes packages from system but leave behind their configuration files. (To see syntax, refer above context)

`apt-get purge` this command is also used to remove packages but in this case configuration files are also removed.  (To see syntax, refer above context)

Difference between apt-get update and apt-get upgrade?

`apt-get update` This command is used to update packages rather than installing them, basically it is used to update local package index with the latest information from the configured source. Remember it does not install packages.

`apt-get upgrade` This command is used to upgrade the packages to the newest version available. Basically, it is used to upgrade and download the packages that are installed in our system.

Syntax for `apt-get update`:

sudo apt-get update
sudo apt-get update

UPDATE

Syntax for `apt-get upgrade`:

In this we going to upgrade firefox,  if it is already upgrade it will show firefox is already upgraded.

sudo apt-get upgrade
sudo apt-get upgrade

UPGRADE

Not able to run `apt-get` in Red Hat Linux?

`apt-get` it is command used for package management but only in Debian-based Linux distributions like mint, Debian and ubuntu, whereas Red Hat Linux is a Linux distribution but does not come under Debian-based Linux distributions. Red Hat Enterprise Linux (RHEL), Fedora and CentOS all will not be able to use `apt-get` instead we can use `dnf` or `yum` package management tools. Just for basic example: we can use `sudo yum update` or `sudo dnf update`.

How to install packages using `apt-get` command?

In this we are going to install firefox package in our Debian-base Linux operating system (In this case we are executing this command in Ubuntu)

Syntax for `apt-get install`:

sudo apt-get install firefox

Installed Packages



Previous Article
Next Article

Similar Reads

Difference Between APT, APT-GET, APT-CACHE and APT-CONFIG
apt, apt-get, apt-cache, and apt-config lie in some specific roles within the Debian package management system. Apt (Advanced Package Tool) is a high-level interface for managing software packages combining the functionalities of apt-get and apt-cache. In this article, we discuss on each component and its play of distinct roles in Debian systems. T
4 min read
sudo apt-get update vs sudo apt-get upgrade: Key Differences Explained
Two basic commands you are likely to utilize when managing software packages on an Ubuntu system are sudo apt-get update and sudo apt-get upgrade. Understanding the differences between these commands is essential for maintaining your system safe and secure. This article will go into detail regarding each command, describing its purposes, best pract
10 min read
How to Fix apt-get command not found in Linux
Linux, celebrated for its power and versatility, can occasionally pose challenges, especially for newcomers. The apt-get command, a vital tool for package management in Debian-based Linux distributions like Ubuntu, is essential for installing, updating, and managing software. However, you may encounter the vexing error message: "apt-get command not
5 min read
apt command in linux with examples
apt provides a high-level Command Line Interface (CLI) for the APT package management system, offering a user-friendly interface intended for interactive use. It simplifies common tasks like installation, upgrades, and removal, with better defaults than more specialized tools like apt-get and apt-cache. Syntaxapt [...COMMANDS] [...PACKAGES]Where, C
5 min read
How to Uninstall Packages With Apt Package Manager in Linux
The apt command is a sophisticated command-line tool that interacts with Ubuntu's Advanced Packaging Tool (APT) to execute tasks including installing new software packages, updating the package list index, and even upgrading the whole Ubuntu system. Along with this, we can uninstall or remove the downloaded packages from the system. So in this arti
2 min read
What is the difference between yum and apt-get?
Package management is a fundamental aspect of any Linux distribution, as it allows users to easily install, update, and remove software packages. Two widely used package managers in the Linux world are yum and apt-get. In this article, we will delve into the details of these package management tools, explain how they work, and highlight the key dif
2 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a Linux and macOS cat command that improved its precursor: the syntax highlighted file contents can be displayed with its help. Therefore, in the case of source code and configuration files, it is extremely helpful. It can highlight over 10 languages, like JavaScript, Java, Ruby, Python, Go, C, and JSON. Syntaxccat [OPTIONS] [FILE...]Basic
3 min read
How to speed up the downloading of packages using apt-fast in Ubuntu?
While updating or installing new packages in ubuntu we often experienced slow downloading speed even while our network connection is running fine. To get around this and speed up the downloads, we use apt-fast wrapper. apt-fast is a shell script wrapper for "apt-get" and "aptitude". It improves downloading speed for packages by providing a correspo
2 min read
How to Install apt-listchanges package on Ubuntu?
Upon collecting the appropriate items from the Debian changelog and NEWS files, the utility apt-listchanges may compare a new version of a package with the one presently installed and display what has changed. It may be run on multiple.deb archives at once to get a list of all changes that would result from installing or updating a set of packages.
3 min read
How To Install apt-offline package on Ubuntu?
Apt-offline adds offline package management features to Debian-based systems. It may be used to download packages and dependencies that will be installed later (or necessary to update) in a disconnected system. Packages can be downloaded from another connected PC. It may also get bug reports for the downloaded packages. Apt-offline is an Offline AP
3 min read
How to Install apt-transport-https package on Ubuntu?
Apt-transport-https is a fake transitory package; in 1.5, https support was relocated into the apt package. It is safe to remove. This is a fake transitory package; in 1.5, https support was relocated into the apt package. It is safe to remove. This is a fake transitory package; in 1.5, https support was relocated into the apt package. It is safe t
3 min read
YUM vs. APT: What's the Difference?
Yum and APT are two of the most popular package management systems in the Linux world, and they are used on various Linux distributions, such as Red Hat-based Linux use yum (Yellowdog Updater Modified) and Debian-based systems use apt (Advanced Packaging Tool). When it comes to updating package information and keeping your system up to date, both A
4 min read
How to Install apt-file package on Ubuntu?
Apt-file is a software program that indexes the contents of packages in your accessible repositories and allows you to search for a certain file among all available packages. Apt-file is a command-line utility for searching files in APT packages. You may search for which package a file is in or show the contents of a package without installing or d
2 min read
How to Install apt-show-versions package on Ubuntu?
If you are using any Linux Distributions like Ubuntu OS, you should know the process to Manage & Verify Installed Packages there. And for that purpose, the Apt-Show-Versions Package on Ubuntu will be the best. With the Ubuntu Apt-Show-Versions Package, you can list down the Ubuntu Packages present in the device. In this article, we will discuss
4 min read
Difference Between APT and DPKG in Ubuntu
The installation, updating, and removal of software are all important functions in the Ubuntu operating system and heavily rely on package management. Two common tools used to manage packages include APT and DPKG, which stands for Debian Package. DPKG is considered the low-level package manager because it makes direct installations and removals of
5 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
fmt command in Linux with examples
fmt command in LINUX actually works as a formatter for simplifying and optimizing text files. Formatting of text files can also be done manually, but it can be really time-consuming when it comes to large text files, this is where fmt comes to rescue. fmt re-formats each paragraph in the file specified, writing to standard output. Here's the syntax
4 min read
anacron command in linux with examples
anacron command is used to execute commands periodically with a frequency specified in days. Its main advantage over cron is that it can be used on a machine which is not running continuously. In cron if a machine is not running on time of a scheduled job then it will skip it, but anacron is a bit different as it first checks for timestamp of the j
3 min read
expect command in Linux with Examples
expect command or scripting language works with scripts that expect user inputs. It automates the task by providing inputs. // We can install expect command using following if not installed // On Ubuntu $sudo apt install expect // On Redhat based systems $ yum install expect First we write a script that will be needing inputs from users and then we
2 min read
function command in Linux with examples
The function is a command in Linux that is used to create functions or methods. It is used to perform a specific task or a set of instructions. It allows users to create shortcuts for lengthy tasks making the command-line experience more efficient and convenient. The function can be created in the user's current shell session or saved in the shell
2 min read
Clear Command in Linux with Examples
clear is a standard Unix computer operating system command that is used to clear the terminal screen. This command first looks for a terminal type in the environment and after that, it figures out the terminfo database for how to clear the screen. And this command will ignore any command-line parameters that may be present. Also, the clear command
2 min read
Continue Command in Linux with examples
continue is a command which is used to skip the current iteration in for, while, and until loop. It is used in scripting languages and shell scripts to control the flow of executions. It takes one more parameter [N], if N is mentioned then it continues from the nth enclosing loop. The syntax for the `continue` command in Linuxcontinue or continue [
2 min read
hostid command in Linux with examples
hostid is a command in Linux that is used to display the Host's ID in hexadecimal format. It provides a quick and straightforward way to retrieve the host ID, allowing administrators to associate it with software licenses or perform system-specific operations. Syntax of `hostid` command in Linuxhostid [OPTION] Options provided by hostedhostid --hel
1 min read
chpasswd command in Linux with examples
chpasswd command is used to change password although passwd command can also do same. But it changes the password of one user at a time so for multiple users chpasswd is used. Below figure shows the use of passwd command. Using passwd we are changing the password of the guest user. Here first you have to enter the password of the currently signed u
2 min read
lsmod command in Linux with Examples
lsmod command is used to display the status of modules in the Linux kernel. It results in a list of loaded modules. lsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded. Syntax: lsmod Example: Run lsmod at the command line to list all active kernel modules. lsmod Output:
1 min read
emacs command in Linux with examples
Introduction to Emacs Editor in Linux/Unix Systems: The Emacs is referred to a family of editors, which means it has many versions or flavors or iterations. The most commonly used version of Emacs editor is GNU Emacs and was created by Richard Stallman. The main difference between text editors like vi, vim, nano, and the Emacs is that is faster, po
5 min read
host command in Linux with examples
host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more specific details of a domain by specifying the corr
2 min read
yes command in Linux with Examples
yes, the command in Linux is used to print a continuous output stream of a given STRING. If STRING is not mentioned then it prints 'y'; Syntax: of `yes` command in Linuxyes [STRING] Note: To stop printing please press Ctrl + C. Use of `yes` commandlet us say that we want to delete all the `.txt` files present in the current directory. Instead of wr
2 min read
three90RightbarBannerImg