Gentoo Wiki


This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

How do you maintain a Gentoo box that's not on the network? Here are a few tips.


Updating portage

You can update portage using another computer that has an internet connection. Most Gentoo mirrors have a directory with recent portage snapshots, so you can download the latest snapshot to your USB-key or other removable media and take that to your non-networked Gentoo box.

You can then delete your old portage directory and untar the new snapshot in its place. To complete the process you emerge the metadata (which is the last step in a normal emerge sync).

Code: Replacing portage with new snapshot
  cd /usr
  rm -rf portage && tar xjvf /mnt/usbkey/portage-latest.tar.bz2 && emerge --metadata
Warning: The following method, while appearing cleaner, will still cause a sync of your local portage tree despite the '-F' option

A much cleaner approach uses the emerge-webrsync command:

Code: Using emerge-webrsync to update portage on a networkless PC
  // On computer with internet connection
  emerge-webrsync -F  //only download, don't sync
  mv /var/tmp/emerge-webrsync/XXXXXXXX.tar.bz2 /mnt/usb //where XXXXXXXX.tar.bz2 is the snapshot file downloaded, and /mnt/usb is a usb key

  // On networkless computer
  mkdir /var/tmp/emerge-webrsync
  mv /mnt/usb/XXXXXXXXX.tar.bz2 /var/tmp/emerge-webrsync

If the source machine (the one connected to the Internet) is not running Gentoo, manually download the snapshot file and its md5 checksum from your favorite Gentoo mirror (as described in chapter 5 of the Gentoo handbook) and copy both files to /var/tmp/emerge-webrsync/ on the target machine before running emerge-webrsync.

Emerging new programs or updates

When you have updated portage you may want to emerge updates or new programs. Without a network connection though, you cannot download the needed distfiles. So you need to find out what files you need to download and transfer these again from another computer that has an internet connection. After downloading the necessary files, you can place them in your distfiles directory, after which you can emerge them normally.


You can pass the fetchonly and pretend flags to emerge to generate a list of files to download.

Code: Get list of files required for emerge and pipe the URL's to a file
emerge -pf world 2> ~/emerge_pf_world

You will notice there are multiple URL's for some of the files, seperated by a space character. They can be used as mirrors in case the first site listed is not reachable.

Code: View contents of emerge_pf_world
# cat ~/emerge_pf_world

Using wget to fetch distfiles

While generating a list of files to download is well and good, a large upgrade can require hundreds or thousands of files. You will almost certainly want to fetch your files automatically. This can be easily accomplished with wget.

Code: Using sed and wget to fetch files automatically
# Assuming a subdirectory named 'distfiles' on your removable media:
sed -r '/^(ht|f)tp:\/\//{s/ +/\n/g;p};d' emerge_pf_world | xargs wget -nc -nd -P distfiles

sed formats the URLs the way wget expects them. The -nc argument to wget assures that each file is only downloaded once (remember, there are multiple mirrors of files in the list). The -nd argument forces wget not to create subdirectories, and -P argument puts the downloads in the specified directory.

Note: for wget and sed on Windows, look at cygwin, a BASH-like shell that runs under Windows. It can even be run from a USB flash drive.


For the following example, assume your removeable media is mounted under /mnt/usb and that a gentoo/distfiles subdirectory exists on that media.

Code: Complete sequence of commands for networkless update
# [online] Fetch portage-latest.tar.bz2 from one of the mirrors
# using your favorite web browser.  Or, alternatively, using wget:
wget -nd

# [offline] Rename (or remove) /usr/portage.
# [offline] Untar portage-latest.tar.bz2 into /usr/portage
# [offline] Update portage metadata.
# [offline] Update portage.  You might be able to skip this.
mv /usr/portage /usr/old-portage
tar jxvf /mnt/usb/gentoo/portage-latest.tar.bz2 -C /usr
emerge --metadata
emerge --pretend --fetchonly --update portage > /mnt/usb/gentoo/portage.emerge

# [online ] Fetch updated portage files.
sed -r '/^(ht|f)tp:\/\//{s/ +/\n/g;p};d' portage.emerge | xargs wget -nc -nd -P distfiles

# [offline] Copy those files into /usr/portage/distfiles.
# [offline] Emerge latest portage.
# [offline] Update world.
cp -uv /mnt/usb/gentoo/distfiles/* /usr/portage/distfiles
emerge --ask --update portage
emerge  --pretend --fetchonly --update --deep world > /mnt/usb/gentoo/world.emerge

# [online ] Fetch world update files.
sed -r '/^(ht|f)tp:\/\//{s/ +/\n/g;p};d' world.emerge | xargs wget -nc -nd -P distfiles

# [offline] Copy those files into /usr/portage/distfiles.
# [offline] Emerge world.
cp -uv /mnt/usb/gentoo/distfiles/* /usr/portage/distfiles
emerge --ask --update --deep world
Retrieved from ""

Last modified: Fri, 05 Sep 2008 23:33:00 +0000 Hits: 12,240