At Ubuntu Desktop 22.04 is installed VirtualBox 7 and if exists the /home/<username>/deb directory - deb is a custom directory - and there is located the virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb file. If is executed the following command:
sudo apt remove virtualbox*
It fails with the following error message:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb
If is executed the sudo apt remove virtualbox* command in other directory where is empty or exists files that do not match the virtualbox* pattern is possible to remove.
Just as an experiment, if in other directory exists the virtualbox.adoc file and if the sudo apt remove virtualbox* command is executed it fails with the following error message:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package virtualbox.adoc
E: Couldn't find any package by glob 'virtualbox.adoc'
Question
Why apt remove tries to remove a file that matches the package name pattern?
I assumed the apt remove command should be able to remove in peace the package installed within the internals paths owned and managed byapt itself. Furthermore through man apt at the install, reinstall, remove, purge (apt-get(8)) section does not appear a note/indication about this behavior
See the How to remove VirtualBox from Ubuntu section. Where exists the sudo apt remove virtualbox virtualbox-* command.
About the commands, because the former is shorter than the latter, it was taken.
As an extra observation, see that in the latter is used virtualbox-* and not virtualbox* as the former. The point is, the latter command works fine (already tested) and was not necessary use neither “” nor ‘’. Interesting this slight difference.
and it results in error because apt cannot find any package named virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb.
If there are no files starting with virtualbox, virtualbox* is passed to apt remove and apt remove expands it to match package names starting with virtualbox.
When you protect glob with double quotes, it is not expanded by the shell immediately. Instead apt remove receives “virtulabox*” and then apt remove command expands to find package names starting with virtualbox.
As usual huge thanks for the polite and valuable feedback.
That’s the reason and origin of the confusion, why does the apt command take in consideration the files within the same directory where it is executed if all the software/repositories managed by apt are stored in a different and specific known path?.
To be honest I assumed from the beginning the files within the same directory where the apt command is executed are completely ignored because they do not represent a software/repository by themselves.
An through man there is no a kind of indication about this behavior
As a friendly suggestion: I am not sure if is valuable to create a tutorial about this situation and add a simple comparison about when this situation enters in action or not according the virtualbox* and virtualbox-* patterns respectively
For that you need to know the working of glob pattern.
By nature, glob virtualbox* gets expanded by shell itself for any matching file names in the current directory.
It’s not apt command’s fault. It’s how the shell behaves with glib pattern (*).
Since the shell already expands the glob, the command becomes sudo apt remove virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb
apt cannot ignore things on its own. It has got some arguments. It checks them and find no package names matching the argument to remove and hence it throws the error.
I don’t think a tutorial will be able to cover for various kinds of situation you could encounter with glob. The forum discussions are the best ways to clear your confusion such as this