Skip to main content

apt-get Command & Examples in Linux [Beginners Guide]

apt-get command & Examples in Linux

apt-get is a command-line tool which 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 the Advanced Packaging Tool.



APT (Advanced Package Tool) is the command line tool to interact with this packaging system. There are already dpkg commands to manage it, but apt is a more user-friendly way to handle packages. You can use it to find and install new packages, upgrade packages, clean your packages, etc.

Syntax:

Command : apt-get [options] command

or


Command : apt-get [options] install|remove pkg1 [pkg2 ...]

or

Command : apt-get [options] source pkg1 [pkg2 ...]


Most Used Commands: You need to provide one of the commands below, if -h option is not used.

update : This command is used to synchronize the package index files from their sources again. You need to perform an update before you upgrade or dist-upgrade.
Command : 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.
Command : apt-get upgrade

dselect-upgrade : This is used alongwith the Debian packaging tool, dselect. It follows the changes made by dselect to the Status field of available packages, and performs any actions necessary to realize that state.


Command : 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.
Command : 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 ‘equals’ 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 must be used with care.
Command : apt-get install [...PACKAGES]

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.


Command : apt-get remove [...PACKAGES]

purge : This command removes the packages, and also removes any configuration files related to the packages.
Command : apt-get purge [...PACKAGES]

check : This command is used to update the package cache and checks for broken dependencies.
Command : apt-get check

download : This command is used to download the given binary package in the current directory.
apt-get download [...PACKAGES]

clean : This command is used to clear out the local repository of retrieved package files. It removes everything but not the lock file from /var/cache/apt/archives/partial/ and /var/cache/apt/archives/.
Command : apt-get clean

autoremove : Sometimes the packages which are automatically installed to satisfy the dependencies of other packages, are no longer needed then autoremove command is used to remove these kind of packages.
Command : apt-get autoremove

Options:

-h or –help : With this option, apt-get displays a short usage summary.
Command : apt-get -h

-v or –version : With this option, apt-get displays it’s current version number.


Command : apt-get  [...COMMAND]

–no-install-recommends : By passing this option, the user lets apt-get know not to consider recommended packages as a dependency to install.
Command : apt-get --no-install-recommends [...COMMAND]

–install-suggests : By passing this option, the user lets apt-get know that it should consider suggested packages as dependencies to install.
Command : apt-get --install-suggests  [...COMMAND]

-d or –download-only : By passing this option, the user specifies that apt-get should only retrieve the packages, and not unpack or install them.
Command : apt-get -d [...COMMAND]

-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.
Command : apt-get -f [...COMMAND]

-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.
Command : apt-get -m [...COMMAND]

–no-download : By passing this command, the user disables downloading for apt-get. It means that it should only use the .debs it has already downloaded.
Command : apt-get  [...COMMAND]

-q or –quiet : When this option is specified, apt-get produces output which is suitable for logging.


Command : apt-get  [...COMMAND]

-s or –simulate or –just-print or –dry-run or –recon or –no-act : This option specifies that no action should be taken, and perform a simulation of events that would occur based on the current system, but do not change the system.
Command : apt-get -s [...COMMAND]

-y or –yes or –assume-yes : During the execution of apt-get command, it may sometimes prompt the user for a yes/no. With this option, it is specified that it should assume ‘yes’ for all prompts, and should run without any interaction.
Command : apt-get -y [...COMMAND]

–assume-no : With this option, apt-get assumes ‘no’ for all prompts.
Command : apt-get --assume-no [...COMMAND]

–no-show-upgraded : With this option, apt-get will not show the list of all packages that are to be upgraded.
Command : apt-get --no-show-upgraded [...COMMAND]

-V or –verbose-versions : With this option, apt-get will show full versions for upgraded and installed packages.
Command : apt-get -V [...COMMAND]

–show-progress : With this option, apt-get will show user-friendly progress in the terminal window when the packages are being installed, removed or upgraded.
Command : apt-get --show-progress [...COMMAND]

-b or –compile or –build : With this option, apt-get will compile/build the source packages it downloads.
Command : apt-get -b [...COMMAND]

–no-upgrade : With this option, apt-get prevents the packages from being upgraded if they are already installed.

Command : apt-get --no-upgrade [...COMMAND]

–only-upgrade : With this option, apt-get will only upgrade the packages which are already installed, and not install new packages.
Command : apt-get --only-upgrade [...COMMAND]

–reinstall : With this option, apt-get reinstalls the packages that are already installed, at their latest versions.
Command : apt-get --reinstall [...COMMAND]

–auto-remove or –autoremove : When using apt-get with install or remove command, this option acts like running the autoremove command.
Command : apt-get install/remove --autoremove [...PACKAGES]

Comments

Popular posts from this blog

Apt-fast for Increasing Download Speed while Installing and Updating Packages Ubuntu/Debian [Beginners Guide]

Have you ever experienced slow download speed when downloading or updating packages in Ubuntu even when your network connection is running fine? You encounter this issue especially when updating and installing packages for the first time after installing a new Ubuntu/Debian OS. However, there is a way to get around this by speeding up the download speed using apt-fast command in Linux. Apt-fast is a shell script wrapper for “apt-get” and “aptitude” that uses the power of either  axel  or  aria 2  download managers to accelerate the download process. It improves download performance by downloading packages simultaneously in parallel with multiple packages per connection. In this article, we will walk through some steps to install apt-fast in order to accelerate the update and downloading process in Ubuntu. We will use Ubuntu 18.04 LTS for describing the procedure mentioned in this article.   Step 1: Installing prerequisites We need to install...

What is a CDN ? How Does a content delivery network Work?

I ntroduction. Latest Web sites and applications often need to provide   amount of static content to end users. This content includes images, style sheets, JavaScript, and video. The increase in the number of static assets and the increase grows the bandwidth usage increases page load time decreased, depending on the size of the user's search experience, and reduce the usable capacity of the server. Dramatically improving performance, reducing the page load time   reduce the bandwidth and infrastructure costs, you can implement a content delivery network,  And  CDN cache these assets at a set of servers that are geographically distributed. What is a CDN? Content delivery network is a group of servers distributed geographically optimized to provide static content to end users. While this static content can be almost any type of data, CDNs are most commonly used to deliver web pages and related files, streaming video and audio, and large softwar...

How To Install PHP 7.4 and PHP 7.3 ON Ubuntu 18.04/19.04/16.04

How to Install PHP 7.4 / PHP 7.3 on Ubuntu?. This guide will help you Install PHP 7.4 / PHP 7.3 on Ubuntu 18 / Ubuntu 16 /  Ubuntu 19 . PHP is an open-source server-side scripting language which has been widely adopted for the creation of dynamic web pages. PHP is secure, fast, simple, efficient, flexible and a loosely typed scripting language. The PHP release 7.4.0 has been made available for the general public and for use in Production environments. How to install PHP 7.4 on Ubuntu 18.04 / Ubuntu 19.04 / Ubuntu 16.04 Step 1: Add PHP 7.4 PPA Repository We’ll add ppa:ondrej/php PPA repository which has the latest build packages of PHP. sudo apt-get update sudo apt -y install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get update Step 2: Install PHP 7.4 on Ubuntu 18/ Ubuntu 19/ Ubuntu 16 Install PHP 7.4 on Ubuntu 18.04/19.04/16.04 using the command: sudo apt -y install php7.4 Check version inst...