Generate package download list with apt-get for offline install

No internet, it’s costly or too slow ? Don’t worry, download the debian packages (deb files) somewhere elsewhere, I mean where internet is fast and affordable.

In this tutorial we are going to learn how to generate the list of package URLs of an application with all dependencies.

This could be done easily with some tools like AptOnCD etc. , which is big and requires further downloading. Personally I too don’t like AptOnCD for its huge size, lots of dependency and ugly Gtk+ based user interface. So how It could be done ? Simply with a little knowledge of apt and basic shell scripting.


1. Initialize the repository

The first step is you have to enable the repository list of update it. This step is mandatory for a fresh Debian install. In Ubuntu, you may not have to do this, as Ubuntu configures the repository URLs automatically during installation.

For Debian put the repository URL of your choice in the /etc/apt/sources.list and configure them properly. For Debian testing, currently stretch just add the line bellow in the /etc/apt/sources.list file with text editor of your choice.

 deb stretch main contrib non-free 

For beginners, you may have a look at this article for a detailed apt and sources.list tutorial.

Now update the repository database with apt-get update,

 sudo apt-get update 

You could further reduce the amount of internet data needed to update the repository, have a look at make apt-get update more bandwidth efficient.


2. Generate the apt-get package URL list

Lets generate the package URL list, the –print-uris command line switch of apt-get is used to print the URLs of relevant deb files of an application with all of its dependency. Just run apt-get -y install –print-uris package_name this command filter and clear the garbage. Look at the example bellow,

 apt-get -y install --print-uris audacity| grep 'http' | tr -d ' | awk '{print$1}' > apt_url_list_audacity

This command will generate the clean URL list and save it in a file names apt_url_list_audacity. You may want to use the –no-install-recommends command line switch of apt, this will further reduce the number of packages to download. Now download the files with wget -i apt_url_list_my_app , or on windows, wget for windows, or with any download manager like IDM.

 wget -i apt_url_list_audacity 


3.  Installed all the Downloaded files

This is the final step, install the downloaded deb files with the dpkg -i command, this step is very simple, just go to that folder and install them.

cd ~/Downloads/deb_files   # example

sudo dpkg -i *.deb

This command will install your application along with all dependency, without any further interaction. By chance if this process returns an error fix it with

 sudo apt-get install -f 


4. wrapping up everything inside a small shell script

You may want to save this shell script bellow to avoid the commandline mess, save it with any name make it executable with chmod +x and use it like bellow.

 ./apt_url_gen my_application  # example
 ./apt_url_gen audacity 

The last command will generate a file named apt_url_list_audacity containg all the necessary URLs.


sudo apt-get -y --print-uris install "$@" |
grep 'http' | tr -d ' | awk '{print$1}' > /tmp/apt_url_list
cp /tmp/apt_url_list ~/apt_url_list_"$@"
rm -rf /tmp/apt_url_list


Thats it, I hope this simple tutorial will help you. Alternatively you could also use your Debian/Ubuntu installer ISO file as offline repository. If you need any further assistance or have a question, just leave a comment. Also don’t forget to share this tutorial with your friends.

Leave a Reply

Your email address will not be published. Required fields are marked *