×

apt-get Command in Linux with Examples

The apt-get command is a command-line tool that is used to handle packages in Linux. This command handles the processes like retrieving the packages and information from authentic sources for upgradation, installation, and removal of packages along with their reliabilities. In this command “apt” stands for Advanced Packaging Tool. If the execution is successful, the apt-get command returns 0, and in case of an error, it returns decimal 100.

The syntax for the apt-get command:

apt-get [options] command
or
apt-get [options] install|remove pkg1 [pkg2 ...]
or
apt-get [options] source pkg1 [pkg2 ...]

Widely used commands with the apt-get command

If we do not use the -h option, then we have to use any one of the commands given below:

  • update: Before dist-upgrading and upgrading, we have to perform an update. If we again want to contemporize the package index files from their sources, then the update command is used.
apt-get update
  • upgrade: To install the latest version of the package that is currently being used on the user’s device, the upgrade command is used, and the latest version is installed from the sources those are listed in /etc/apt/sources.list. If new packages are available then the packages that had been already installed are recovered and installed. We know that before upgrading, the update has to be performed so that the apt-get command gets to know about new versions available.
apt-get upgrade
  • dselect-upgrade: The dselect-upgrade command is used with the Debian packaging tool, dselect. It checks the changes made to the status field of available packages by dselect, and it performs any mandatory operations to bring in that state.
apt-get dselect-upgrade
  • dist-upgrade: The dist-upgrade command is also used to perform the task of upgrading, and this command also manages to change holdings with the new version of packages. If it is important, the apt-get command will upgrade the important packages only, and some of the packages get removed in this process.
apt-get dist-upgrade
  • install: To upgrade or install the packages, the install command is used. With this command, the names of the packages that one wishes to install shouldbe provided. If the user wants any specific version to install, then the package name must be followed by an “equal” (=) sign, and the number of the version he desires. And if desired, then a specific distribution can also be selected by following the package name with a “forward slash” (/) and the archive or version name. The packages can be downgraded if any of these selection methodsare not used carefully.
apt-get install [...PACKAGES]
  • remove: The remove command is used when the user wants to remove the packages. It removes the packages but does not remove the presentation files created by the package.
apt-get remove [...PACKAGES]
  • purge: The purge command removes the packages along with the presentation files created by or related to the packages.
apt-get purge [...PACKAGES]
  • check: The check command checks for broken dependencies and update the package cache.
apt-get check
  • download: If we want to download any binary package in the given directory, then the download command is used.
apt-get download [...PACKAGES]
  • clean: To clear the local repository of the recovered package files, the clean command is used. Everything gets erased except the lock file forms /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.
apt-get clean
  • autoremove: Some packages get automatically installed to support some packages, and after that, they are not required, then to remove these kinds of unwanted packages the autoremove command is used.
apt-get autoremove

Some widely used options with the apt-get command

  • -no-install-recommends: By passing the-no-install-recommends option, the user can stop the apt-get command to consider suggested packages as a dependency to install.
apt-get --no-install-recommends [...COMMAND]
  • -install-suggests: By passing the -install-suggests option, the user gives the apt-get command, the authority to consider suggested packages as a dependency to install.
apt-get --install-suggests [...COMMAND]
  • -download-only or -d: By passing any one of the -download-only or -doptions, the user allows the apt-get command to only recover the package, but not install or unpack them.
apt-get -d [...COMMAND]
OR
apt-get -download-only [...COMMAND]
  • -fix-broken or -f: By passing any one of the -fix-broken or -f options, the user permits the apt-get command to correct the broken holdings in place, in the system.
apt-get -f [...COMMAND]
OR
apt-get -fix-broken [...COMMAND]
  • -fix-missing or -ignore-missing or -m: By passing any one of the -fix-missing or -ignore-missing or -moptions, the user lets the apt-get command know that to ignore the packages that could not be recovered and take care of the result.
apt-get -m [...COMMAND]
OR
apt-get -fix-missing [...COMMAND]
OR
apt-get -ignore-missing [...COMMAND]
  • -no-download: The -no-downloadoption is passed when the user does not want the apt-get command to download anything.
apt-get-no-download [...COMMAND]
  • -quiet or -q: After passing the -quiet or -qoption, the apt-get command only returns the output that is suitable for registering.
apt-get -quiet [...COMMAND]
OR
apt-get -q [...COMMAND]
  • -no-act or -recon or -dry-run or -just-print or -simulate or -s: This option is passed to ensure that no action should be taken, and perform cloning of events that would occur according to the existing system, but it does not alter the system.
apt-get -no-act [...COMMAND]
OR
apt-get -recon [...COMMAND]
OR
apt-get -dry-run [...COMMAND]
OR
apt-get -just-print [...COMMAND]
OR
apt-get -simulate [...COMMAND]
OR
apt-get -s [...COMMAND]
  • -yes or -assume-yes or -y: During the execution of the program, many times a condition is reached when the user is asked to select any one yes/no, so this option, by default assumes the input as yes for all the prompts, will run without any interaction with the user.
apt-get -yes [...COMMAND]
OR
apt-get -assume-yes [...COMMAND]
OR
apt-get -y [...COMMAND]
  • -assume-no: This option is passed to assume all the prompts as no.
apt-get --assume-no [...COMMAND]
  • -no-show-upgraded: This option is used to hide the list of all packages that have to be upgraded.
apt-get --no-show-upgraded [...COMMAND]
  • -verbose-versions: This option shows all the versions of the upgraded packages and installed packages.
apt-get -verbose-versions [...COMMAND]
  • -show-progress: This option shows the progress in the terminal when any package is being upgraded, installed, or removed.
apt-get --show-progress [...COMMAND]
  • -compile or -build: This option helps the apt-get command to compile the source packages that are being downloaded.
apt-get -compile [...COMMAND]
OR
apt-get -build [...COMMAND]
  • -autoremove or -auto-remove: When the install or remove command is used with the apt-get command, this option runs like the autoremove command.
apt-get install/remove --autoremove [...PACKAGES]
  • -h or -help: The apt-get command displays a short usage summary when used with this option.
apt-get -h

Output:

apt-get Command in Linux with Examples
  • --version or -v: The apt-get command displays the current version number when used with this option.
apt-get --version

Output:

apt-get Command in Linux with Examples

Related Topics

unzip Command in Linux/Unix with Examples

The 'unzip' command in Linux is used to extract files from a ZIP archive file. The command allows you to decompress and extract the files and directories stored in a...

3 minutes read.

cat Command in Linux/Unix with Examples

The cat command in Linux is a command-line utility that is used to display the contents of a text file. It stands for "concatenate" and it is used to view...

4 minutes read.

echo Command in Linux/Unix with Examples

The "echo" command in Linux is used to display a line of text on the terminal. It can also be used to print the value of a variable or to...

3 minutes read.

tail Command in Linux/Unix with Examples

The "tail" command in Linux (and other Unix-like operating systems) is used to display the last few lines of a file. By default, the tail command will display the last...

4 minutes read.

telnet Command in Linux/Unix with Examples

The telnet command in Linux is a command-line utility that allows you to connect to a remote host using the Telnet protocol. Telnet is a network protocol that provides a...

3 minutes read.

du Command in Linux/Unix with Examples

The "du" command in Linux (and other Unix-like operating systems) is used to estimate the space used by a file or directory. The du command stands for "disk usage," and...

4 minutes read.

top Command in Linux/Unix with Examples

The 'top' command in Linux is a real-time system monitoring tool that displays information about the running processes and system resource usage. The command provides a dynamic, scrolling view of...

4 minutes read.

grep Command in Linux/Unix with Examples

The grep command in Linux is a command-line utility that searches for patterns in text files. It stands for "global regular expression print" and it is used to search for...

5 minutes read.

tar Command in Linux/Unix with Examples

The 'tar' command in Linux is used to create, maintain, and extract files from archive files called tarballs. The command stands for "tape archive" and it allows you to combine...

4 minutes read.

Linux SCP Command

SCP stands for secure copy protocol. It is a command-line application for copying files and directories safely between two places. Command-line utilities are programs that operate on a computer's command...

3 minutes read.

addgroup Command in Linux with Examples

What is the addgroup command? It is a command in Linux to create a new group using specified command lined and the system’s default values. How to add groups Adding a user group:...

4 minutes read.

netstat Command in Linux/Unix with Examples

The "netstat" command in Linux is a command-line utility that displays network connections, routing tables, and various network statistics. It is used to display the status of network connections, both...

3 minutes read.

Linux Admin Tutorial

In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document without relying on meaningful content....

1 minute read.

man Command in Linux/Unix with Examples

The man command in Linux is used to display the manual pages for a given command or system call. These manual pages provide detailed information on the command's usage, options,...

3 minutes read.

mv Command in Linux/Unix with Examples

The 'mv' command in Linux is used to move or rename files and directories. The command stands for "move" and it allows you to move files and directories from one...

3 minutes read.

sed Command in Linux/Unix with Examples

The 'sed' command in Linux is a powerful text processing tool that allows you to perform various operations on text files, such as searching, replacing, and manipulating text. The command...

3 minutes read.

Linux Absolute and Relative Path

The concept of the absolute and relative path is very simple. The names “relative path” and “absolute path” give us little understanding of the concept we are learning here. The...

1 minute read.

rm Command in Linux/Unix with Examples

The "rm" command in Linux (and other Unix-like operating systems) is used to remove files and directories. The "rm" command stands for "remove" and it is used to delete files...

4 minutes read.

cut Command in Linux/Unix with Examples

The "cut" command in Linux (and other Unix-like operating systems) is used to remove sections from each line of a file or stream of data. The cut command is often...

3 minutes read.

chown Command in Linux/Unix with Examples

The 'chown' command in Linux is used to change the ownership of a file or directory. The command stands for "change owner" and it allows you to change the user...

3 minutes read.