0

I know how check if new packages are available with root privilegies. But how can I do it from shell script without sudo or editing sudoers. I'm using Debian 12 with openbox. Thanks!

PS. I know about package-update-indicator, but I'd like to use plain shell script solution.

2 Answers 2

2

You can run apt list --upgradable to get a list of all known available updates.

However, this will not be entirely accurate without updating your package sources first, which requires root permissions (sudo apt update).

4
  • The default setup nowadays includes a daily refresh of the repositories, so it shouldn’t be necessary to run apt update manually. Commented Dec 3, 2024 at 9:36
  • How could I check if my system has daily refresh of repo's or not? Commented Dec 3, 2024 at 9:50
  • If you’re using systemd, run systemctl status apt-daily.timer to check that the timer is active, and systemctl status apt-daily.service to see the logs of the last run. Commented Dec 3, 2024 at 10:23
  • And I got this wrong, the service is enabled by default but it doesn’t update repositories by default. Commented Dec 3, 2024 at 10:32
1

When running apt update as user, the following problems appear:

E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied) E: Unable to lock directory /var/lib/apt/lists/ W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied) W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)

Thus one needs a local version of the lists and the cache - by standard both with read access available, yet no writing allowed. With apt-config dump one will see a list of available options and how to modify them. The relevant ones are these:

Dir::State "var/lib/apt"; Dir::State::lists "lists/"; Dir::Cache "var/cache/apt"; Dir::Cache::archives "archives/"; Dir::Cache::srcpkgcache "srcpkgcache.bin"; 
  1. Copy lists and cache to local directory
mkdir /home/user/apt_local cp -r /var/lib/apt/list /home/user/apt_local/lists cp -r /var/cache/apt /home/user/apt_local/cache 
  1. run apt with modified directories
apt update -o DIR::State::lists=/home/user/apt_local/lists -o DIR::Cache=/home/user/apt_local/cache apt list --upgradable -o DIR::State::lists=/home/user/apt_local/lists -o DIR::Cache=/home/user/apt_local/cache 

Of course that easily means a local copy of some 200 MB, and one would have to always make a copy of the latest state to get proper answers.

3
  • @StephenKitt This seems like a very local setting - on my debian system (PC not server), I've never had any automatic updates, nor on my raspbian machines. And at least I would not remember deactivating such setting during installation. Commented Dec 3, 2024 at 10:25
  • 1
    It’s the default setup provided by the apt package (see its apt-daily.timer and apt-daily.service). Commented Dec 3, 2024 at 10:26
  • 1
    My bad, the service is enabled by default but it doesn’t update repositories by default. Commented Dec 3, 2024 at 10:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.