How can I check if a package exists in a repository that's not on my sources.list?

What I want:

Most answers I'm finding assume the repo I need to check is already in my /etc/apt/sources.list.

However, in this exact case, I need to see if a specific package exists in a specific repository that is not yet on my sources.list file. Is this possible?

The package is php8.3-common and the repository is https://packages.sury.org/php/

I was hoping someting like apt-cache show php8.3-common --repository=https://packages.sury.org/php/ exists. Alternatively, if the repository follows some Debian-standard filesystem structure (I would assume so), maybe there's a URL I can hit and get my answer that way.

Why I want it:

I have a script that starts with collecting user input and then does the actual server setup. It has to prompt user for which PHP versions need to be installed, and then check if given versions are available. At that point in time the https://packages.sury.org/php/ repository is not yet configured on the server - this happens later during the setup. So the given PHP versions will be checked against the main Debian repository where most latest versions are not yet available.

The only way out I can think of would be to prematurely add the sury repo to sources.list, but that breaks the logic and script structure. Is there a better way?

1 Answer 1


Got some external help - unless there is a better way, of course

# Download the Packages file
wget -qO "/tmp/Packages.gz" "https://packages.sury.org/php/dists/$(lsb_release -sc)/main/binary-$(dpkg --print-architecture)/Packages.gz"

# Check for the package in /tmp/Packages.gz
if zgrep -q 'Package: example-package' /tmp/Packages.gz; then
    echo "Package example-package is available."
    echo "Package example-package is not available."
  • 2
    Quite bad script. The entire check can be done in one line. And IMHO AI answers are not tolerated here. Commented Mar 29 at 18:31
  • Could you please suggest a better script? You said it could be done in one line. I will then of course delete the AI answer. I posted it here for now in case the question gets no attention and someone else who needs some answer stumbles upon it. Commented Mar 29 at 18:35
  • Better build by self. 1. Use something like: curl URL|zgrep 'Package: example-package' ..... Commented Mar 29 at 18:39
  • 1
    Thanks for the tip, I updated the answer. I kept wget and zgrep separate in case multiple packages will have to be checked in a loop – in that case fetching the list on every iteration would be ineffective Commented Mar 29 at 18:53
  • 1
    You're right, I copied a part of the script and forgot to check the path. Thank you. Commented Mar 29 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .