That’s where virtual packages come in! They allow you to create a fake version of a package that satisfies the dependencies without actually installing it. This can be really helpful when dealing with broken or outdated systems, as well as for testing purposes.
Here’s how it works: let’s say we want to create a virtual package called “awesome-things-virtual” that provides version 10 of the “awesome-things” library. First, we need to edit our system’s sources list (usually located in /etc/apt/sources.list) and add this line:
# This script creates a virtual package called "awesome-things-virtual" that provides version 10 of the "awesome-things" library.
# First, we need to edit our system's sources list (usually located in /etc/apt/sources.list) and add this line:
# Add the "deb" command to specify that we are adding a new repository to our sources list
# Add the "[trusted=yes]" option to allow the system to trust the repository without prompting for confirmation
# Add the "file://" prefix to indicate that the repository is a local file
# Replace "/path/to/your/repo" with the actual path to the repository
# Replace "awesome-things-virtual" with the name of the virtual package we want to create
# Replace "main" with the component of the repository where the package is located
deb [trusted=yes] file:///path/to/your/repo awesome-things-virtual main
This tells APT to look for packages in the local repository at “/path/to/your/repo” instead of using the default repositories. Next, we need to create a new package called “awesome-things_10.0~virtual.deb”. This file should contain the following lines:
# This tells APT to look for packages in the local repository at "/path/to/your/repo" instead of using the default repositories.
# The "Package" keyword indicates the name of the package.
# The "Version" keyword indicates the version of the package.
# The "Architecture" keyword indicates the system architecture the package is compatible with.
# The "Depends" keyword indicates the dependencies required for the package to function properly.
# The "Description" keyword provides a brief description of the package.
Package: awesome-things-virtual
Version: 10.0~virtual
Architecture: all
Depends: awesome-things (>= 10) | awesome-things-virtual
Description: Virtual package providing version 10 of the awesome-things library
# The "awesome-things-virtual" package is a virtual package, meaning it does not contain any actual files but serves as a placeholder for other packages.
# The "Version" specifies the version of the virtual package.
# The "Architecture" is set to "all" to indicate that the package is compatible with all system architectures.
# The "Depends" specifies the dependencies required for the package, in this case, either "awesome-things" version 10 or "awesome-things-virtual".
# The "Description" provides a brief description of the package's purpose.
The “Depends” line is what makes this a virtual package. It says that we either need to have the real “awesome-things” package installed (if it’s available) or use our own fake one (“awesome-things-virtual”). Now, when you run `apt update` and then `apt install cool-stuff`, APT will see that “cool-stuff” requires version 10 of the “awesome-things” library. If it can’t find a real package with that version number, it will use our virtual one instead!
This might seem like cheating or hacking, but in reality it’s just a clever way to work around broken systems and make life easier for everyone involved.