Howto: Fresh Ubuntu Install Without Losing Your Current Settings

Published on November 12, 2008 in General by Rami Taibah

Warning: There are  two commands mentioned in this how to, both that require double dashes – - but for some reason WordPress is not rendering that correctly. After each dpkg hit space and hit the dash button twice. Sorry for the the inconvenience.

A clean install or an upgrade? That’s a question that keeps tossed around every new Ubuntu release. Common wisdom would suggest that a clean install would probably be better, however the inconvenience of losing current installed apps and configuration makes most of us shy away from this path. But what if I told you that you could have the good of both worlds? A fresh install and keeping your apps and configuration intact?

Configuration

Keeping your configuration intact is pretty straight forward and obvious. Just backup your /home folder onto an external drive or whatever. Make sure you also grab the hidden files, don’t do my mistake!

Applications

Now for the current applications. Basically we just need to make a full list of the installed apps.

sudo dpkg --get-selections > /home/user/package.selections

Of course don’t forget to backup package.selections on the external hard-drive. Also you should backup your /etc/apt/sources.list file since you probably have some extra sources listed over there. Now you can go about your business and do a fresh install.

Restore

Once your done with the fresh install, copy the file package.selections into your home. Then copy your sources.list file into /etc/apt/ and update it to match your current distro (e.g Gutsy –> Intrepid) you can use CTRL + H in gedit for that. Then do a “sudo apt-get update” ,and finally invoke:

sudo dpkg --set-selections /home/package.selections && apt-get dselect-upgrade

apt-get will now start downloading all your apps, this will take some time depending on the number of apps you have installed.

Once that’s done, just copy your backup-ed /home over the current /home (again don’t forget hidden folders).

Log out and log back in to your shiny new fresh install!

Edit: As the commentators below also mentioned, it would also be wise to have your /home in a seperate partition (thanks Boo Radley), back  up /etc (thanks Bartek), and use the tar command to back up home (it will preserve your structure and permissions)

About Rami Taibah

Rami Taibah the founder of The Linuxologist and a self proclaimed geek and Linux aficionado. This fall, he will be pursuing an MIMS degree at UC Berkeley, California. You can follow him on Twitter @rtaibah.

«

»

  • trex9016
    Be aware that you have to be careful restoring /home specially all those gnome hidden directories
  • One suggestion from the ubuntu wiki I originally found the advice
    https://help.ubuntu.com/community/FeistyUpgradesFreshInstall
    dpkg --get-selections | grep -v deinstall > filename
    simply removes the 'deinstall' entries though it's unclear how important that is as no-one here looks as though they have had difficulty
    it looks as though "aptitude update" "sudo dpkg --set-selections < filename" "sudo dselect" is a possible substitution for "sudo dpkg --set-selections < filename" "apt-get dselect upgrade"
    I may as well rewrite those commands here in case that page is cleared up
  • gritty
    sudo dpkg --set-selections < package.selections && sudo apt-get dselect-upgrade
  • How to install #Ubuntu fresh **and keep** your installed apps as well as your desktop/apps configuration: http://tinyurl.com/58alep
  • joe
    ( Home in its own partition ) This is how 90 percent of real linux distros do it and have done it for years just for that reason. ubumtu is just a crappy fanboy os, trying to do things the easy way, not really the right way.

    I take it you have never really ran linux or have no clue about linux and what it really is.
  • [enlace de utilidad] Cómo actualizar tu distribución de Ubuntu sin perder tus datos ni programas.. http://bit.ly/HAGr
  • flip
    Boo, could you explain that a little more? I was following Rami's explanation pretty well until I got to your suggestion.

    I take it you are suggesting that you have a separate partition in your new install for /home so you can reinstall again in the future without disturbing it?

    If that is right, how is it done? I assume the rest of Ubuntu needs to know where it is.

    Thanks,

    phil
  • crux
    use apt-on cd and restore it. that's the easiest way.
  • At first glance this title made me think of an analogy to that *other* os and I read it like "Repair-Installs for XP are okay!"(gag!)
  • It works for you (right now) and that's great - just don't be afraid to experiment with other distros. VirtualBox and VMWare make it trivial to make a second system to test on. Maybe you have an external HDD somewhere via USB/1394.

    *Note to all*
    Don't forget, when making a USB key/HDD boot with GRUB
    "(hd0,0)" in the menu.lst (or grub.conf)
    That one caught me for a few days untill Google to the rescue.
  • I will second the Update issues - I'm on my Uber-customized lappy that I installed Ubuntu 7.10 on last Feb when I got it because Vista just blows big moose wooter.

    Every time I even think of upgrading to 8.04 I shudder - and I don't really want to use anything else at the moment because I need to go back through and notate all of my additions/customizations for the next distro (Gentoo - I should have never left it).

    Hardware support for me is a must since I've got one of those Atheros EG5007 integrated wireless cards (chip?) and IMHO MadWifi is a tangled mess, but it works enough for now. (No NDISWrapper - I refuse to use a 'Windows" driver on my box)
  • you could also use the copy command with the archive option to copy your home directory, so that you preserve the modification and creation dates of your files.
    cp -a /home/joedoe /DestinationFolder
  • I was hesitating fresh install but now I am more willing and confident to do so. What about Perl modules that I installed thru CPAN. Is there a method (similar to dpkg -get-selections) in cpan to keep list of installed modules and then re-install them?
  • Mike
    Don't forget /usr/local if you compiled anything from source. Its also probably worth looking in /opt.
  • shamil
    I meant to say paranoid instead.
  • shamil
    That's getting a little too in depth as well. Basically setting up your own home partition leaves your files and settings alone when you do a fresh install. And yeah when you install a different distro or upgrade to a newer one, yeah, your home directory app settings will get affected depending on which version of app is going to be in use. Why is this so? Because app settings get stored in hidden folders in the home directory of your user profile. I'm pretty sure upgrading something like firefox2 to firefox3 will affect the app settings for it in your home directory.
    Your documents and stored stuff wont get affected though.
  • weizbox
    If you do a lot of tweaking, I would suggest getting a distro other than Ubuntu. Get something that allows you to customize the distro a little more like Arch or Gentoo. Ubuntu is great for grandma, etc.. but if you want to do anything serious, it makes it more of a pain than it's worth.
  • As Michael said, I tweak a lot, and I never felt comfortable with a straight upgrade....
  • yes I chown'ed, totally forgot about that!

    And yes I do also have a separate /home, but I was aiming for the least common denominator ;)
  • It may be superficial, but again I don't really have such configurations. My mail is in the cloud, and don't really use anti-virus, or spamassasain. Personally my apps and config is all I need. I am sure I am not alone, and its still relevant to a lot of people out there. Then again, users who have such configs aren't exactly noobs to forget to back up these files.
  • Why would you remove .mozilla?
  • I guess that depends on where the DB is located right? I don't know about mythtv to be honest never really used it, but me thinks it should also be in /home.

    Unless you mean the multimedia itself.
  • You are totally right, however the post idea occurred to me only 1 week ago :S

    Hopefully this will still be relevant with 9.04 ;)
  • Thanks windcallers for your suggestions. I really value such suggestions from new comers as yourself. After a couple of years on Linux, one tends to forget how some simple stuff seemed so confusing :)

    Will take your suggestion into consideration :)
  • windcaller
    How about an article about on how to partition and place your home directory in that partition. What is a good size partition for Ubuntu? Then a new article on how to get your new Ubuntu to recognize the home file in another partition. Just moved fully over to Ubuntu from MS two weeks ago. Thank you for writing this article it makes my life easier.
blog comments powered by Disqus