35

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?

1
  • 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. Jun 17, 2021 at 3:03

5 Answers 5

50

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

3
  • 1
    Oooh, beat me by 26 seconds :) Mar 27, 2012 at 23:33
  • 12
    That's why I have twice as much reputation ;-P
    – turbo
    Mar 27, 2012 at 23:34
  • 1
    Oooooohhhh, burrrrn. :) Mar 28, 2012 at 1:54
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

2
  • 1
    You can even install squid-deb-proxy on the proxy server and squid-deb-proxy-client on others; this will make the proxy detection work transparently (using Avahi), no client-side configuration required. As a bonus, if the proxy server is not found on the local network, the client will connect to the repositories directly (making this suitable even for laptops). May 23, 2013 at 13:55
  • I second the use of Squid-deb-proxy over Apt-cacher. Relevant Q: Best way to cache apt downloads on a LAN?
    – gertvdijk
    May 23, 2013 at 14:13
17

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

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

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.

1
  • Please note this should be .deb not .dep
    – Malfist
    Sep 5, 2014 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.