37

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?

hkoosha
  • 668
  • You can use apt-config dump to print the config to the screen. The entry you want is Dir::Cache. The values build up on their parent entries. So you need to look at Dir to get context for the value of Dir::Cache. On my system its /var/cache/apt/. It's also possible to query individual entries. I didnt look into how to do that though. – Paul Rooney Jun 17 '21 at 03:03

5 Answers5

50

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

turbo
  • 4,622
17

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

Naftuli Kay
  • 4,226
17

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

1

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!)

Lorenz Keel
  • 8,905
0

You can backup all the *.deb, then copy it into vmware, you can copy it in /root/sw_backup. The folder can not be /var/cache/apt/archives/.

Then you can locally install it with synaptic. $synaptic "file" menu to find local install. but it also needs network, just need to update a little package.

nsane
  • 476