27

I have one machine setup with the apps I need, and I'd like to install the same on a new Ubuntu box.

Is there a script that will list all the installed apps, so that I can diff between the boxes and so add the missing items?

Thanks in advance, Chris

Zoredache
  • 128,755
  • 40
  • 271
  • 413
Chris Kimpton
  • 713
  • 9
  • 18

9 Answers9

18

Aswell as the dpkg tricks mentioned by pjz, you may also want to look at etckeeper (tutorial ) - an app that puts your /etc/* under version control, making it easier to find any changes you've done and replicate them to other servers.

Also, for a shorter list than that produced by pjz's method, you can use

$ deborphan -a --no-show-section > /tmp/mypackagelist

This will give you a list of packages that will install all the other packages you require as dependencies. Can be useful if you actually want to look through the list. (dpkg --get-selections will produce a loooong list). In addition the list is short enough that you could add newlines and comment out entries with '#'. Then when installing the extra packages you can do

$ grep -v '#' /tmp/mypackagelist | xargs apt-get install -y

This way, if there are some packages you only want to install on some machines, you don't have to delete them from the package list altogether.

Hamish Downer
  • 9,142
  • 6
  • 36
  • 49
  • etckeeper looks really interesting (+1). – jkp Apr 30 '09 at 17:30
  • "you may also want to look at etckeeper (tutorial ) - an app that puts your /etc/* under version control" - is that enough to keep all packages the same from one machine to another? Or is there a similar tool which can actually just reinstall all packages from one system to another? – Peter Elbert Aug 04 '22 at 11:15
17
dpkg --get-selections >/tmp/mypackagelist

should do the trick. Then, after making sure that your /etc/apt/sources.list on the new machine has the same set of entries as on the old, copy mypackagelist over to the new machine and do:

cat mypackagelist | xargs apt-get -y install 

and you should be good to go.

Note that the dpkg --get-selections line is also good info to put into your /etc/dir ocassionally - it means you don't have to bother to back up /bin/ and /usr/bin/ and such because you know what packages are on the system.

Jeff Atwood
  • 12,994
  • 20
  • 74
  • 92
pjz
  • 10,497
  • 1
  • 31
  • 40
  • Yes, Jeff, but how about the modifications to the configuration files? how about the dpkg-reconfigure options? how about hostnames... users, shares, mounts... See my response about `dd` bellow – elcuco Jul 18 '09 at 10:01
2

Ubuntu Forums has a good answer

  1. On the old machine: $ dpkg --get-selections > installed-software
    • This gets your list of installed apps
  2. On the new machine: $ dpkg --set-selections
    • This sets the new machine to install the packages not currently installed on the new machine.
    • It might be interesting to see if the new machine has some packages not installed on the old machine, so you could find the dpkg --get-selections> command on the new machine, and then use diff to compare the output files from both.
  3. Finally, on the new machine: $ dselect and the packages will be installed.

Some additional links from the forums discussion:

  1. Don't forget your gpg keys (from the same thread)
  2. How to install all the desired packages and uninstall all the undesired packages
pcapademic
  • 1,650
  • 1
  • 14
  • 22
2

The better dpkg commands may be [original machine]

dpkg --get-selections | grep -v deinstall > packages_list

then when installing [new machine; after transferring the packages_list]

sudo dpkg --set-selections < packages_list
sudo apt-get -u dselect-upgrade
Benji
  • 39
  • 3
1

If you're not a CLI fan (although you really should be), you can use the Synaptic package manager to save the image of the installed packages, and use that file (again through Synaptic) to load the new machine. Under the file/save markings option, there is a checkbox called "save full state".

Nerdfest
  • 618
  • 4
  • 7
1

Why aren't you just clonning the machine using dd?

elcuco
  • 357
  • 1
  • 4
  • 10
  • 1
    This. Just clone the machine and change the name, it's by far the fastest way of doing it. – pjc50 Jul 17 '09 at 16:46
1

There is a tool called ReMasterSys that can do it for you. see http://geekconnection.org/remastersys/

I hope that will be of use.

1

Using FSArchiver to replicate the machines is perfectly acceptable. Otherwise, here are useful pairs of commands, the first half of which you can also add to your backup cron:

debconf-get-selections
debconf-set-selections

~

aptitude-create-state-bundle
aptitude-run-state-bundle --unpack

~

dpkg --get-selections
dpkg --clear-selections; dpkg --set-selections

Locations you should replicate are /etc and /var. The above commands manipulate a few files in /var directly, and some conffiles in /etc indirectly via debconf. You will get the same effect by just replicating those subtrees and running aptitude.

Tobu
  • 4,367
  • 1
  • 23
  • 31
0

I guess Docker would be the way to do this now - define the requirements in a Dockerfile - you can then run it on any Docker host.

Chris Kimpton
  • 713
  • 9
  • 18