
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.















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