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 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.

«

»

  • http://twitter.com/bianconeri4ever/statuses/1001893383 bianconeri4ever (bianconeri4ever)

    Latest blogpost: Howto: Fresh Ubuntu Install Without Losing Your Current Settings http://is.gd/77h7 don’t forget to Digg or Stumble!

  • Bartek

    I do the same thing +

    tar -xzvf config.tar.gz /etc

    just in case I realise there’s something I need from there. Normally it is not needed, but sometimes I find that I lost my TV card options or a PPP provider settings.

    The file is not much in terms of disk space, so always worth a backup.

  • http://vadi-blog.com Vadim P.

    I heard that you shouldn’t be saving the .gnome_2 and whatever system hidden folders are there, because settings can change between releases. So I only backup my personal data.

  • Boo Radley

    It should be mentioned that an ideal install would have the /home folder in it’s own partition – then no need to backup (at least not specifically for the install)

  • weizbox

    ‘Common wisdom would suggest that a clean install would probably be better..’
    How come? How would a clean install be better than an update? I like doing fresh installs with Windows… but not with Linux. I’ve had the same install for 6 years without any issues.

    Should Ubuntu users really reinstall every 6 months if they want to keep current?

  • http://twitter.com/top_web/statuses/1002914701 top_web (top_web)

    Digg: Fresh Ubuntu Install Without Losing Your Current Settings: hehe2.net — (Digg and comment.. http://tinyurl.com/58alep

  • http://twitter.com/top_dedist/statuses/1002916609 top_dedist (top_dedist)

    Digg: Fresh Ubuntu Install Without Losing Your Current Settings: hehe2.net — (Digg and comm.. http://tinyurl.com/58alep

  • Jwess Wilder

    Ubuntu totally RULES in any shape or form.

    jess
    http://web-anonymity.vze.com

  • http://www.prettyscripts.org prettyscripts

    thanks for this information. it’s very useful.

  • Chris

    “Common wisdom would suggest that a clean install would probably be better”

    This “wisdom” isn’t true for Linux. Just upgrade.

  • E

    If you’re doing things right when you do the initial install, there’s no need to back up your home folder.

    I’ve had /home on a different partition than / and I’ve been able to retain it and my settings across many fresh installs. Not just between Ubuntu distributions. But also many others. All it takes is an extra 10 or so clicks during the install process.

    However, you may have to do a chown -R once the install is complete. But that’s trivial.

  • Tim

    False. Ubuntu has a poor track record for upgrades. Things often break, particularly with hardware support.

  • marcabru

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

    typo:

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

    you left one of the dashes.

    If you forget the hidden (dot) files, you lost your e-mails, bookmarks and browser history too. Not only your configurations. And your’re better making a backup with tar instead of just copying, because tar conserves the exact file permissions too.

    I agree with you, it’s better to do a clean install. But it’s good to backup your system-wide settings too, i.e., the whole /etc directory. You should not restore /etc into your new installation, but it’s good to have a working xorg.conf or other configuration file around, when something is wrong with your new system.

  • marcabru

    And another thing:

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

    you don’t need sudo here.

  • http://mrooney.blogspot.com Michael

    Well not necessarily, but this is great for all us alpha/beta testers who might have a crufty install, with some things compiled from source with patches, and otherwise messy setups from toying around / debugging.

  • http://hehe2.net Rami Taibah

    Hmm that’s weird, there IS a double dash in both commands. However it’s just appearing as one long dash. Any ideas?

    Oh and thanks for you feedback :)

  • http://twitter.com/top_dedist/statuses/1003468397 top_dedist (top_dedist)

    d: Howto: Fresh Ubuntu Install Without Losing Your Current Settings http://tinyurl.com/58alep

  • http://twitter.com/top_web/statuses/1003468450 top_web (top_web)

    delicious: Howto: Fresh Ubuntu Install Without Losing Your Current Settings http://tinyurl.com/58alep

  • jonathan hopley

    You only need to go to the ubuntu forums to see how many failed upgrades there have been to know that a fresh install and if you want to backup you programs just copy /var/cache/apt/archives to your external hdd.I personally prefer a fresh install but we all have our different preferences

  • Vishnu Rao

    Aw man, I wish you had posted this howto a week earlier. Just did a fresh install last weekend. :-(

  • shamil

    This is easy to do fresh installs without needing to download some freaking utility. Make a home partition. Then you can format the root partition as much as you like, and your settings, documents, files, in your home partition don’t get affected.

  • http://apps.jooopa.ne ret

    Ubuntu totally RULES in any shape or form.

  • Agathe

    little trick

    sudo dpkg –get-selections > ~/package.selections

    tilde ‘~” will be automatic change to YOUR home !

  • pcozzy

    good info, I never looked at man dpkg for something like this. My system is that every time I install an application I have a text file with all the apps I install on my desktop. My home directory is the separate partition. I backup though then I remove .mozilla and reinstall. After doing this for the past few years I realized that I install a lot of stuff never used so in the reinstall I select useful apps.
    gonna give this a shot, since I seem to stay current with Ubuntu Ultimate releases.
    thanx

  • http://www.neohide.com Keith

    Never knew this exists although I did believe in the past that one could save the configuration outside and do a fresh install to restore all the previous configurations.

    Having lost touch with Ubuntu for quite some time, this might be a good practice for me to upgrade my current Ubuntu system; as such this trick can come into good use. Simple and easy, just wondering if it’s just too good to be true.

  • Blue

    While this might seem to be the solution it is only superficial. It does not keep network settings, nor does it keep the configuration of apps such as spamassassin, email, antivirus (needed to prevent viruses being relayed to windows machines) etc, where configuration data is not stored in the user’s home area.

  • http://geekman.com jgb

    I think perhaps that the second command in the article should read:

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

  • http://www.peppertop.com/blog/ MarkC

    Don’t forget any other data that might not necessarily live in your home directory – others have already noted /etc but don’t forget things like MySQL databases.

  • heythere

    What about backing up databases?

    How do I make sure all my mythtv data or website data doesn’t get whacked?

  • http://www.midnightclublosangelescheats.com/ Midla

    You should of posted this when 8.10 was released, I could of used this a few weeks ago.

  • Al

    When backing up the sources.list you can’t just replace the version on the new install. You need to manually add any extras and take care, most repositories will indicate the release in the deb line (i.e. hoary gusty whatever)

  • http://www.javipas.com/2008/11/13/instala-ubuntu-de-cero-sin-perder-tus-preferencias/ Instala Ubuntu de cero sin perder tus preferencias | Incognitosis

    [...] práctico genial el que se han currado en Royal HeHe2-ness! (vaya nombrecito), que muestra cómo poder instalar desde cero una nueva versión de Ubuntu y hacer [...]

  • B

    And what about the programs I installed manually that ain’t in the repositories ?

  • http://hehe2.net Rami Taibah

    Well in that case you will probably need to reinstall them again. Just note them down and install it again. But hey this method does 90% of the leg work….

  • 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.

  • http://hehe2.net Rami Taibah

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

  • http://hehe2.net Rami Taibah

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

  • http://hehe2.net Rami Taibah

    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.

  • http://hehe2.net Rami Taibah

    Why would you remove .mozilla?

  • http://hehe2.net Rami Taibah

    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.

  • http://hehe2.net Rami Taibah

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

  • http://hehe2.net Rami Taibah

    As Michael said, I tweak a lot, and I never felt comfortable with a straight upgrade….

  • 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.

  • 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.

  • shamil

    I meant to say paranoid instead.

  • http://links.bubmiller.com/2008/11/13/links-for-2008-11-13/ Web Sites of Interest » links for 2008-11-13

    [...] Howto: Fresh Ubuntu Install Without Losing Your Current Settings (tags: upgrade ubuntu tutorial todo tips tip restore pc settings update) steve on November 13th, 2008 | Filed under 15 | [...]

  • Mike

    Don’t forget /usr/local if you compiled anything from source. Its also probably worth looking in /opt.

  • http://www.guyker.com/2008/11/%e4%b8%8d%e6%94%b9%e5%8f%98%e7%b3%bb%e7%bb%9f%e8%ae%be%e7%bd%ae-%e5%85%a8%e6%96%b0%e5%ae%89%e8%a3%85ubuntu.html ??????? ????Ubuntu | ???

    [...] ????Howto: Fresh Ubuntu Install Without Losing Your Current Settings????? [...]

  • http://alperyilmaz.org ayilmaz

    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?

  • http://0ddn1x.wordpress.com/2008/11/14/maintain-your-settings-across-installs/ Maintain your settings across installs « 0ddn1x: tricks with *nix

    [...] Maintain your settings across installs Filed under: Linux — 0ddn1x @ 2008-11-14 19:58:42 +0000 http://hehe2.net/linuxhowto/howto-fresh-ubuntu-install-without-losing-your-current-settings/ [...]

  • http://queleimporta.com Alejandro Cuervo

    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

  • http://eco-geeks.net Jon Craig

    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)

  • http://eco-geeks.net Jon Craig

    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.

  • http://eco-geeks.net Jon Craig

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

  • crux

    use apt-on cd and restore it. that’s the easiest way.

  • http://www.davidgilson.co.uk/2008/11/bookmarks-for-november-13th-through-november-18th/ David.R.Gilson » Blog Archive » Bookmarks for November 13th through November 18th

    [...] Howto: Fresh Ubuntu Install Without Losing Your Current Settings – 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? [...]

  • http://ubuntu.philipcasey.com/19/11/2008/intrepid-ibex-is-a-beauty/ Intrepid Ibex is a Beauty

    [...] If you don’t want to risk all that, have a look at Howto: Fresh Ubuntu Install without losing your current settings. [...]

  • 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

  • http://twitter.com/joserojas/statuses/1056101533 joserojas (Jose Rojas)

    [enlace de utilidad] Cómo actualizar tu distribución de Ubuntu sin perder tus datos ni programas.. http://bit.ly/HAGr

  • 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.

  • http://twitter.com/bossmanbeta/statuses/1098583646 bossmanbeta (bossmanbeta)

    How to install #Ubuntu fresh **and keep** your installed apps as well as your desktop/apps configuration: http://tinyurl.com/58alep

  • gritty

    sudo dpkg –set-selections < package.selections && sudo apt-get dselect-upgrade

  • gritty

    sudo dpkg –set-selections < package.selections && sudo apt-get dselect-upgrade

  • http://www.halloit.com Mark

    One suggestion from the ubuntu wiki I originally found the advice
    https://help.ubuntu.com/community/FeistyUpgrade…
    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

  • http://www.halloit.com Mark

    One suggestion from the ubuntu wiki I originally found the advice
    https://help.ubuntu.com/community/FeistyUpgrade…
    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

  • http://ubuntu.linuxguru.co.uk/ubuntu-reinstalledmonitors-just-showing-garbage/4498/ Ubuntu Linux » Blog Archive » [ubuntu] Reinstalled..monitors just showing garbage

    [...] [ubuntu] Reinstalled..monitors just showing garbage Due to various problems stemming from what was apparently a missing Randr extension, I reinstalled yesterday, as instructed here: http://hehe2.net/linuxhowto/howto-fr…rent-settings/ [...]

  • trex9016

    Be aware that you have to be careful restoring /home specially all those gnome hidden directories

  • trex9016

    Be aware that you have to be careful restoring /home specially all those gnome hidden directories

  • http://www.informatica-global.com/2010/05/howto-fresh-ubuntu-install-without-losing-your-current-settings-the-linuxologist-howto-fresh-ubuntu-install-without-losing-your-current-settings-bringing-linu Howto: Fresh Ubuntu Install Without Losing Your Current Settings | The Linuxologist Howto: Fresh Ubuntu Install Without Losing Your Current Settings | Bringing Linux to the Masses « Informatica Information Systems Ltd.

    [...] Howto: Fresh Ubuntu Install Without Losing Your Current Settings | The Linuxologist Howto: Fresh Ubu…. var a2a_config = a2a_config || {}; a2a_config.linkname="Howto: Fresh Ubuntu Install Without [...]

  • http://twitter.com/AndyShutcha Andy Shutcha

    Hi i’m Andy, very helpful tut, but had problems with ubuntu 11.04 the
    “sudo dpkg –set-selections /home/package.selections && apt-get dselect-upgrade” didn’t work, so i had to modify it to “sudo dpkg –set-selections < /home/package.selections && apt-get dselect-upgrade", Notice '<'
    Thanx again!

  • http://www.facebook.com/profile.php?id=1318242333 Daniel Cuneo

    I prefer rsync -au .

    If you’re unfamiliar with rsync try rsync -auhn –stats.
    n is dry run, h is human readable and –stats willl kick out # of files transfered

     

  • http://pulse.yahoo.com/_J37PSS7EQP25L2RUZUTNTVQL74 r@dvil

    hi there..im a newbie in Linux Ubuntu..im currently using Lucid Lynx and thinking about installing 11.04..does the above procedure applies to what i would want to do?  i want my old apps and settings but i also want to upgrade to a newer Ubuntu version…
    (note: not really well versed in the command line and tar command) is there a more ‘newbie-friendly’ way to go about this? thanks in advance..

  • Ryan Doherty

    just fyi, this line:

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

    should have a less than symbol before /home! I can’t type the line here, for some reason it deletes the rest of the line.

    The less than symbol reverses the get-selections run when backing up your data.

    Great overview, thank you!

  • Wiktor Ku?mierczyk

    problem with ubuntu is when i update (mostly i do two distribution upgrades in a row) – this causes system to update sooooooo long and also a lot of old software remains – so “common wisdom” is good. I use Ubuntu from two years and it’s almost sure that after upgrade something will not work properly which IS working properly on fresh install, therefore i use information from this article ;)

  • http://profile.yahoo.com/ZWN372QDH53UV33GFM5POK2JWU Essa Tikanen

    The wrong word was used here.  What the writer really means is “Upgrade” as Ubuntu is aware of newer versions’ availability, either by checking online or by finding an Ubuntu distribution disc that is newer inside the optical drive.  The latter is much akin to what happens when you put a Windows 7 disc in a computer installed with XP or Vista, for example.

  • Jonathan Ma

    does this work for changing from inside windows  to full install?