Rationale

It is possible that you, as it happened to me, need to install more up-to-date packages in your machine. One way of doing this is to download the .deb files you need to install plus all their dependencies and execute a simple sudo dpkg -i *deb . In theory, that should be good enough. An alternative is to create a local APT repository, and hopefully I can give you a hand on how to do this.

The steps

1. Create the directory for your local APT repository

The location for such directory is up to you. Surfing the Web, the consensus seen to be under /usr/local . So if the directory’s name will be myrepo, then you can create the repository as follows:

sudo mkdir -p /usr/local/myrepo

Optional

You may change the owner and group of the directory to your own if you don’t wish to make use of sudo in order to populate the repository with packages. You can achieve that with the help of the following command:

sudo chown my_user:my_group /usr/local/myrepo

2. Create the script that will generate the repository’s metadata

You can name the scrip whatever you want. The recommended pattern to follow is update-<repository's name> . In our particular case and following the example above, it would be named update-myrepo .

#!/bin/bash # Source: https://askubuntu.com/a/772636 cd /usr/local/myrepo #change accordingly # Generate the Packages file dpkg-scanpackages . /dev/null > Packages gzip --keep --force -9 Packages # Generate the Release file cat conf/distributions > Release # The Date: field has the same format as the Debian package changelog entries, # that is, RFC 2822 with time zone +0000 echo -e "Date: `LANG=C date -Ru`" >> Release # Release must contain MD5 sums of all repository files (in a simple repo just the Packages and Packages.gz files) echo -e 'MD5Sum:' >> Release printf ' '$(md5sum Packages.gz | cut --delimiter=' ' --fields=1)' %16d Packages.gz' $(wc --bytes Packages.gz | cut --delimiter=' ' --fields=1) >> Release printf '

'$(md5sum Packages | cut --delimiter=' ' --fields=1)' %16d Packages' $(wc --bytes Packages | cut --delimiter=' ' --fields=1) >> Release # Release must contain SHA256 sums of all repository files (in a simple repo just the Packages and Packages.gz files) echo -e '

SHA256:' >> Release printf ' '$(sha256sum Packages.gz | cut --delimiter=' ' --fields=1)' %16d Packages.gz' $(wc --bytes Packages.gz | cut --delimiter=' ' --fields=1) >> Release printf '

'$(sha256sum Packages | cut --delimiter=' ' --fields=1)' %16d Packages' $(wc --bytes Packages | cut --delimiter=' ' --fields=1) >> Release # Clearsign the Release file (that is, sign it without encrypting it) gpg --clearsign --digest-algo SHA512 -o InRelease Release # Release.gpg only need for older apt versions # gpg -abs --digest-algo SHA512 --local-user $USER -o Release.gpg Release # Get apt to see the changes sudo apt-get update

This script is a modification of one shared in StackOverflow. You can navigate to the original one via this link: https://askubuntu.com/a/772636

You have to make the script executable. In order to do that, just execute:

chmod u+x update-myrepo

Once again, the location of the script is for you to decide. I recommend to store it under ~/.local/bin . It will be very convenient to have said directory in your path for you to have the possibility of running the script as any other command in your system.

3. Create a GNUPG key if you don’t have one

We need to sign the packages in our local APT repository in order for the system to trust their origin. This security mechanism is in place in order to avoid installing bogus packages, among other reasons.

This is already covered in the official documentation. You can follow the instructions in the section Generating a new keypair.

4. Tell the system about your key

In order for the system to make sure the packages in your local repository are safe to install, you need to add your key as a trusted one. For that, execute the following command:

gpg --export --armor XXXXXXXX | sudo apt-key add -

Where XXXXXXXX is your key’s ID.

You can get your key’s ID with the help of this command:

gpg --keyid-format short --list-keys | grep 'pub ' | awk -F '/' '{ print $2 }' | awk -F ' ' '{ print $1 }'

5. Tell GNUGP to use your key by default

Create the a ~/.gnupg/gpg.conf file with the following content:

default-key XXXXXXXX

Where XXXXXXXX is your key’s ID.

6. Populate your local APT repository

Move/copy the .deb files you are interested on being in your personal repository as follows:

mv/cp ~/Downloads/*.deb -t /usr/local/myrepo

7. Update your configured sources

Run the script with a simple update-myrepo and wait for the update to be finished.

8. Enjoy!

You are ready to upgrade/install your new packages.

I hope for me to have been of help and for you to have a lot of fun with your new personal APT repository.