0

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.

1 Answers1

1

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

Jeremy Davis
  • 134
  • 11
  • I don't want to have software working on different distros that are installed side by side. My aim is to not have to manually reinstall each software on a given distro if for some reason I end up having to reinstall/wipe it. – Three Diag Jun 26 '15 at 11:03
  • Cool, is there a way to systematically compile this text file each time I install a new program? Better, to retrieve the current installed apps in a file properly formatted for the purpose? – Three Diag Jun 26 '15 at 11:07
  • Ah ok sorry I misunderstood... TBH now I think I probably should have realized this being Ubuntu specific and all... Just the "installing different distros" threw me! – Jeremy Davis Jun 26 '15 at 11:08
  • Yes there is. I don't recall the command off the top of my head but you can use dpkg to list all installed software (I'll post back in a sec). You'd probably want to run it on a clean install and adjust your list first though or otherwise it will set all installed software as manually installed (so even if you remove a program, the stuff that it depends on would all still stay... – Jeremy Davis Jun 26 '15 at 11:11
  • I edited to include info form that thread. I will leave unanswered for a while, see if somebody can come up with a way by moving folders in partition (which I would prefer). – Three Diag Jun 26 '15 at 11:47
  • Looks like your edit got rejected. It doesn't matter as I edited my answer a bit to include a more complete answer and another option (which will probably save a fair bit of time downloading packages if you have a ton of software installed). – Jeremy Davis Jun 26 '15 at 12:16
  • When you say you'd prefer to move folderss; Do you mean move the installation files (like you might move a dir in Windows Program Files)? If so that won't happen. Linux filesystem doesn't work like that. It isn't set up to separate different programs; but what the files do and who can access them. This has some great answers that explain it really well: http://askubuntu.com/questions/138547/how-to-understand-the-ubuntu-file-system-layout

    Copying out the debs (sort of like Win installer exes) like I said above is maybe the closest you will get to what I think you are asking for.

    – Jeremy Davis Jun 26 '15 at 12:16
  • I was thinking of something along the line of: move /usr/local/bin to a different partition; install x in /usr/local/bin; if something goes wrong reinstall, delete newly created /usr/local/bin and mount the one on the different partition in its place. I have no idea if this is possible in any way. – Three Diag Jun 26 '15 at 12:23
  • It's totally possible but I'm not clear on what advantage it would have... Many apps will install files to all over the place so just restoring their binary executable will not restore the data and config that they need to work properly. Also how would you differentiate between what you wanted and what you didn't (because of changes that you made)? – Jeremy Davis Jun 26 '15 at 12:32
  • Yeah, it is probably a silly idea. Thanks for the pro-answer! – Three Diag Jun 26 '15 at 12:52