Install Ubuntu packages and dependencies offline

I was caught in a catch-22 when the NIC broke in one of my computers. I bought a USB-ethernet adapter, but I needed to install the driver from the internet using make and gcc which I didn’t have.

Using another computer, I tried “Generate package download script” to install make and gcc, but the problem was that not all dependencies were being downloaded because many of them were already installed in the computer with internet (gcc’s and make’s libraries).

The solution I found was to temporarily replace /var/lib/dpkg in the computer with internet for the /var/lib/dpkg from the computer with no internet. This way, Synaptic was tricked into thinking the dependencies didn’t exist in that computer and downloaded them all.

The entire solution:

1. Trick Synaptic into thinking the online computer is the offline computer:

# in the online computer
mv /var/lib/dpkg/ /var/lib/dpkg.online_computer

# copy /var/lib/dpkg from the offline computer to a pendrive and mount it in the online computer
cp - /media/pendrive/var/lib/dpkg /var/lib/dpkg

2. Start Synaptic, select packages, click “Apply” and check “Download package files only”. Apply.

3. Copy the contents of /var/cache/apt/archives/ to a pendrive.

4. Copy the files in the pendrive to the offline computer’s /var/cache/apt/archives/

5. Use dpkg -i to install the packages wanted. You will still have to install dependency by dependency, but at least you have all of them available.

6. Revert Synaptic/apt to the online computer:

rm -rf /var/lib/dpkg
mv /var/lib/ /var/lib/dpkg

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s