• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to use apt Command in Linux

Written by Admin, Updated On December 10, 2022
apt, debian, terminal, ubuntu
How to use apt Command in Linux

APT (Advanced Package Tool) is the command line tool to interact with the packaging system. It helps in handling packages and retrieve the information and packages from the authenticated sources for installation, upgrade and removal of packages along with their dependencies. apt command is a more friendly way to handle packaging.

Mostly, to use apt command you requires superuser privileges so you’ll need to use sudo.

Update package index (apt update)#

The APT package index is a database where it remember the available packages from the repositories which are enabled on your system. apt actually works on a database of available packages. Without database update the system won’t know if there are any newer packages available.

On the updating the package index it will pull the latest changes from the repositories. Run the below command to update the package index:

sudo apt update

When you run this command, you’ll see the package information being retrieving from various servers.

Always remember that, you should update the package index before installing any new packages.

Upgrade Packages (apt upgrade)#

Once you have updated the package database, you can now upgrade the installed packages.

Regularly updating your Linux system is one of the most important aspects of overall system security.

After updating the package database, you can now upgrade the installed packages. This is the most convenient way is to upgrade all the packages that have available updates. Simply use the command below:

sudo apt upgrade

This will show you how many and which all packages are going to be upgrade. Some packages requires removal of installed packages which will not upgrade.

You can upgrade specific package by passing package name as below:

sudo apt upgrade package_name

Install packages (apt install)#

Install package is a easy same as single upgrade package. Run the below command to install any package:

sudo apt install package_name

You can install multiple packages at a single command just by passing a space-separated list:

sudo apt install package_name1 package_name2

Remove Packages (apt remove)#

If you want to remove any package just execute the below command:

sudo apt remove package_name

Same as install, you can remove multiple packages in a single command, pass package names separated by spaces:

sudo apt remove package_name1 package_name2

After uninstalling package using remove some of package files may remain. If you would like to remove completely then you should use purge instead of remove:

sudo apt purge package_name

Remove Unused Packages#

At the time of installation of any package some of dependencies are installed too. So when you uninstall some packages, the dependencies packages are remain on systems. These leftover packages are no longer use by anything else and can be remove.

You can remove the unused packages using:

sudo apt autoremove

Listing Packages (apt list)#

You can use the list command to get list of available, installed and upgradeable packages. Run the below command to get the list of available packages:

sudo apt list

If you need to find any specific package is installed or not you can use grep along with list as below:

sudo apt list | grep package_name

Below command will return the list of only installed packages on your system:

sudo apt list --installed

To get the list of upgradeable packages type:

sudo apt list --upgradeable

Package Information (apt show)#

The information about the package dependencies, installation size, the package source and so on might be useful before removing or installing a new package.

To retrieve information about a given package, use the show command:

sudo apt show package_name

Searching Packages (apt search)#

You also can search a package in the list of available packages:

sudo apt search package_name

If the command will found the nit will print the matched package name.

Conclusion#

It is a good practice to have knowledge of manage packages.

If you have any query for installation of packages or any feedback, feel free to comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install PostgreSQL on CentOS 8
Next Article   How to Disable SELinux on CentOS 8

Related Posts

  • How to Install WordPress with Nginx on Debian 11

    How to Install WordPress with Nginx on Debian 11

    March 22, 2023
  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install PHP 8.2 on Debian 11
    How to Install PHP 8.2 on Debian 11 Linux February 24, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook