Record Installed .deb Packages In A Text File (Ubuntu/Debian)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2009-03-12 12:10. :: Debian | Ubuntu | Desktop

Record Installed .deb Packages In A Text File (Ubuntu/Debian)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 03/06/2009

This short guide shows two methods of recording all your installed .deb packages in a text file that you can then use on another computer to install the same packages there. This is useful if you want to install the same set of packages on more than one computer.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I will show how to do this on the desktop (with Synaptic) and on the command line. I'm using a USB stick to store the text file; that way I can simply plug in the USB stick with the text file into the other computer and start the package installation there.

If you try this, please make sure the the file /etc/apt/sources.list is identical on both systems (if you like, you can also copy that file to the USB stick so that it can be used on the other computer).

 

2 Synaptic Package Manager

This chapter shows how you can create the package file with the Synaptic Package Manager. Open the Synaptic Package Manager (System > Administration > Synaptic Package Manager):

Then go to File > Save Markings or File > Save Markings As...:

Type in a name for the file (e.g. my_packages.txt) and check Save full state, not only changes (otherwise it would save only the changes that you've made in the current Synaptic session). Select your USB stick to save the file (my USB stick is named disk):

That's it. Now plug the USB stick into the other computer, open Synaptic, and go to File > Read Markings...:

Select the my_packages.txt file from the USB stick:

Afterwards, you should notice that some packages are marked (the ones that are installed on the first system, but not on this one). Click on Apply to start the installation:

 

3 Command Line

This chapter shows how you can create the package file on the command line. Open a terminal (Applications > Accessories > Terminal) and type:

sudo dpkg --get-selections "*" > /media/disk/my_packages.txt

(I'm assuming that /media/disk is your USB stick.)

Now plug the USB stick into the other computer, open a terminal there and run...

sudo dpkg --set-selections < /media/disk/my_packages.txt
sudo apt-get -u dselect-upgrade

... to start the package installation (I'm assuming that the USB stick's mount point on the second computer is /media/disk again).

 

4 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by johan (not registered) on Wed, 2009-09-30 01:15.

This is very helpfull, but sometimes you whant versions also, you whant to duplicate a machine and avoid updates which could cause problem for your usage. I have a solution for it.

DRY RUN SCRIPT
echo -n "apt-get -s install" > update.sh
dpkg-query -W -f=' ${Package}=${Version}'>> update.sh
chmod 700 update.sh

DO UPDATE SCRIPT
echo -n "apt-get install" > update.sh
dpkg-query -W -f=' ${Package}=${Version}'>> update.sh
chmod 700 update.sh

Johan

Submitted by Marcus (not registered) on Mon, 2009-03-23 13:16.

Using dpkg --[get|set]-selections will miss the information on which packages were installed manually and which were installed automatically to satisfy dependencies. So on the target machine those packages that were installed automatically won't be removed when they are no longer needed. To keep the information about auto-installed packages instead of dpkg --get-selections one should use aptitude-create-state-bundle(1). On the target machine simply run aptitude-run-state-bundle(1) instead of dpkg --set-selections. Just my €0.02 ;) Cheers Marcus

Submitted by Anonymous (not registered) on Sat, 2009-03-14 11:24.

Thanks for the post.

On the target system it probably would be a good idea to run
sudo dpkg --clear-selections
before dpkg --set-selections.  According to the man-page this makes sure that no packages installed on the target and not on the source are set to be removed when running the apt-get command.

Submitted by Alejandro (not registered) on Thu, 2009-03-12 12:54.

Very useful post.

Anyway, I think you should aware  that this method only works well if you use the same Ubuntu version on both computers.

This applies not only to the release  (i.e. 8.10), but also to the type of installation (server or desktop) and the hardware architecture (Intel 32 bit, AMD 64 bit...)

Great and useful post, as always

 

Submitted by hippie (not registered) on Thu, 2009-03-12 21:29.
I get an empty text file.
Submitted by treb0r (not registered) on Sun, 2009-03-15 02:10.
Same problem here. Synaptic just saves an empty file. Any ideas?
Submitted by falko (registered user) on Sun, 2009-03-15 02:52.
Did you check Save full state, not only changes?