RSS

Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages

Tue, Sep 19, 2006

ArsGeek, Linux, Ubuntu

Talk about it in our Forums

Packages

This tutorial will work for any Debian based system, but is written specifically for Ubuntu.

I’ve recently had the occasion to make a complete list of software installed on one of my Ubuntu boxes, and then reinstall it from scratch. Here’s a quick and easy way to generate a list of installed .deb packages, and then use that list to quickly reinstall them.

First, let’s make the list. You’ll be doing all of this in a Terminal Session:

dpkg –get-selections | grep -v deinstall > ubuntu-files

NOTE: Wordpress interprets two dashes (- -) as one dash (–). When you’re putting this into your CLI, make sure it’s dropping two dashes ‘- -’ without the space between them.

Now you’ve got a list of all of your installed debs in a fairly small file. In my case, I simply moved this file to a thumb-drive. You could also store it on a separate partition or on a disk somewhere. Heck, it’s not that big, email it to your gmail account.

So now you’ve got this list and all is well, until you’re Ubuntu install either dies or has to be reinstalled for some reason. Go ahead and do the base install.

Once you’ve got Ubuntu back up and running, copy your ubuntu-files back into your home directory and do the following:

sudo apt-get update

sudo apt-get dist-upgrade

dpkg –set-selections < ubuntu-files

NOTE: Wordpress interprets two dashes (- -) as one dash (–). When you’re putting this into your CLI, make sure it’s dropping two dashes ‘- -’ without the space between them.

Now you’ve told your system what it needs to install, so let’s install it all.

sudo dselect

This will open up a dselect session. Type ‘I‘ and allow dselect to install of the the packages listed in your ubuntu-files document. When it’s finished, type ‘Q‘ and hit the ENTER key to exit dselect.

Now you’re a lot closer to where you were before.

EDIT: As fak3r points out, you can modify the fist dpkg command line to have it mail yourself the list after creatoin. Like so:

dpkg –get-selections | grep -v deinstall > ubuntu-files; cat ubuntu-files | mailx -s “ubuntu-files” my.mail@my.address

Technorati Tags: , , , , ,

According to the current web hosting review, the hoi polloi is making good use of wireless internet. Now a personal web hosting is usually done through a dedicated hosting service. Gone are the days when people went for shared web hosting without paying any consideration to the website design. The wireless internet has changed everything about website hosting.

Click the icon, share the link:
  • Digg
  • del.icio.us
  • MisterWong
  • Furl
  • Reddit
  • Technorati
  • BlinkList
  • feedmelinks
  • PopCurrent
  • Blogosphere News
  • Facebook
  • Fark
  • Mixx
  • Slashdot

This post was written by:

arsgeek - who has written 1975 posts on ArsGeek.


Contact the author

33 Comments For This Post

  1. Keith Says:

    You’ve got my attention. I am planning to perform a reformat of my PC, so this will definintely come in handy. Cheers!

  2. Mskadu Says:

    Hmm. Thats a nifty one. Thanks. Will certainly come in handy.

    - Mskadu

  3. Vitor Baptista Says:

    Damn, that’s what I was looking for!!

    Just fyi, the 1st command, “dpkg –get-selections | grep -v deinstall > ubuntu-files”, does not work if you simply copy/paste it. Because when you typed, probably it merged the two “–” into one “–”, so, simply do this:
    dpkg –get-selections | grep -v deinstall > ubuntu-files

    Ok, ok, it’s quite obvious. But it took me around 5s to figure out.

  4. Jokin Says:

    No os esforceis, el sistema se come los 2 guiones y los transforma en uno. Lo correcto son dos guiones antes de la orden (get-selections)

  5. arsgeek Says:

    Hi all!

    First, thanks for pointint out how wordpress interprets the two dashes. I’ve edited the post.

    Second, we’ve been getting lots of hits today thanks to digg! Our little server is making a valiant effort to keep up, so bear with us if the site loads slow, or not well!

    geek out

  6. fak3r Says:

    Thanks, I’ve been looking for docs on how to do this, much easier than I suspected! Hey, for a slicker way to backup your ubuntu-file file, cat it and pipe it to mailx for quick email action!

    dpkg -–get-selections | grep -v deinstall > ubuntu-files; cat ubuntu-files | mailx -s “ubuntu-files” fak3r@fak3r.com

    fak3r

  7. arsgeek Says:

    fak3r,

    just saw your comment on Digg and I was coming back here to add it to the post! Thanks for the tip!

    geek out

  8. Lee Colleton Says:

    Why use a file at all? Isn’t the point to have your dpkg selections backed up in email?

    dpkg –get-selections | grep -v deinstall | mailx -s “dpkg-selections for $HOSTNAME” address@example.com

    This long list of unique words will probably be flagged as spam.

  9. HipJiveGuy Says:

    I’m a Ubuntu/Linux newbiew, and I’m not near an ubuntu system, so please bare with me if is obvious…

    Will this work without the sources list being updated? Or would you need to keep a copy of your sources as well?

    Thanks!

  10. arsgeek Says:

    Hey HipJiveGuy,

    It would depend on what you had on your system, but that’s a good point. You’ll need your sources.list file to look similar if not the same to install all of the same packages.

    geek out.

  11. Lee Colleton Says:

    HipJiveGuy,

    If your sources list has been modified, it would need to be backed up as well.

    –Lee

  12. mzilikazi Says:

    Wow so the Ubuntu users are discovering one of the many wonders of Debian. ‘Bout time you got caught up. ;)

  13. Prakash Jose Kokkatt Says:

    great trick.thanks :)

  14. Anan Says:

    Great Tips!!

    i am wondering, if it is possible to do the same thing for the desktop appearance:

    To restore the menu, tool bar, background picture that i personalized for my desktop.

    Thank you.

  15. Nicolas Schaetti Says:

    Hi, nice trick, thank you. But when you save the list of file by invoking grep -v deinstall, you pick up the “purge” packages too. So I would rather use:

    sudo dpkg –get-sellection | grep ” install” > ubuntu-files

    To insure that just the right packages are selected. I know that this caution implies only a fw of cases so, sorry for the useless comment ;-)

    Bye

  16. Nicolas Schaetti Says:

    Little error in my command line

    sudo dpkg –get-selection | grep ” install” > ubuntu-files

    sorry

  17. Donn Says:

    Nice tip:

    That space-install ” install” tip earlier doesn’t work.

    This one seems to do it:

    dpkg –get-selections | grep “\binstall”

    The slash-b matches empty space on the edge of a word, so this ensure only the complete word ‘install’ is matched.

    At least I hope so… :)

  18. arsgeek Says:

    Donn,

    Thanks for the \b tip! Very useful.

  19. fj Says:

    Is there a way to list ALL ubuntu packages from CLI, I mean both installed and not-yet-installed ?

    I wonder where did synaptic pkg mgr retrieve those categorized pkg info from ?

  20. Matt Philmon Says:

    Hey man, thanks a lot! That was a breeze with Ubuntu Feisty and really simplified things for me.

  21. arsgeek Says:

    Excellent Matt. Glad it went smoothly for you.

  22. David Says:

    Using this very handy guide and gleaning bits of info from the ubuntu forums, I created a script to perform this on bootup and copy it to my NAS. The script simply contains:

    #!/bin/bash
    sleep 30s;dpkg –get-selections | grep -v deinstall > /home/user/location_on_NAS/ubuntu-files

    and placed it in my /home/user/.local/bin naming it whatever you like, I named it package_list.sh

    The “sleep 30s” causes the script to wait 30 seconds before performing it (handy if it takes your NAS a while to wake up as mine does). Now every time on startup a fresh file is created. You could use it to create the file anywhere you like on your hard drive also. To put it on an external link you will need to automount the remote file system. Here’s a good tutorial on it for ubuntu:

    http://ubuntuforums.org/showthread.php?t=280473

    Which is especially handy if you have a password protected remote directory.

  23. David Says:

    oops, you will also need to make the file in /home/user/.local/bin executable by in a terminal executing chmod +x /home/user/.local/bin/name_of_your_script.sh

  24. Seth Says:

    Thanks a lot, first in google and answers directly.

    I’d rather postpone the grep -v till *after* saving the file, either with tee or by grepping on the ’set-selections’ command instead. That way, I suppress the nerves of ‘discarding’ the information I might find usesful at a later day (after I wiped my system…)

    Cheers

  25. andy baxter Says:

    you can also perform the final step using apt-get instead of dselect:

    sudo apt-get update
    sudo apt-get dselect-upgrade

  26. Kipp Says:

    You can have this list auto-update by adding the “dpkg –get-selections” command like so:

    1. Open Menu - System - Preferences - Sessions
    2. On the “Startup Programs” tab click “Add”
    3. Name: Update installed files
    Command: {as noted in article}
    Comment: Will write a list of all installed files, which can be used to reinstall them (see {wherever you save this webpage to}
    4. Click OK and Close.

    Now whenever you log in the list will be updated.

  27. Kipp Says:

    Update: that didn’t work. So, this does (tested). It establishes a cron job to run on the hour:

    1. Open a terminal and type: sudo /etc/cron.d/my_cron_file
    2. Paste in the following:
    0 * * * * dpkg –get-selections | grep -v deinstall > ubuntu-installed-files
    3. Save and close the file.
    4. The file will be owned and run by root; therefore it will write that file list to every logged-in users directory.

    If you only want it to go to yours, figure out how to make a cron job just
    for you. I don’t know how yet. I had to do some reading and examing
    of files already in the /etc/cron.d/ directory to figure it out. To test it,
    replace the leading “0″ with an asterisk. That will make it run every minute.

    The format of a cron task is (note: not all zero-based indexes):
    min(0-59) hour(0-11) DayOfMonth(1-31) Month(1-12) DayOfWeek(0-6) command

    Be sure to have two dashes in front of “get-selected”.

  28. Kipp Says:

    sudo gedit /etc/cron.d/my_cron_file

    Left out “gedit”.

  29. dennyhalim.com Says:

    just one thing.
    it print out all installed packages. including installed dependencies.

    how can i see only what i install manualy, excluding dependencies??

    tia

  30. cdaaawg Says:

    So, what happens if any of these previously installed packages had required a gpg key? Will it halt the installation process gracefully or wait for input?

  31. Daryl Says:

    In the “dpkg –get-selections | grep -v deinstall > ubuntu-files” command, what does the “deinstall” option do?

  32. Natasha Hopper Says:

    hi
    k56yjxon6psu63ya
    good luck

  33. Leisa Adams Says:

    hi
    k56yjxon6psu63ya
    good luck

30 Trackbacks For This Post

  1. meneame.net Says:

    Como generar una lista de todo lo instalado en Ubuntu para luego reinstalarlo automaticamente…

    Uno de los mejores trucos que he visto para ubuntu: generas una lista de todo lo que tienes instalado para luego poder resintalarlo en tu PC. Ojo que la primera orden tiene un error (– => -), esta es la correcta: dpkg –get-selections | grep -v dei…

  2. 本日書籤 « penk - Keep on rockin’ in the free world Says:

    [...] http://www.arsgeek.com/?p=564 [...]

  3. teknokool.net » Blog Archive » links for 2006-09-20 Says:

    [...] how to generate a list of installed packages and use it to reinstall packages ubuntu tricks (tags: ubuntu) [...]

  4. links for 2006-09-21 « Where Is All This Leading To? Says:

    [...] ArsGeek :: Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages (tags: ubuntu backup howto install linux packages list opensource debian admin) [...]

  5. its about time» Blog Archive » links for 2006-09-20 Says:

    [...] ArsGeek :: Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages (tags: ubuntu install howto debian apt dpkg list backup) [...]

  6. Linux #2 « Paranormalaus pasaulio užeiga Says:

    [...] Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages [...]

  7. Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages : Tech Tips Says:

    [...] Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages [...]

  8. The Inveterate Observer » Blog Archive » Ubuntu tricks - how to create a list software and use it to restore your pc Says:

    [...] I’ve recently had the occasion to make a complete list of software installed on one of my Ubuntu boxes, and then reinstall it from scratch. Here’s a quick and easy way to generate a list of installed .deb packages, and then use that list to quickly reinstall them.read more | digg story [...]

  9. Newy’s Blog » Blog Archive » Easy way to install all pkgs you want on an ubuntu system Says:

    [...] This is a cool process to go through if you are testing ubuntu on a system and have to re-install a bunch of times.  Found it at http://www.arsgeek.com/?p=564 dpkg –get-selections | grep -v deinstall > ubuntu-files [...]

  10. tecosystems Says:

    links for 2006-09-30…

    ongoing · Upcoming Gig: Zend PHP Conference Tim’s right; this should be a fun session - hope to see you there (tags: Zend PHP conference Solaris Sun Bray stacks) EdgyEft/Beta - Ubuntu Wiki i may upgrade to Edgy this……

  11. Linux Says:

    Dave…

    Interesting topic… I’m working in this industry myself and I don’t agree about this in 100%, but I added your page to my bookmarks and hope to see more interesting articles in the future…

  12. tecosystems Says:

    So Far, So (Mostly) Good…

    Zimbra Doesn’t Seem to Like Bon Echo Originally uploaded by sogrady. With my first completely free weekend in a month or so, I decided to take a bit of time and see if I couldn’t get Bishop (my laptop)……

  13. luKas' bloggie [at] vdchuyen.com Says:

    Ubuntu - how to generate a list of installed packages and use it to reinstall packages !…

    Má»›i đọc xong má»™t tip rất hay trên Artgeeks First, let’s make the list. You’ll be doing all of this in a Terminal Session:dpkg –get-selections | grep -v deinstall > ubuntu-f ……

  14. EveryDigg » Blog Archive » Ubuntu tricks - how to create a list software and use it to restore your pc Says:

    [...] I’ve recently had the occasion to make a complete list of software installed on one of my Ubuntu boxes, and then reinstall it from scratch. Here’s a quick and easy way to generate a list of installed .deb packages, and then use that list to quickly reinstall them.read more | digg story [...]

  15. Nicolas Schaetti Says:

    Sauvegarde de configurations de paquets pour Distribution Debian-based (ex: Ubuntu)…

    Ce post est directement inspire de celui de arsgeek a cette adresse. Refere vous au trackback a la fin de ce billet.

    Pour sauvegarder votre liste de paquets installes actuellement sur votre configuration Linux et la sauvegarder dans un fichier…

  16. HOWTO: Use a file list in Ubuntu for quick system restore at fak3r Says:

    [...] While I’ve read this plenty of times, today via Digg I found complete docs that I wanted to save on how to restore a Ubuntu Linux install; bringing it back to the way you had it from a fresh install easily. Why would you need this? Well, hard drives die, but more often (in my case at least) it’s *fun* to start with a fresh system when new versions of Ubuntu come out, or when you *have* to try out the latest/fastest filesystem, or you can’t live without the latest/bleeding edge apps/features. So to start, you’ll first need a snapshot of your installed applications on your working system, which is easy enough to do: [...]

  17. HOWTO generate a list of installed packages for disaster recovery at fak3r Says:

    [...] I came across this page again, seems they took my advice to heart on the one line command to grep out a list of all installed packages on a Debian or Ubuntu system. This creates a file that you can use as a DR (disaster recovery) map of all installed apps — you only need to install your base system, and then use this file to reinstall all of your apps. Their earlier versions didn’t produce a clean list and it certiainly didn’t go the extra mile of emailing a copy to you. [...]

  18. tecosystems » Friday Afternoon Grab Bag Says:

    [...] I’ve installed over the time I’ve used it. With Ubuntu, you can do that as described here. Basically, I have the following line inserted in my crontab: 30 1 * * * dpkg –get-selections | [...]

  19. Afaceri pe internet » Blog Archive » Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages Says:

    [...] Read the article at Arsgeek.com [...]

  20. Web 2.0 Announcer Says:

    backup howto install linux ubuntu

    [...]ArsGeek :: Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages[...]

  21. tecosystems » The RedMonk IT Report: From One Thinkpad to Another Says:

    [...] installed via apt. Therefore, recreating my setup is actually fairly trivial using the instructions here. Making matters easier is that I have that set up on a nightly cron job, which deposits the output [...]

  22. Howto - Generar una lista de paquetes instalados y usarla para reinstalar paquetes | Magarto Says:

    [...] Fuente [...]

  23. Ubuntu Life » Blog Archive » Listar los paquetes que tienes instalados e instalarlos en otra maquina Says:

    [...] original | guia ubuntu y Arsgeek Tambien te puede [...]

  24. Generar una lista de tus paquetes/programas instalados en ubuntu y guardarlos « luisbp Says:

    [...] tutorial está basado en este artículo en inglés publicado por [...]

  25. Linux Al Poder - El Blog de Tuxams297 » Blog Archive » Howto - Generar una lista de paquetes instalados y usarla para reinstalar paquetes Says:

    [...] Fuente [...]

  26. ??????ubuntu - ???? Says:

    [...] via Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages Published in ??? [...]

  27. The Happy Heron « the spike Says:

    [...] To solve this problem, a trick that worked like a charm is this tip from ArsGeek. [...]

  28. Back maken van Cydia/Installer Apps? - iPhone Forum - alles over de Apple iPhone en iPhone 3G Says:

    [...] zou dit even kunnen proberen (ssh naar je iPhone): Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages*|*ArsG… is een ubuntu howto, maar tjah… cydia == apt, dus dit moet in principe wel werken. Ik ga het iig [...]

  29. System/user state backup, Linux? - Perth Street Bikes Says:

    [...] HowTo: Create a list of installed packages - Ubuntu Forums And Ubuntu Tricks - how to generate a list of installed packages and use it to reinstall packages|ArsGee… Do you have another machine Desmo? Maybe slam SVN on it and back your config files up to [...]

  30. Lista generálása a telepített csomagokból és újrainstallálás ezen lista alapján « wordpress Says:

    [...] a leírást a itt találtam, végigcsináltam helyenként igazítottam rajta magyar nyelv? Ubuntuhoz. A [...]

Leave a Reply