What are some different Aptly commands?

Key takeaways:

  • A repository management tool for debian, facilitating management, mirroring, and merging of package repositories.

  • Use aptly mirror create, aptly mirror update, and aptly mirror drop to manage local mirrors of remote repositories.

  • Use aptly repo create to set up local repositories and aptly repo remove to clean up outdated packages.

  • Utilize aptly snapshot merge and aptly snapshot filter to merge several snapshots into one, resolving package versions and filtering a source snapshot to create a new one based on specified packages, respectively.

Aptly is a repository management tool in debian. Aptly enables managing, mirroring, and merging repositories of packages. It also allows taking snapshots of repositories, publishing them, and merging them. We are going to look at a few important commands of Aptly.

Before using Aptly, ensure it's installed on the system. We can install it using the following command:

apt-get install aptly

If we want to check whether it is installed or not, we can use the following command:

aptly version

Let us run the above commands in the following terminal to see how Aptly is installed and its version:

Terminal 1
Terminal
Loading...

Aptly commands categories

Aptly commands are divided into multiple categories. We will discuss commands from three categories. These names are also added to the commands of the relevant category:

  • mirror

  • repo

  • snapshot

In the case of these categories, the name of these categories corresponds to the component they operate on. For example, the aptly mirror <command name> command works with mirrors.

Category 1: mirror commands

We use aptly mirror <command> to run commands that work with mirrors. The mirror category is essential for users who want to manage upstream repositories. It allows us to create and maintain a local mirror of a remote Debian repository.

Here are some of the mirror commands:

1. aptly mirror create

This command creates mirrors of repositories. It helps in setting up a local repository that mirrors packages from a specified remote source. Here is how we can use it:

aptly mirror create <name> <archive url> <distribution> [<component1> ...]
  • <name>: This will be the name of the mirror.

  • <archive url>: This is the address of the root of the archive for which the command creates a mirror.

  • <distribution>: This is the name of the distribution of the repository.

  • [<component1> ...]: This is the optional list of components we can download. Leaving it empty will result in the command downloading all the components.

2. aptly mirror update

This command updates remote mirrors. It is also used to download mirror contents right after a mirror is created. Here is how we can use it:

aptly mirror update <name>
  • <name>: This is the name of the mirror we wish to update.

Regularly run this command to ensure your local mirror stays up-to-date with the latest packages and versions.

3. aptly mirror drop

This command deletes a specified mirror. When a mirror is no longer needed, use this command to clean up the Aptly setup.

aptly drop <name>
  • <name>: Replace this placeholder with the name of the repository from which you want to remove packages.

Category 2: repo commands

We use aptly repo <command> to work with local repositories. The repo category is focused on the management of Debian repositories, allowing users to create, modify, and query repositories. Here are some of the commands from repo category.

1. aptly repo create

This command creates an empty local repository. Here is how we can use it:

aptly repo create <name>
  • name: This is the name of the repository that the command creates.

We can use this command with its optional flags:

  • -comment="": This flag can be used to add any information about the repository.

  • -component="main": This sets the default component to main.

  • -distribution:"": This sets the default distribution.

2. aptly repo remove

It removes specified packages from a repository. Keep your repository clean by removing outdated or unnecessary packages using the following command:

aptly repo remove <name> <package-query> ...
  • <name>: Replace this placeholder with the name of the repository from which you want to remove packages.

  • <package-query>: This represents one or more queries specifying the packages you wish to remove. This can include package names, version specifications, or other selectors.

Category 3: snapshot commands

We use aptly snapshot <command> to work with snapshots. Snapshots are a key feature in Aptly, allowing us to capture the state of a repository at a specific point in time. This is particularly useful for creating stable versions of the packages.

Here are some of the commands from snapshot category.

1. aptly snapshot merge

This command merges several snapshots into one snapshot. It resolves packages with the same name-architecture pair such that it chooses the package from the latest snapshot. Here is how we can use this command:

aptly snapshot merge <destination> <source> [<source>...]
  • destination: This is the name of the merged snapshot.

  • <source> [<source>...]: This is the list of snapshots that we wish to merge.

This command can also be used with its optional flags:

  • -latest: This tells the command to use the latest versions of each package.

  • -no-remove: This tells the command not to remove duplicate arch or name packages.

2. aptly snapshot filter

This command filters the contents of a source snapshot and creates a new snapshot. Here is how we can use it:

aptly snapshot filter <source> <destination> <package-query> ...
  • source: The name of the snapshot from which we wish to create a snapshot.

  • destination: The name of the new snapshot that the command creates.

  • package-query: A list of packages that we wish to pull from source.

Conclusion

In summary, Aptly is an essential tool for anyone managing debian package repositories. Its robust command set allows for efficient repository creation, management, and publication. Whether we're managing small projects or large-scale deployments, mastering Aptly will significantly enhance our workflow.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


How can we serve a Debian package with the Apache web server?

We can serve a publish Debian packages using Aptly and server technology in the following way:

Steps to serve a debian package:

  1. Generate a public key
  2. Export the key
  3. Copy the key
  4. Build the package
  5. Create an Aptly repository
  6. Add the package
  7. Create a snapshot
  8. Publish the snapshot
  9. Copy published files to the Apache default serve
  10. Remove default Apache server file
  11. Start Apache server

Check out our detailed Answer on how these steps are implemented to serve a Debian package with the Apache web server.


How do I publish a snapshot?

Use aptly publish snapshot <name> to publish a snapshot.


How do I list all mirrors?

Use aptly mirror list to display all created remote repository mirrors.


Free Resources

Copyright ©2025 Educative, Inc. All rights reserved