Skip to main content

How to disable "WARNING: apt does not have a stable CLI interface..." [Resolved]

I'm trying to write a script which will output the number of upgrade-able packages from apt. However it keeps giving me this warning with it also:

# sudo apt update | grep packages | cut -d '.' -f 1

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

All packages are up to date

I would like it to just output either:

All packages are up to date


35 packages can be updated

Is there any way to disable that warning? I will be using this returned string, along with some extra information, in a Discord notification from a cron job and it messes up my output pretty wickedly.

I already looked at these, but none of them worked for me:

Question Credit: CorruptComputer
Question Reference
Asked March 15, 2019
Posted Under: Network
3 Answers

First, consider the meaning of the warning you're trying to hide. In theory, apt could change tomorrow to calling them "distributions" instead of "packages" (because it "does not have a stable CLI interface yet") and this would completely break your pipeline. A more likely change would be one which uses the word "packages" in multiple places, causing your pipeline to return extraneous information instead of only the package count you're looking for.

But you're probably not too worried about that, and, realistically, there's no reason you should be. The interface has been stable for years and probably isn't changing any time soon. So how do you make that warning go away?

In the *nix world, output to the command line is generally of two flavors, stdout (standard output) and stderr (standard error). Well-behaved programs send their normal output to stdout and any warnings or error messages to stderr. So, if you want errors/warnings to disappear, you can usually accomplish this by throwing away any messages on stderr using the output redirection 2>/dev/null. (In English, that's "redirect (>) the second output channel (2, which is stderr) to /dev/null (which just throws away everything sent there)".

The answer, then, is:

$ sudo apt update 2>/dev/null | grep packages | cut -d '.' -f 1
4 packages can be upgraded

Side note: In the question, your command is shown as # sudo apt.... The # shell prompt implies that you were probably logged in as root when using that command. If you're already root, you don't need to use sudo.

More on the warning you want to ignore (from man apt):

       The apt(8) commandline is designed as a end-user tool and it may change
       the output between versions. While it tries to not break backward
       compatibility there is no guarantee for it either. All features of
       apt(8) are available in apt-cache(8) and apt-get(8) via APT options.
       Please prefer using these commands in your scripts.

credit: Dave Sherohman
Answered March 15, 2019
Your Answer