Introducing ‘Aptly’, A Debian Repository Management Tool

About Aptly

Aptly is a free Debian repository management tool that allows you to mirror remote repositories, manage local package repositories, take snapshots, pull new versions of packages along with dependencies, publish as Debian repository. It is available both as CLI tool and HTTP REST service.


Using Aptly, you can:

  • Take and update mirrors of any Debian/Ubuntu remote repository ;
  • Take Snapshot of the mirror ;
  • Merge two or more snapshots into one ;
  • Publish Snapshots as repository ;
  • Search for any required packages including the dependencies ;
  • Manage your own local repositories ;
  • Merge your local repositories into official repositories ;
  • Publish your repositories directly to Amazon S3 as public or private repositories ;
  • Upload packages using HTTP, manage your repositories, snapshots, published repositories etc ;
  • And more yet to come.

For more details, have a look here.

Why Aptly is important?

The answer is to save bandwidth. Nowadays, Computers are so imperative in every organization. Each organization has hundreds of systems running with Linux operating systems. You may need to install applications, software updates, security fixes in all computers everyday. You may wish to add some third party repositories to get softwares which are not available in the official repositories. Also, sometimes, you may want to package your own software. In such cases, setting up and maintaining a local repository is mandatory. Not only it saves lot of bandwidth, also it will help us to publish our own or modified versions of official packages in the repositories. This is where Aptly comes in handy.

Install Aptly in Debian/Ubuntu

Aptly is available in the default repositories of Debian 8 and Ubuntu 15.04. So, you can install it using command:

sudo apt-get install aptly

For older versions, you can install by adding aptly repository.

First, import aptly key using command:

apt-key adv --keyserver --recv-keys E083A3782A194991

Edit /etc/apt/sources.list file:

sudo vi /etc/apt/sources.list

Add the following line:

deb squeeze main

Then update your source list and install it as shown below.

sudo apt-get update
sudo apt-get install aptly


If you have Go environment set up (go 1.3+ required), you can build aptly from source by cloning it and building with gom:

$ go get -u
$ mkdir -p $GOPATH/src/
$ git clone $GOPATH/src/
$ cd $GOPATH/src/
$ gom -production install
$ gom build -o $GOPATH/bin/aptly
$ aptly

Aptly basic usage

The list of available commands in aptly is:

  • mirror

    : manage, update mirrors of remote repositories

  • repo

    : manage local package repositories, add, remove, move, copy packages

  • snapshot

    : create, merge, manage snapshots

  • publish

    : publish snapshot or local repository

  • serve

    : quickly export published repositories via HTTP

  • task

    : manage aptly tasks

  • db

    : cleanup database and package pool, recover database after failure

  • api

    : REST API service

  • config

    : configuration management

  • task

    : multi-command tasks

Creating local repositories

To create a new repository, just enter:

aptly -distribution="vivid" -architectures=amd64 repo create skrepo

Here, skrepo is my local repository name.

Sample output:

Config file not found, creating default config at /home/sk/.aptly.conf

Local repo [skrepo] successfully added.
You can run 'aptly repo add skrepo ...' to add packages to repository.

Viewing available repositories

To see list of available repositories, run:

aptly repo list

Sample output:

List of local repos:
 * [skrepo] (packages: 0)

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

Adding packages to the repository

As you see in the above output, there is no packages in “skrepo”.

To add a package in repository, go to the directory where you have kept .deb files and run:

aptly repo add skrepo *deb

Sample output:

Loading packages...
[+] libmysqlclient18_5.6.24-0ubuntu2_amd64 added
[+] mysql-client-5.6_5.6.24-0ubuntu2_amd64 added
[+] mysql-client-core-5.6_5.6.24-0ubuntu2_amd64 added
[+] mysql-client_5.6.24-0ubuntu2_all added
[+] mysql-common_5.6.24-0ubuntu2_all added
[+] mysql-server-5.6_5.6.24-0ubuntu2_amd64 added
[+] mysql-server-core-5.6_5.6.24-0ubuntu2_amd64 added
[+] mysql-server_5.6.24-0ubuntu2_all added

Viewing the details of a repository

To view the complete details of a repository, run:

aptly repo show skrepo

Sample output:

Name: skrepo
Default Distribution: vivid
Default Component: main
Number of packages: 8

Creating snapshot of a repository

To create a snapshot of a repository (Ex.test-skrepo), run:

aptly snapshot create test-skrepo from repo skrepo

Here, test-skrepo is the snapshot of skrepo.

Sample output:

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

Viewing Snapshot list

To view list of available snapshots, run:

aptly snapshot list

Sample output:

List of snapshots:
 * [test-skrepo]: Snapshot from local repo [skrepo]

To get more information about snapshot, run `aptly snapshot show <name>`.

Publishing Snapshots

To publish a Snapshot, run:

aptly -architectures="amd64" -skip-signing=true publish snapshot -architectures="amd64" test-skrepo

Sample output:

Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...

Snapshot test-skrepo has been successfully published.
Please setup your webserver to serve directory '/home/sk/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
 deb http://your-server/ vivid main
Don't forget to add your GPG key to apt with apt-key.

You can also use `aptly serve` to publish your repositories over HTTP quickly.

Publish repositories over HTTP

To publish your snapshots over HTTP, simply run:

aptly serve

Sample output:

Serving published repositories, recommended apt sources list:

# ./vivid [amd64] publishes {main: [test-skrepo]: Snapshot from local repo [skrepo]}
deb http://server:8080/ vivid main

Starting web server at: :8080 (press Ctrl+C to quit)...

Configuring client systems to use local repository

Configure your /etc/apt/sources.list file by adding your local repository server in your client systems.

Edit /etct/apt/sources.list file:

vi /etc/apt/sources.list

Add the following line:

deb http://ip-address:8080/ vivid main

That’s it. Comment out all remaining lines and update your repository list using command:

sudo apt-get update

Then, you can install any packages of your choice from your local repository.

sudo apt-get install <package-name>

Removing Snapshots

To remove a snapshot, run:

aptly snapshot drop test-skrepo

If snapshot is published, it can’t be dropped (first remove publishing for snapshot). If snapshot is used as source for other snapshots (using merge or pull), aptly would refuse to drop such snapshot, use flag


to override this check.

Removing repositories

To remove a repository, run:

aptly snapshot drop skrepo

For more usage details, refer the official documentation.


I didn’t test ‘aptly’ completely, Still I am testing and exploring it. I will make an another interesting article about Aptly soon. As far as I know during the testing process, Aptly worked just fine as it’s advertised. I strongly recommend you to try aptly if you are planning to setup a local repository.

Good luck!

Source and reference: