Syncing apt-get installations between multiple computers

Is there a way to synchronize my installations (and removals) between multiple PCs?

Preferably with dropbox - since I'm already using that to keep my files in sync.

I thought of an alias for the apt-get install and apt-get remove commands that stores the parameters to a file (one for install, one for remove) and another command that reads all the entries in the file and executes the respective command. Is this a realistic approach?


Solution 1:

I don't know if there is a better way (there probably is), but depending on the scale you need, you could use aptitude's search feature for part of the machinery. It lets you search for packages matching a pattern. So, aptitude search '~i' gives you all installed packages

We need to go a step further, though. The packages manager likes to know which packages were directly requested by you and which ones were just pulled in because of other packages. Without that information, ugly stuff can happen. So, we can expand on that search pattern to select packages that are not automatically installed: aptitude search '!~M ~i'

The search feature is covered in some detail in Aptitude's reference manual.

Now, you have your list of packages to install. You can format the output as necessary by passing the -F flag to that command, like -F '%p' to get a list with just package names.


For example, you could run this on machine 1:

aptitude -F "%c %p" --disable-columns search '!~M ~i' | awk -F " " '{ print "apt-get -y install " $2 }' > aptshell.sh

Then copy the newly created aptshell.sh file over to machine 2 and and use this command on machine 2 to run it there:

sudo sh aptshell.sh

Then repeat the process, with the original machine 2 as the new machine 1, and the original machine 1 as the new machine 2. Now each machine has all the packages that were formerly only on the other.

Solution 2:

You could use puppet to create configuration files specifying which packages should be installed, and you could use Dropbox rather than a puppetmaster server to synchronise the puppet config between machines, plus a cron job to periodically run puppet and implement any config changes.

Solution 3:

This is an old question, but since no one has said it, you could possibly do something with dpkg and cron. Set up a cron job that does something clever with the get-selections and set-selections commands of dpkg.

dpkg --set-selections < ~/Dropbox/selections.dpkg


dpkg --get-selections > ~/Dropbox/selections.dpkg

This isn't a proposed solution, you'll have to work out some way to make sure that the selections.dpkg gets updated whenever you make a change on either computer...

Solution 4:

Ubuntu Software Center has a feature for syncing installed packages among multiple computers. It uses your Ubuntu One account for saving packages. Just select File > Sync Between Computers... and login with your Ubuntu One account.

Syncing packages with Ubuntu Software Center

Currently it has somehow limited functionality, for example it only supports default packages (not ppas), and you must manually select which packages to install (this can be seen as a positive feature tough). For detailed instructions, see this article.