Where are apt-get files stored?

There are multiple virtual machines running Ubuntu and they are all updated by the following command:

apt-get update
apt-get upgrade

But updating each VM separately takes a lot of time to download the required packages and also uses massive amount of bandwidth (which I'm running out of). Is it possible to transfer the updated files by apt-get directly into VMs?

I know the packages are stored in /var/cache/apt/archives but I need the apt-get database files (list of mirrors, indexes, available packages on mirrors, ...)


Update: There are many solutions

  1. apt-cacher-ng as mentioned in the answers.
  2. Docker images built for caching apt files (they run squid actually)
  3. Simply using squid

Also, as mentioned in the answers, see Best way to cache apt downloads on a LAN?


Solution 1:

The .deb-files you have allready downloaded are stored in /var/cache/apt/archives/.

Solution 2:

Not an explicit answer to your question, but have you considered setting up an apt proxy? I use apt-cacher-ng (apt-get install apt-cacher-ng). Prehaps set this up on the VM host, and tell the VMs (and the host) to use this as their proxy (as simple as adding a file (eg 02proxy) to /etc/apt/apt.conf.d/ containing

Acquire::http { Proxy "http://vm host ip:3142"; };

That way you can just do apt-get upgrade without having to manually copy file around. When one computer downloads the debs they will be stored on the proxy for the next computer that requests it. Can handle multiple releases and different architectures, etc

Solution 3:

/var/cache/apt/archives is where they should be stored.

Solution 4:

Quick instructions to create a local apt archive using a convenient debian tool called "apt-ftparchive"

Example, create /home/aptcache as local directory to store *.deb files to install in future without repeat download and wasting bandwidth:

# Create the directory

  mkdir /home/aptcache

# Copy debs already downloaded to your system:

  cp /var/cache/apt/archives/* /home/aptcache/

# Scan the local packages into local database

  cd /home/atpcache
  apt-ftparchive packages . > Packages
  apt-ftparchive release . > Release

# Add this line to /etc/apt/sources.list (I placed at top)

  deb [allow-insecure=yes] file:/home/aptcache ./

# Update apt

  apt-get update

Now you can install the package normally. If apt-get asks "Install these packages without verification?", answer "Y" to install. That's because this local repository is not signed.

You can also install all packages in your new local apt archive in one simple command

  apt-get install aptcache

source information: https://wiki.debian.org/DebianRepository/Setup#Quick_instructions_to_create_a_trivial_local_archive_with_apt-ftparchive

(acknowledgement to Debian team!)