Saving a apt-get file for future installations, how do I do it? [duplicate]

I have a terribly limited download allowance and have multiple computers. So, my questions folks is. Would I be able to save what has been installed thru apt-get and any other terminal installations I attempt?


Solution 1:

When you install a package using apt-get corresponding deb files are downloaded in your /var/cache/apt/archives. Unless user deletes them all those files should be there. You can copy and preserve them for future use.

All you need is to set a local repository[Source]. Then you could install all those packages as usual using apt-get from it. Make a folder localrepo say at you home directory and put all the .deb files from /var/cache/apt/archives in it.

$ mkdir ~/localrepo
$ cp /var/cache/apt/archives/*.deb .

Next you need to create an index file for your repository. For that you need to install dpkg-dev (on your source machine only).

$ sudo apt-get install dpkg-dev

To create index file,

$ cd ~/localrepo
$ dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

It will create an index file named Packages.gz in ~/localrepo. In future you just need to copy the whole ~/localrepo to other machines where you want to install. If you modify the deb files in ~/localrepo you also need to update the index file.

Now you need to show apt-get the repo editing your source list in all machines where you want to install packages from your local repository. First backup your original source.list

$ sudo cp /etc/apt/source.list /etc/apt/source.list.original
$ sudo gedit /etc/apt/source.list

Write the following line in it and save,

deb file:/home/<user_name>/localrepo ./

Replace <user_name> with your exact user name. Now you are ready to install any package that exists in your source machine.

sudo apt-get update
sudo apt-get install <package_name>

You may need to give additional affirmation. As the repository is not trusted. For home use purpose it should be just enough as creation of a trusted repo requires quite a lot extra efforts. But your software center will not probably work with untrusted repo. But the advantage is that it will take care of all the dependencies for a package by itself.

If your /var/cache/apt/archives in your source machine do not contain any package. You can download deb files for all your existing packages using the following command in terminal,[Source]

dpkg -l | grep "^ii"| awk ' {print $2} ' | xargs sudo apt-get -y install --reinstall --download-only

Solution 2:

Assuming you have a server/spare box, you can setup Apt-Cacher, which will store all of the .deb files for you.