3

Can't find any formal explanation to determine whether apt-cache policy <package_name> command requires sudo or not.

Tested it in my machine (Ubuntu) with lots of packages and seems to work, but I'd like to know if there's an scenario where this does not work.

  • 2
    No it doesn't make any changes, and sudo is not required. – guiverc Nov 13 at 12:05
  • Thanks @guiverc! – Cheche Nov 13 at 12:06
6

No, it doesn't make any changes and only grabs public details from your system (also available via http://packages.ubuntu.com/ with a browser though not as useful or machine specific as apt-cache provides) so sudo is not required.

2

When you run apt-cache policy <pkg>, it:

  • checks the repositories in /etc/apt/sources.list and /etc/apt/sources.list.d/*.list to get all the enabled respository addresses

  • based on the above list, gets all the packages matching the pattern from each repository packages file -- these reside in /var/lib/apt/lists/

  • it also checks /var/lib/dpkg/status to get the installation info for the package

It also does some other stuff but not important to go into the details of those.

Now, all it needs is the user has:

  • read-execute permissions for the directories (starting from root leading to it, including all subdirectories)
  • read permission on the relevant files

all the directories mentioned have read-execute by default for others with files having read for others.

As a result, on a default installation of Ubuntu, any user would be able to run apt-cache policy <pkg> without needing any special privilege.

FWIW the binary apt-cache itself has the permission 0755, so is executable by anyone.

  • 1
    Great explanation!, thanks a lot!! – Cheche Nov 14 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.