APT vs APT-GET – Which to Use in Shell Scripting?

apt

apt is the command that is being recommended by the Linux distributions. It provides the necessary option to manage the packages. It is easier to use with its fewer but easy to remember options.

As quoted in itsfoss.com

There is no reason to stick with apt-get unless you are going to do specific operations that utilize more features of apt-get.

  1. apt is a subset of apt-get and apt-cache commands providing necessary commands for package management
  2. while apt-get won’t be deprecated, as a regular user, you should start using apt more often

I get this error when I use apt in shell scripts whereas it does not happen when I use apt-get instead"

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

My questions are:

  1. Why doesn't apt have a stable CLI interface?
  2. How can I use apt with caution or safely?
  3. How can I disable this error message?

Best Answer

apt is the recommended command for interactive use by administrators, not for use in shell scripts.

This is addressed to a large extent in the apt manpage:

The apt(8) commandline is designed as an end-user tool and it may change behavior between versions. While it tries not to break backward compatibility this is not guaranteed either if a change seems beneficial for interactive use.

All features of apt(8) are available in dedicated APT tools like apt-get(8) and apt-cache(8) as well. apt(8) just changes the default value of some options (see apt.conf(5) and specifically the Binary scope). So you should prefer using these commands (potentially with some additional options enabled) in your scripts as they keep backward compatibility as much as possible.

Thus:

  1. apt doesn’t have a stable CLI interface to allow breaking changes, if they’re deemed beneficial.

  2. You can’t, the tool is explicitly not designed for this.

  3. Use apt-get or apt-cache in your scripts to avoid the error message.

Related Question