Ubuntu: Install software so that cannot be wiped by reinstalling


Is there a way to install programs under Ubuntu in such a way that the standard reinstall from live usb will not wipe them out? (e.g. by installing them in a different partition or keeping folders such as /bin/local, and similar, on a different partition?)

If not, what's the best way to compile a list of all previous software (assuming they can all by added via apt-get, at most by adding a repo) and make a script that can reinstall them? (some software, e.g. stuff that requires license cannot be dealt in this way, but a lot of other are e.g. texlive, geany, etc..)

Motivation: being a pretty newbie to linux and liking experimenting around (I want to try other distros, change partition and such) I often end up having to reinstall as it is at times the easiest way to fix broken systems. But being this my main computer, I would like to not have to reinstall/redo all config everytime this happen.


There are ways that you could do this for an OS, but I'm not sure how transferable from distro to distro it would be. You could do it (using apt & dpkg) for Debian based distros and it would probably work fairly consistently. But there are plenty of distros that don't use apt/dpkg and so it almost certainly wouldn't work for those. E.g. Fedora uses yum and I don't recall what Arch uses.

So probably the best/most transferable way would be to keep a text file of the apps you want... Even then though it won't be foolproof as different distros often even have slightly different naming conventions.

As per your edited answer (keeping it to Ubuntu) a quick and dirty way to list all packages installed would be

apt-cache pkgnames > apps.txt  

Note though that that will list all installed packages; not just the ones that you explicitly installed. So if you switch between different Ubuntu versions which have different desktop environments it will be a bit of an issue... It also will list dependencies (that weren't manually installed - so they won't be auto flagged as unneeded if you uninstall the manually installed software).

To minimize the impact of that (although not eliminate it) you could rerun the command on a clean install of the same version (say before you switch to Lubuntu for example). Then clean the first list using the results of the second...

apt-cache pkgnames > clean-install-apps.txt  grep -v -x -f clean-install-apps.txt apps.txt > new-apps.txt  

You can then install with this:

sudo apt-get update && sudo apt-get install < new-apps.txt  

Keep in mind though that this will manually install the dependencies as well. Also it won't include all the config info (if you've configured those apps the way that you want them... Generally this is kept in your home dir in dot directories (e.g. directories like ".appname". So in theory you could mount your home dir in a different directory and just remount it each time. Even then though it may not work if you are using different distros or version as the software versions may not be the same (shouldn't be an issue if you are using the same version of Ubunut though; e.g. 15.04)...

One other thought that I've had for a quick and dirty way to do this and probably make the installation quicker (and reduce your download bandwidth of that is a concern) would be to copy all the deb packages in /var/cache/apt/archives to a USB (or a separate partition, etc). Then you can install all the debs with dpkg. Assuming that your USB is mounted on /media/USB that would look something like this, on your current system:

mkdir /media/USB/debs-to-install  cp /var/cache/apt/archives/*.deb /media/USB/debs-to-install  

Then after reinstall:

dpkg -i --force-depends /<USB-dir>/*.deb  apt-get install -f  

Explanation: dpkg -i installs --force-depends forces install even if dependencies aren't satisfied (generally not recommended but in this case it's ok because it's almost guaranteed that all the dependencies are there in that directory; just that they aren't being installed in the right order). apt-get install -f should solve any dependency issues (if there are any).

Note that this second option will also make dependencies marked as manually installed too...

There are also other options as noted as answers to this question: How to list all installed packages

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »