
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: ubuntu, linux, packages, technology, geek, tech
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.
Popularity: 27% [?]












September 20th, 2006 at 4:51 am
You’ve got my attention. I am planning to perform a reformat of my PC, so this will definintely come in handy. Cheers!
September 20th, 2006 at 4:59 am
Hmm. Thats a nifty one. Thanks. Will certainly come in handy.
- Mskadu
September 20th, 2006 at 5:00 am
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.
September 20th, 2006 at 9:33 am
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)
September 20th, 2006 at 9:39 am
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
September 20th, 2006 at 9:45 am
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
September 20th, 2006 at 9:48 am
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
September 20th, 2006 at 10:26 am
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.
September 20th, 2006 at 10:40 am
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!
September 20th, 2006 at 10:41 am
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.
September 20th, 2006 at 10:45 am
HipJiveGuy,
If your sources list has been modified, it would need to be backed up as well.
–Lee
September 20th, 2006 at 3:38 pm
Wow so the Ubuntu users are discovering one of the many wonders of Debian. ‘Bout time you got caught up.
September 21st, 2006 at 12:30 pm
great trick.thanks
November 8th, 2006 at 2:11 pm
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.
November 11th, 2006 at 11:53 am
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
November 11th, 2006 at 11:54 am
Little error in my command line
sudo dpkg –get-selection | grep †install†> ubuntu-files
sorry
December 5th, 2006 at 5:24 am
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…
December 5th, 2006 at 8:45 am
Donn,
Thanks for the \b tip! Very useful.
June 5th, 2007 at 1:01 pm
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 ?
August 29th, 2007 at 9:02 am
Hey man, thanks a lot! That was a breeze with Ubuntu Feisty and really simplified things for me.
August 29th, 2007 at 9:06 am
Excellent Matt. Glad it went smoothly for you.
October 18th, 2007 at 11:13 am
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.
October 18th, 2007 at 11:15 am
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
December 3rd, 2007 at 2:46 pm
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
February 7th, 2008 at 11:14 am
you can also perform the final step using apt-get instead of dselect:
sudo apt-get update
sudo apt-get dselect-upgrade
February 13th, 2008 at 12:00 pm
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.
February 14th, 2008 at 12:32 am
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”.
February 14th, 2008 at 12:40 am
sudo gedit /etc/cron.d/my_cron_file
Left out “gedit”.
May 11th, 2008 at 8:22 am
just one thing.
it print out all installed packages. including installed dependencies.
how can i see only what i install manualy, excluding dependencies??
tia
August 13th, 2008 at 4:17 am
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?
August 26th, 2008 at 5:02 am
In the “dpkg –get-selections | grep -v deinstall > ubuntu-files” command, what does the “deinstall” option do?
January 8th, 2009 at 4:58 pm
hi
k56yjxon6psu63ya
good luck
January 10th, 2009 at 5:53 am
hi
k56yjxon6psu63ya
good luck
October 23rd, 2009 at 10:08 pm
nice!
you can also execute the following if you replaced the hard disk.
You make a fresh install on the new disk, connect the old disk and execute:
dpkg –admindir=/media/disk-1/var/lib/dpkg –get-selections | grep -v deinstall > ubuntu-files
November 27th, 2009 at 8:46 pm
it is a goooooooooooooooood post
thanks for share
May 13th, 2010 at 7:03 pm
Very interesting topic will bookmark your site to check if you write more about in the future..
Ubuntu Tricks – how to generate a list of installed packages and use it to reinstall packages | ArsGeek
May 30th, 2010 at 4:08 am
Between me and my husband we’ve owned a few of the eco bags. These bags are awesome. We are able to store many gorceries into a bag. So easy to use and clean too. Do yourself a favor and get a bunch of these green bags. No more plastic bags in the future.
July 8th, 2010 at 3:45 am
Thank you for this tips, but from my own experience I can tell that even a newbie can figure out what to do to install and reinstall packages in Ubuntu it is simple like 1-2-3.
July 31st, 2010 at 4:06 pm
That,s a great idea. Though I’m not much of a gamer but I will definitely try this tool in some
other directions connected with flash format. Thanks for sharing
August 10th, 2010 at 3:47 am
Cool!! those are very useful tips. thanks!
September 9th, 2010 at 5:02 pm
you are professional.
November 15th, 2010 at 9:22 pm
Great tip! Thanks a lot!
November 21st, 2010 at 5:54 pm
When I typed the last command
sudo dselect
I just got “sudo: dselect: command not found”
I have Kubuntu 10.10 /32b/
Any idea, pls?
November 26th, 2010 at 11:19 am
Thanks for this tutorial it helped me to detect what packages I need to reinstall.
January 7th, 2011 at 12:53 pm
Wow so the Ubuntu users are discovering one of the many wonders of Debian. ‘Bout time you got caught up.
January 7th, 2011 at 12:57 pm
Hey man, thanks a lot! That was a breeze with Ubuntu Feisty and really simplified things for me.
January 7th, 2011 at 12:58 pm
If your sources list has been modified, it would need to be backed up as well.
January 27th, 2011 at 4:44 pm
::’ I am really thankful to this topic because it really gives up to date information ,”~
February 27th, 2011 at 1:00 pm
So what do? We go out on a mission to try and find the best push-up bra ever invented, while some women seek out a good plastic surgeon for a breast lift Scottsdale women are beginning to see that they don’t need to live their life unhappy about how they look.
March 5th, 2011 at 10:29 am
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!
April 13th, 2011 at 3:59 am
Thanks for the post. Now, i can easily generate list of installed packages.
April 14th, 2011 at 5:19 am
nice post. I agree with your point,nice article,thanks.
May 4th, 2011 at 3:35 pm
Pretty insightful submit. Never thought that it was this simple after all. I had spent a great deal of my time looking for someone to explain this topic clearly and you’re the only one that ever did that. Kudos to you! Keep it up
June 22nd, 2011 at 10:56 pm
One little tidbit. My clean Ubuntu 11.04 install did not recognize the “sudo dselect” command. I searched the software center for that word, and installed it from there, and the restore process went just fine from there. That sure makes for a nice way to restore the software environment after screwing it up! Thanks!
August 10th, 2011 at 6:03 am
Hello ArsGeek,
many thanks, it’s a very helpful post.
Is there also a way to save and restore all config files of the installed packages in the same manner?
Best regards,
Erwin
August 17th, 2011 at 8:50 am
Thnks, it was what i was looking for !!!
Thanks a ton
August 24th, 2011 at 1:19 am
I am extremely impressed together with your writing talents neatly as with the format on your weblog. Is this a paid subject matter or did you modify it yourself? Either way keep up the excellent quality writing, it’s uncommon to peer a great weblog like this one today.
August 24th, 2011 at 9:48 am
Undeniably believe that which you stated. Your favorite justification seemed to be on the web the simplest thing to be aware of. I say to you, I definitely get irked while people think about worries that they plainly don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks
September 4th, 2011 at 2:37 pm
Excellent publish however i was wondering if you might create the litte read more about this subject? I would end up being really happy if you might sophisticated slightly additional. Be thankful!
September 13th, 2011 at 1:06 pm
At the moment I stumbled upon the web for exactly these kinds of details. Thank to your publish that search has got to finish right this moment. You published the posting in a very easy to undestand way. With this, I included your sites among my favorites! All the best!
October 6th, 2011 at 9:01 am
its very nice site. i have read lot of wonderful things here and entertaining too.i am very thankful to you because here i can remove my reading and knowledge thirst.please keep posting
October 6th, 2011 at 9:04 am
Thank you for the work you have put into this post, it helps clear up some questions I had.I will bookmark your blog because your posts are very informative.We appreciate your posts and look forward to coming back..
October 6th, 2011 at 9:05 am
Thank you for the work you have put into this post, it helps clear up some questions I had.I will bookmark your blog because your posts are very informative.We appreciate your posts and look forward to coming back..road runner
October 6th, 2011 at 9:07 am
I must say the man is really blessed with art and talent. He makes a good use of his depth and color. Worth visiting his exhibitions. I think James Koehler is really a gifted artist
October 22nd, 2011 at 4:50 pm
Thank you for these instructions. I’m glad I found this site through Google search.
October 22nd, 2011 at 4:53 pm
Thank you for these instructions. I’m glad I found this site.
October 27th, 2011 at 4:50 am
Look for a very long time that 09 spring summer fashion show, everyone is there a seems to have had the feeling of spring? For everyone to beat exposure part of LV (Louis Vuitton) 09 early spring bag.
October 27th, 2011 at 5:02 am
This time the lovely bulldog bag with no one can still vivid match colors to lure enemy you heart.
October 27th, 2011 at 5:07 am
What new things are curious, willing to try different he is everyone idea of the eldest brother; Julius let the life is full of surprise, you never know what will happen next second thing!!!!!
December 8th, 2011 at 1:45 am
This design special deserve to act the role of normal became fashionable dress reflect individual character and the essence in the beautiful field lens of rob good baby, also occasionally by female stars “take” on fashion activities, for modelling win disappearing eyes.
December 23rd, 2011 at 2:19 am
In addition, KongXianZhu will and HanYi Fraser, the nangongshan people together in the new TV star, show soon will begin taking work.
December 26th, 2011 at 3:55 am
seen as vulgar and vulgar bump color collocation, become the most costly high-key jing is colourful choice, red no longer rely on black, New Year’s eve, and costly, the light will show off black out of the most avant-garde fashion outside.