aptly remove a package from a repository using the cli

Here is a fast tip – how to remove a package from our local aptly repository:

  1. Remove the package from the local repository.
  2. Create a new snapshot form the local repository.
  3. Publish the snapshot by switching to the newly created snapshot from the above step.

The commands executing over repository with name xenial-apps to remove package with name example-app and version 10.5.1.22-ubuntu20. The snapshot name xenial-apps1588149526 is just a temporary name used for the snapshot (the ID is unix timestamp of the current time).

aptly repo remove  xenial-apps 'example-app (= 10.5.1.22-ubuntu20)'
aptly snapshot create xenial-apps1588149526 from repo xenial-apps
aptly publish switch xenial-apps ubuntu xenial-apps1588149526

Real world example.

This is the log from our system with just changed names:

Initial state and configuration.

root@srv: ~ # su - aptly
aptly@srv:~$ aptly repo list
List of local repos:
 * [test]: Test repo (packages: 0)
 * [xenial-apps] (packages: 2681)

To get more information about local repository, run `aptly repo show <name>`.

aptly@srv:~$ aptly snapshot list
List of snapshots:
 * [xenial-apps1481544472]: Snapshot from local repo [xenial-apps]
 
To get more information about snapshot, run `aptly snapshot show <name>`.

aptly@srv:~$ aptly publish list
Published repositories:
  * ubuntu/xenial-apps [amd64] publishes {main: [xenial-apps1588819449]: Snapshot from local repo [xenial-apps]}

Switch to the aptly user, because all configuration and files are under this user (for more information our installation guide – Install aptly under Ubuntu 18 LTS with nginx serving the packages and the first steps)

Removing the package ‘example-app (= 10.5.1.22-ubuntu20)’

aptly@srv:~$ aptly repo remove  xenial-apps 'example-app (= 10.5.1.22-ubuntu20)'
Loading packages...
[-] example-app_10.5.1.22-ubuntu20_amd64 removed

aptly@srv:~$ aptly snapshot create xenial-apps1588149526 from repo xenial-apps

Snapshot xenial-apps1588149526 successfully created.
You can run 'aptly publish snapshot xenial-apps1588149526' to publish snapshot as Debian repository.

aptly@srv:~$ aptly publish switch xenial-apps ubuntu xenial-apps1588149526
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "ubuntu" components main...

Publish for snapshot ubuntu/xenial-apps [amd64] publishes {main: [xenial-apps1588149526]: Snapshot from local repo [xenial-apps]} has been successfully switched to new snapshot.

Repository state after removing the package

aptly@srv:~$ aptly repo list
List of local repos:
 * [test]: Test repo (packages: 0)
 * [xenial-apps] (packages: 2680)

To get more information about local repository, run `aptly repo show <name>`.

aptly@srv:~$ aptly snapshot list
List of snapshots:
 * [xenial-apps1481544472]: Snapshot from local repo [xenial-apps]
 * [xenial-apps1588149526]: Snapshot from local repo [xenial-apps]
 
To get more information about snapshot, run `aptly snapshot show <name>`.

aptly@srv:~$ aptly publish list
Published repositories:
  * ubuntu/xenial-apps [amd64] publishes {main: [xenial-apps1588149526]: Snapshot from local repo [xenial-apps]}

Note 1) Removing package only from the “repo” is not enough.

Removing packages from the repository only will just remove the file, but the metadata won’t be updated and the package won’t be installable any more, but apt will say the package exists.

root@srv2 ~ # apt update
Hit:1 http://aptly.example.com/ubuntu xenial-apps InRelease
Fetched 28.1 kB in 1s (35.7 kB/s)                  
Reading package lists... Done
Building dependency tree       
Reading state information... Done
root@srv2 ~ # apt search example-app
Sorting... Done
Full Text Search... Done
example-app/xenial-apps 10.5.1.22-ubuntu20 amd64 [upgradable from: 10.5.1.21-ubuntu20]
  Example apps version of xenial-apps - 10.5.1.21-ubuntu20

root@srv2 ~ # apt install example-app/xenial-apps 10.5.1.22-ubuntu20
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package 10.5.1.22-ubuntu20
E: Couldn't find any package by glob '10.5.1.22-ubuntu20'
E: Couldn't find any package by regex '10.5.1.22-ubuntu20'

Still upgradable by apt metadata, but the package files are not available anymore.

Leave a Reply

Your email address will not be published.