Sunday, June 13, 2010

HOWTO: Installing Ubuntu Packages Offline

Something that is difficult to do in Ubuntu (and Linux in general) is installing packages on a system without an active internet connection. This is a brief HOWTO for easily installing packages on an offline Ubuntu system. In order to do this you will need another system (preferably something with Linux) that has an active internet connection as well as a flash drive.

Step 1 - Manually performing an apt-get update
This step is optional if your system was online at some point, however if the system never had an internet connection (or never had apt-get update run) you will need to manually update the packages lists.

To do this goto your system that has an active internet connection, open a terminal and run the following commands in order:

wget http://archive.ubuntu.com/ubuntu/dists/lucid/main/binary-i386/Release
mv Release archive.ubuntu.com_ubuntu_dists_lucid_Release

wget http://archive.ubuntu.com/ubuntu/dists/lucid/main/binary-i386/Packages.bz2
bunzip2 Packages.bz2
mv Packages archive.ubuntu.com_ubuntu_dists_lucid_main_binary-i386_Packages

wget http://archive.ubuntu.com/ubuntu/dists/lucid/restricted/binary-i386/Packages.bz2
bunzip2 Packages.bz2
mv Packages archive.ubuntu.com_ubuntu_dists_lucid_restricted_binary-i386_Packages

wget http://archive.ubuntu.com/ubuntu/dists/lucid/universe/binary-i386/Packages.bz2
bunzip2 Packages.bz2
mv Packages archive.ubuntu.com_ubuntu_dists_lucid_universe_binary-i386_Packages

wget http://archive.ubuntu.com/ubuntu/dists/lucid/multiverse/binary-i386/Packages.bz2
bunzip2 Packages.bz2
mv Packages archive.ubuntu.com_ubuntu_dists_lucid_multiverse_binary-i386_Packages


This should generate five files for you, copy them to your flash drive. Take the flash drive over to your Ubuntu system that is offline and copy them to

/var/lib/apt/lists

Note, you will need super user privileges to do this. To open a super user file manager on Ubuntu run

sudo nautilus

Step 2 - Generating Package List
On your offline system we now need to generate the list of packages we want to install. For this example I am going to use the wine1.2 and filezilla packages, however it will work for any package(s). On the offline system run the following in terminal


Due to issues with the terminal code posting on blogger the two lines needed can be found here.

Note you can list as many (or as little) packages as you want to install. Take the apt_list_new file we just generated and copy it to your flash drive.

Step 3 - Download the Packages
Plug the flash drive with the apt_list_new file into your computer that has an internet connection. Copy the file to the desktop of the computer and then run the following in terminal


cd ~/Desktop && wget -i apt_list_new

The above command will download all the packages you need to your desktop, copy them to your flash drive.

Step 4 - Installing the Packages
Attach the flash drive you copied all the packages onto to your offline system. Next, copy all the files ending in .deb to /var/cache/apt/archives as root. Finally run


sudo apt-get install wine1.2 filezilla

It will tell you "Need to download 0 of XMB" just enter "y", press enter, and poof! Your software will be installing.

Have any issues or suggestions on an easier method of installing software on an offline Ubuntu system please drop a comment below. Also, if you only have a windows system with an internet connection available to you a LiveCD is a good option or you can always install wget on Windows.

Cheers,
~Jeff Hoogland

15 comments:

  1. Try aptoncd to create an apt ISO from a machine that already has all the apps downloaded. also try apt-cacher-ng. allows you to create an apt proxy on a pc which other machines on the lan can download from. very usefull, can even cache packages from other versions of ubuntu.

    ReplyDelete
  2. There is a much simpler way, the excellent Keryx project. As far as I know, it automates pretty much the same process you outline above, but with a wxPython GUI that works on Windows or on Linux; this provides a synaptic-like interface to update, install, and upgrade packages. Basically you put Keryx in a folder on a USB stick, it reads your sources list and packages state, you take it to any computer with internet, run it, and tell it what you want. Magic! Oh, and it works for any deb-based system.

    ReplyDelete
  3. Good how-to. I will try it on my ubuntu boxes.

    The funny thing is that just moments ago I was reading the apt-on-cd docs to figure out how I can ensure that I download a package only once.

    Is there anything similar for "apt-get upgrade"? I.e. let's say I have two Ubuntu 10.04 32-bit systems, then I upgrade just one, but, I can "magically" copy and install all the upgraded packages from one system to the other without having to connect the other system to the net.

    ReplyDelete
  4. You can pull the package list for an apt-get upgrade by running:

    apt-get -qq --print-uris upgrade > apt_list
    awk '{gsub("\x27", "", $0); print $1}' < apt_list > apt_list_new

    ReplyDelete
  5. how about 64 bit. i know the basic commands remain. the slight changes need to posted especially in the repos.

    ReplyDelete
  6. For 64bit just replace "binary-i386" with "binary-amd64" in the manual apt-get update stage.

    ReplyDelete
  7. If the computer with the available internet connection is a windows-system, how can I generate manually the needed packages and get them to my offline-ubuntu system?

    ReplyDelete
  8. You can mark the packages and generate a "Download script" in synaptic that will contain the urls of all the debs you need to install a given program.

    ReplyDelete
  9. Thanks so much, Jeff! I found one thing, though, when trying to do this with maverick. When you move the Release and unzipped Package files to a new name, you have to prepend "us." to "archive.ubuntu.com", and I guess for another country it would have to be modified. I guessed this since some of the already existent files in /var/lib/apt/lists were listed as "us.archive.ubuntu.com...."
    I hope that helps someone. Thanks again, Jeff!

    ReplyDelete
  10. Jeff, I really really appreciate your instructions. I've used it countless times. It's the only reliable instructions I've found online for this task of offline Ubuntu. My one question is how do you install Medibuntu files using the same system that you discussed? I googled hopelessly but couldn't find it. If you don't have the time, don't worry about it! Thanks in either case!

    ReplyDelete
  11. Thanks for sharing,yours is the best explanation I've found.

    ReplyDelete
  12. You can get Ubuntu Apps Offline installer (but not all) in www.delavega.blogspot.com

    Just download and enjoy!

    ReplyDelete
  13. I'm not versatile with Linux but I was thinking, If I have 2 identical and newly installed Ubuntu servers (1 on a server and the other on a virtual machine), why not just use apt-get to only download (-d) the needed packages (On the VM) and then copy the packages from the VM to the offline server and run the "apt-get install" command. Would that work ?

    ReplyDelete