Thursday, July 28, 2011

Offline Upgrade / Install Packages in Ubuntu

If you want to either offline update your package information or upgrade your packages, there is currently no application that supports either of those targets. But it is nevertheless possible, although at least technically a bit tricky. However, by simply following these instructions step-by-step, it is also possible for less experienced users to succeed.

This method, btw., is also particularly interesting if you need to upgrade multiple machines at a time. So, let's start over and squeeze the hell out of the command line!

For the following instructions, I picked up some of the essential commands from this earlier post:

What you need
  • At the online machine, it doesn't matter what OS, only Firefox with extension DownThemAll must be installed, link in the section below.
  • At the offline machine, the package "tree" must be installed, instructions in the section below.
  • A USB flash drive or another writable media.

Update Package Information

1. At the offline machine, create the list for files to download.

In this example, I save the file on the desktop, and name it "apt-lists", but you can also use any other location or name, in this case adapt the commands that follow.

sudo apt-get --print-uris update | grep -v Translation | cut -d "'" -f 2 -s > ~/Desktop/apt-lists

2. At the offline machine, check if the package "tree" is installed:

dpkg -l | grep tree

If you don't get it listed in the output, create a separate download list:

sudo apt-get --print-uris --yes install tree | grep http | cut -d "'" -f 2 -s > ~/Desktop/apt-install

3. Copy the created files to a USB drive or another media and transfer them to online machine. I recommend creating an own directory into which the files to download will be written in the next steps.

4. At the online machine, it doesn't matter what OS is installed, all you need is Firefox and the extension DownThemAll. If not already installed, install it from here:

Now open the created file "apt-lists" with Firefox either through the right-click menu when clicking on the file itself, or through "File > Open File..." from within Firefox.

Once the content of the file is displayed - it will show a lot of URLs -, right-click in the page and choose "DownThemAll!...". In the upcoming dialog, all files should already be selected for download. If not, tick "All Files" under "Filters". Next, choose the directory into which the files shall be downloaded, the directory you may have created therefore before.

Into the field "Renaming Mask", enter this:


When ready, click on "Start" to begin the download process.

5. If you don't have the package "tree" installed at the offline machine, and therefore created the file "apt-install" in the earlier step, handle this file similar to the above step, but this time enter this into the field "Renaming Mask" of DownThemAll (the default):


6. Transfer the downloaded files with a USB drive or another media to the offline machine.

7. At the offline machine, enter the directory that contains all the downloaded files in the Terminal.

For the next step, you need the package "tree" installed. If you downloaded it in the earlier step, run this command to install it:

sudo dpkg -i *.deb

Now we need to convert the names of the downloaded files, that are currently contained in a subdirectory structure, into the proper formats and cumulate them in a single directory. Therefore, we first create a new directory with a name like "lists-update", and then carry on with the actual converting:

mkdir lists-update
for i in `tree -fi * | grep [PR]`; do cp $i lists-update/${i//\//_}; done
cd lists-update
bunzip2 *.bz2
for i in *.asc; do mv $i ${i%.asc}; done

In this final step, we copy the updated list files into the target system, and set the correct permissions:

sudo cp * /var/lib/apt/lists
sudo chmod 644 /var/lib/apt/lists/*
sudo chmod 640 /var/lib/apt/lists/lock

8. If you need to update multiple machines with this method, you obviously only need to copy the produced files contained in the directory "lists-update" to the target system by running the very last command.

Upgrade Packages

1. Now, after importing the updated lists by the steps above, create another download list for the packages to upgrade with this command:

sudo apt-get --print-uris --yes dist-upgrade | grep http | cut -d "'" -f 2 -s > ~/Desktop/apt-upgrade

2. Follow the steps 3 - 6 of the above section, "Update Package Information", with the field "Renaming Mask" of DownThemAll! set to:


3. Enter the directory that contains the downloaded deb-packages in the Terminal, and run this command to install them:

sudo dpkg -i *.deb

4. If you need to upgrade multiple machines with this method, only repeat the very last step for the other target systems.

Install Packages

If you want to install additional packages, just create another download list for the packages to install with a command like below, where "PACKAGENAME" is obviously the name of the package to install. You can also state multiple packages here, as usual with 'apt-get'.

sudo apt-get --print-uris --yes install PACKAGENAME | grep http | cut -d "'" -f 2 -s > ~/Desktop/apt-upgrade

Then simply follow the steps 2 - 4 of the above section, "Upgrade Packages".

Another method to offline install packages, by using Synaptic Package Manager, is described here:

Related Posts:

Installation , Package Manager