How to Use the apt Command to Manage Ubuntu Packages

How to Use the apt Command to Manage Ubuntu Packages

The apt command is an effective command line tool for managing packages in Ubuntu and other Linux based systems. In this article, we will discuss the basic apt commands that you can use to install, upgrade, update or remove Ubuntu packages, search installed packages, find dependencies, view information about installed packages, and more.

Basically, the apt command is which administrators can use to perform some of the functions available in the older apt-get and apt-cache commands. However, apt is a simpler command line that delivers several benefits over the other package management tools. It is easy to use, and admins can also include in system administration scripts.

In order to run the apt commands, you need to access the Ubuntu server remotely using a secure shell terminal (SSH).

Remember that the foundation of every successful Ubuntu project lies in a reliable hosting environment. Explore our top picks for the best Linux hosting providers, like HostArmada and Kamatera, to ensure your applications run seamlessly.

Managing packages in Ubuntu

Once you access your Ubuntu server through SSH, you can now start managing the packages. The commonly used commands include install, remove, update, upgrade, search, list, show, and others.

Some of these are used to perform one task at a time, while others have options to do multiple functions. For example, you can use apt to install or remove with multiple packages instead of just one.

The general syntax for apt is this:

$ sudo apt [option] [pkg1] [pkg2] ... ,

In the above expression, the option is the action, such as install, remove, search or show, while the pkg represents the package to install, remove, upgrade, etc.

To learn how to use the apt command, below are the common practical applications.

Installing a Package

The apt command tool allows you to install one or more packages in the Ubuntu system. Type and run the install command in the following syntax;

$ sudo apt install [package name]

For instance, if installing apache2:

$ sudo apt install apache2

By default, the system will prompt you to confirm if you want to continue installing the specified package or not. Type Y and enter to continue or N if you do not want to install the package.

However, you can override this by adding a –y option after the apt. Any install and even remove will happen without requiring any confirmation.

$ sudo apt -y install apache2

Install multiple applications

The apt command can be used to install multiple applications at a go. To do these separate the different package names with a space between them.

Syntax sudo apt install <package1> <package2> <package3>

$ sudo apt -y install apache2 vim

This command will automatically install apache2 and Mplayer without prompting for any additional prompts, such as a confirmation.

Remove One or More Packages

If you want to remove a package, use the apt in the format; sudo apt remove [package name].

If you want to remove the apache2 package:

$ sudo apt remove apache2 vim

This will only remove one application. To remove multiple packages, use the same command while separating the package names with a space:

sudo apt remove apache2 vim

If you want to remove a package without confirming add –y between apt and remove words.

$ sudo apt -y remove apache2

Remove files and configuration

You can use purge to remove the package files and configurations from the system. Use use apt purge followed by the package name:

$ sudo apt purge apache2

Autoclean to Remove Old Downloaded Archive Files

$ sudo apt autoclean

Search For a package

You can search for a package with the “search” option:

$ sudo apt search apache2

Updating the Repository Index or package database

This updates or refreshes the Repository Index file or database of all installed applications as defined in/etc/apt/sources.list or /etc/apt/preferences. It checks if there are new updates and then compares with installed packages. It then updates the repository with newer releases.

$ sudo apt update

After running the command, the system may show results in three categories.

  1. Hit: if there is no need for an update, such as when the packages are of the same version.
  2. Ign: package version is more recent hence ignored.
  3. Get: when there is a new version. The system then downloads the information about the new version. However, it does not download the package itself.

Upgrading packages

Perform this to upgrade installed software with the latest versions available in the package repositories. However, it requires that you first update the package index as above.

To upgrade the packages, use the command

$ sudo apt upgrade

Upgrade just one program

When you do not want to upgrade all the programs, simply specify the particular package.

$ sudo apt upgrade apache2

Install a package without upgrading

Most often, when you install a newer version, it upgrades the package automatically. However, you can choose not to upgrade by adding –no-upgrade option.

$ sudo apt install vim --no-upgrade

List packages

Use the apt command to display all the packages, installed packages, upgradable packages etc.

To list installed packages:

$ sudo apt list --installed

To list upgradable packages

$ sudo apt list --upgradable

View package information

To view package information such as version, size, origin, and a description of what it does, use the command;

$ sudo apt show apache2

Show dependencies

This shows raw dependency information:

$ sudo apt depends apache2

Display policy settings:

$ sudo apt policy

Getting Help with the apt Command

To get help about the apt command usage, use,

$ sudo apt help

The system keeps a log file of the apt activities such as the installs, removals, updates and others that you have performed.

The log file is available on the path /var/log/dpkg.log .

Conclusion

The apt a command line interface is a simple, yet powerful tool that helps administrators in managing packages in Ubuntu and other Linux based systems.

For those serious about their Linux-based projects, considering top-notch Linux hosting providers is a step in the right direction.

The package management tool allows the admins to easily and quickly perform tasks such as installing, upgrading, updating or removing software as well as keeping track of the installed packages.

To use the tool, you need to access your server, usually through SSH which is available via the inbuilt terminal applications in Linux and MAC systems, or through a client tool such as puTTY on a Windows client (Check out the best Windows hosting services).


Check out these top 3 Linux hosting services

FastComet
$1.79 /mo
Starting price
Visit FastComet
Rating based on expert review
  • User Friendly
    4.7
  • Support
    5.0
  • Features
    4.8
  • Reliability
    4.5
  • Pricing
    5.0
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
  • Click this link and all your queries to best hosting will end.

How to Install and Configure Linux Malware Detect on CentOS 7

This tutorial will help you install and configure Linux Malware Detect (LMD) on
4 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install a Let’s Encrypt Certificate on your Ubuntu 18.04 Dedicated Server or VPS

If you are hosting your website on a VPS server running Ubuntu 18.04, we will sh
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to use Git for Version Control on Your VPS or Dedicated Server

This primer will help you get started using Git for version control on your virt
4 min read
Arvind Singh
Arvind Singh
Hosting Expert

How to Install Own Cloud On an an Ubuntu 18.04 Dedicated Server or VPS

You can create your own self-hosted cloud storage services by installing the ope
3 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top