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.
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) sosudo
is not required.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 addressesbased 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 packageIt also does some other stuff but not important to go into the details of those.
Now, all it needs is the user has:
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 permission0755
, so is executable by anyone.