PDA

View Full Version : HowTo: Create a list of installed packages


Cynical
September 20th, 2006, 06:28 AM
I found out how to do this recently and thought it might be helpful to some people. To output this information to a file in your home directory you would use,


dpkg --get-selections > installed-software


And if you wanted to use the list to reinstall this software on a fresh ubuntu setup,


dpkg --set-selections < installed-software


followed by


dselect

starscalling
September 21st, 2006, 02:48 AM
bump
damn this is smooth! good looking out!

stalefries
November 6th, 2006, 01:11 AM
Can anyone provide a list generated by this on a clean Edgy install? I'm trying to figure out what I've installed in the past, so I can remove things I no longere need.

xfile087
November 13th, 2006, 10:08 AM
I'm installing Edgy (x86) as we speak so once it's installed I will give you the list!

Included is a list of installed packages on a fresh install.

lo900
November 13th, 2006, 01:45 PM
many thnks

I was looking for this

bierpullen
November 13th, 2006, 02:04 PM
:D I was looking for this:D





------------------------------------------------------
http://www.antarctica-rbak.nl/ubuntu/acer_aspire.php
------------------------------------------------------

Henry Rayker
November 13th, 2006, 02:20 PM
huh. This would be really nice in diagnosing problems I've had.

stalefries
November 13th, 2006, 07:01 PM
Thank you so much!

qamelian
November 13th, 2006, 08:48 PM
You don't need a list of a clean install to get rid of unnecessary packages resulting from installing and uninstalling stuff. Just sudo apt-get autoremove and apt will generate a list of orphaned packages and give you the option to remove them.

nuclear_eclipse
December 19th, 2006, 02:40 PM
Is there an easy way to tell Ubuntu / dpkg to uninstall every package *except* what's listed in that output file? I'm trying to take an existing install, and remove all the unnecesary packages beyond a basic command line system, but I know of no easy way to do so.

But if I could use a package list from a different system, which is just a command line install, as a basis, and tell it to remove everything but that package list, that would be great.

stijn_pol
January 21st, 2007, 02:39 PM
nuclear_eclipse,
why don't you install Ubuntu server?

jdhore
January 21st, 2007, 03:30 PM
where does the output of the command in the first post (to backup) get put?

lukew
March 5th, 2007, 08:18 AM
where does the output of the command in the first post (to backup) get put?

The directory that you are in. To find this out type (present working directory)

~$ pwd

To put this into a dir called "install" within your home dir you could have
~$ dpkg --get-selections > ~/install/installed-software

ronzo
September 13th, 2007, 06:02 AM
#!/bin/bash

vsave=0
vrestore=0

function usage()
{
echo "USAGE:"
echo "$0 [-s] [-r] [-f installedpackages.txt]"
echo ""
echo "-s ... save installed packages"
echo "-r ... restore installed packages"
echo ""
echo "-f file.txt ... file where installed packages are saved"
echo " or from which installed packages are taken"
echo ""
exit 0;
}

while getopts ":srf:" options
do
case "$options" in
s) vsave=1 ;;
r) vrestore=1 ;;
f) file="$OPTARG" ;;
*) usage;;
esac
done

function doSave()
{
dpkg --get-selections > $file
}

function doRestore()
{
dpkg --set-selections < $file
}

if [ "$vsave" == "1" ] && [ "$vrestore" == "1" ] || [ "$file" == "" ]
then
usage
fi

if [ "$vsave" == "1" ] && [ "$file" != "" ]
then
doSave
fi

if [ "$vrestore" == "1" ] && [ "$file" != "" ]
then
doRestore
fi

chrome307
September 13th, 2007, 10:44 AM
The script didn't work for me (posted above) .... just opened up Archive Manager and that's it.:confused:

capink
September 14th, 2007, 07:08 PM
Is there an easy way to tell Ubuntu / dpkg to uninstall every package *except* what's listed in that output file? I'm trying to take an existing install, and remove all the unnecesary packages beyond a basic command line system, but I know of no easy way to do so.

But if I could use a package list from a different system, which is just a command line install, as a basis, and tell it to remove everything but that package list, that would be great.

Have a look here (http://ubuntuforums.org/showthread.php?t=442974). It might help you.

takuhii
October 19th, 2007, 05:02 AM
Could someone post a CLEAN Gutsy Install list??

inportb
October 24th, 2007, 11:49 PM
This might be helpful if you want to uninstall everything except what's listed in your output file: http://www.inportb.com/wp/index.php/2007/10/24/how-to-save-a-list-of-installed-packages-and-reinstall-the-packages-later/

Evil Dax
October 30th, 2007, 03:02 PM
This is good, it just saved me 1/2 a day of boring work.
Thanks !! :popcorn:

benow
November 12th, 2007, 02:41 PM
cat toremove | xargs --replace=+ sudo apt-get -y remove +

rouge568
March 27th, 2008, 09:57 PM
Thank you very much for this. You have no idea how much time this just saved me.

sigdrifa
March 28th, 2008, 11:44 AM
Great time saver :)
Except one problem for me:
On "dselect" I got "command not found". That was on a fresh Kubuntu Gutsy install.
What worked, however, was to load the file into Synaptic.

whein
April 7th, 2008, 04:39 PM
cat toremove | xargs --replace=+ sudo apt-get -y remove +

Just curious, what does the above code do?
-Will

lennyleonard
April 13th, 2008, 05:03 PM
That's exactly the thing I've been looking for. Thank you very much!

unutbu
April 13th, 2008, 05:25 PM
Just curious, what does the above code do?
-Will


cat toremove | xargs --replace=+ sudo apt-get -y remove +

Short answer:
It removes all packages listed in 'toremove'.
man cat
man xargs
man apt-get


Long answer:
'toremove' is a file with all the packages you wish to remove listed, one package per line. 'cat' lists them all and the pipe '|' pumps the list into 'xargs'. 'xargs' runs 'sudo apt-get -y remove +' where '+' is replaced with the name of a package. 'xargs' runs it once for each package. Cool, eh?

Jad
April 20th, 2008, 02:10 PM
Any idea how to list installed packages from the official ubuntu repository not any other repository, source install or manually downloaded deb package.

unutbu
April 20th, 2008, 05:27 PM
I am not aware of any apt-* or dpkg command that will definitely indicate the repository from which a package came.
I did notice, however, a certain pattern which seems to suggest when a package comes from some source other than an official repo:


17:18:56 cyrano@farmer:~% apt-cache policy acroread
acroread:
Installed: 8.1.2-0medibuntu1
Candidate: 8.1.2-0medibuntu1
Version table:
*** 8.1.2-0medibuntu1 0
100 /var/lib/dpkg/status
17:19:07 cyrano@farmer:~% apt-cache policy gnome-panel
gnome-panel:
Installed: 1:2.20.1-0ubuntu1
Candidate: 1:2.20.1-0ubuntu1
Version table:
*** 1:2.20.1-0ubuntu1 0
500 http://archive.ubuntu.com gutsy-updates/main Packages
100 /var/lib/dpkg/status
1:2.20.0.1-0ubuntu6 0
500 http://archive.ubuntu.com gutsy/main Packages


The packages from the official repos seem to report
http://archive.ubuntu.com while all other packages seem to report /var/lib/dpkg/status.

Based on this pattern, I wrote this perl script which lists packages which are installed on the system grouped according to the repo:

#!/usr/bin/perl
use strict;
use warnings;

my @pkg;
open(PACKAGES,"COLUMNS=500 dpkg -l |") || die;
while (<PACKAGES>) {
if (m/^ii/) {
my ($pkg)=($_=~m/^ii\s+(\S+)\s+/);
push(@pkg,$pkg)
}
}
close(PACKAGES);

my %dat;
foreach my $pkg (@pkg) {
open(APT,"apt-cache policy $pkg |") || die;
my $in_version_section=0;
while (my $line=<APT>) {
if ($line=~m/^\s*Installed: (.*)/) {
($dat{$pkg}->{version})=($line=~m/^\s*Installed: (.*)/);
} elsif ((!$in_version_section)&&(defined($dat{$pkg}->{version})) && ($line=~m/^\s+\S{3}\s+\S+/)) {
my ($a_version)=($line=~m/^\s+\S{3}\s+(\S+)/);
if ($a_version eq $dat{$pkg}->{version}) {
$in_version_section=1;
next;
}
} elsif (($in_version_section) && ($line=~m/^\s+\d+\s+\S+/)) {
($dat{$pkg}->{repo})=($line=~m/^\s+\d+\s+(\S+)/);
last;
}
}
close(APT);
}

my %repo;

foreach my $pkg (keys %dat) {
my $version=$dat{$pkg}->{version};
my $repo=$dat{$pkg}->{repo};
push(@{$repo{$repo}},"$pkg version $version");
}

foreach my $repo (keys %repo) {
print "$repo:\n";
foreach (@{$repo{$repo}}) {
print " $_\n";
}
}

danielv42
May 5th, 2008, 11:33 PM
I wanted a list of packages with their descriptions, so I used:

dpkg -l | grep '^[D|+i]' >> installed_dpkg_l.txt

davidshere
May 12th, 2008, 10:23 AM
Here is a complete list from a fresh minimal Hardy server i386 install:

adduser install
apparmor install
apparmor-utils install
apt install
apt-utils install
aptitude install
at install
base-files install
base-passwd install
bash install
bash-completion install
belocs-locales-bin install
bind9-host install
bsdmainutils install
bsdutils install
busybox-initramfs install
bzip2 install
command-not-found install
command-not-found-data install
console-setup install
console-terminus install
console-tools install
coreutils install
cpio install
cpp install
cpp-4.2 install
cron install
dash install
debconf install
debconf-i18n install
debianutils install
dhcp3-client install
dhcp3-common install
diff install
dmidecode install
dnsutils install
dosfstools install
dpkg install
e2fslibs install
e2fsprogs install
ed install
eject install
ethtool install
fdutils install
file install
findutils install
friendly-recovery install
ftp install
fuse-utils install
gcc-4.2-base install
gettext-base install
gnupg install
gpgv install
grep install
groff-base install
grub install
gzip install
hdparm install
hostname install
ifupdown install
info install
initramfs-tools install
initscripts install
inputattach install
installation-report install
iproute install
iptables install
iputils-arping install
iputils-ping install
iputils-tracepath install
klibc-utils install
klogd install
laptop-detect install
less install
libacl1 install
libatm1 install
libattr1 install
libbind9-30 install
libblkid1 install
libbz2-1.0 install
libc6 install
libc6-i686 install
libcap1 install
libcomerr2 install
libconsole install
libcurl3-gnutls install
libcwidget3 install
libdb4.6 install
libdbus-1-3 install
libdevmapper1.02.1 install
libdns32 install
libedit2 install
libelfg0 install
libexpat1 install
libfribidi0 install
libfuse2 install
libgc1c2 install
libgcc1 install
libgcrypt11 install
libgdbm3 install
libgnutls13 install
libgpg-error0 install
libgpmg1 install
libhtml-parser-perl install
libhtml-tagset-perl install
libhtml-tree-perl install
libidn11 install
libisc32 install
libisccc30 install
libisccfg30 install
libiw29 install
libkeyutils1 install
libklibc install
libkrb53 install
libldap-2.4-2 install
liblocale-gettext-perl install
liblwres30 install
liblzo2-2 install
libmagic1 install
libncurses5 install
libncursesw5 install
libnewt0.52 install
libntfs-3g23 install
libopencdk10 install
libpam-modules install
libpam-runtime install
libpam0g install
libparted1.7-1 install
libpcap0.8 install
libpopt0 install
libreadline5 install
librpc-xml-perl install
libsasl2-2 install
libsasl2-modules install
libselinux1 install
libsepol1 install
libsigc++-2.0-0c2a install
libslang2 install
libsqlite3-0 install
libss2 install
libssl0.9.8 install
libstdc++6 install
libsysfs2 install
libtasn1-3 install
libterm-readkey-perl install
libtext-charwidth-perl install
libtext-iconv-perl install
libtext-wrapi18n-perl install
liburi-perl install
libusb-0.1-4 install
libuuid1 install
libvolume-id0 install
libwrap0 install
libwww-perl install
libxml-parser-perl install
linux-image-2.6.24-16-server install
linux-image-server install
linux-server install
linux-ubuntu-modules-2.6.24-16-server install
locales install
login install
logrotate install
lsb-base install
lsb-release install
lshw install
lsof install
ltrace install
lzma install
makedev install
man-db install
manpages install
mawk install
memtest86+ install
mii-diag install
mime-support install
mktemp install
mlocate install
module-init-tools install
mount install
mtr-tiny install
nano install
ncurses-base install
ncurses-bin install
net-tools install
netbase install
netcat install
netcat-traditional install
ntfs-3g install
ntpdate install
openssh-client install
parted install
passwd install
pciutils install
pcmciautils install
perl install
perl-base install
perl-modules install
popularity-contest install
ppp install
pppconfig install
pppoeconf install
procps install
psmisc install
python install
python-apt install
python-central install
python-gdbm install
python-gnupginterface install
python-minimal install
python-support install
python2.5 install
python2.5-minimal install
readline-common install
reiserfsprogs install
rsync install
sed install
startup-tasks install
strace install
sudo install
sysklogd install
system-services install
sysv-rc install
sysvutils install
tar install
tasksel install
tasksel-data install
tcpd install
tcpdump install
telnet install
time install
tzdata install
ubuntu-keyring install
ubuntu-minimal install
ubuntu-standard install
ucf install
udev install
ufw install
update-inetd install
update-manager-core install
upstart install
upstart-compat-sysv install
upstart-logd install
usbutils install
util-linux install
util-linux-locales install
uuid-runtime install
vim-common install
vim-tiny install
w3m install
wget install
whiptail install
wireless-tools install
wpasupplicant install
xkb-data install
zlib1g install

simon_w
May 20th, 2008, 02:46 AM
Any idea how to list installed packages from the official ubuntu repository not any other repository, source install or manually downloaded deb package.

Appreciate that this is four weeks after your post, but since no-one else has yet made a suggestion, how about temporarily editing your sources.list file to only the official repositories (or whatever you're interested in) and then running: aptitude search . | grep ^i??

Think that should do it...?

Simon

abhiroopb
June 10th, 2008, 04:13 PM
My question:

I have installed programs through apt, as deb packages and used checkinstall. So all my programs are listed in synaptic and when I create the list using the original command.

However, what I would like to know is when I try to re-install everything will the programs that are NOT in the official repos install? What will happen say for the program avast4workstation? It is listed in the dpkg list but I downloaded it as a separate .deb file from avast.

Thanks in advance!

unutbu
June 10th, 2008, 04:34 PM
I think the reinstall would fail because dpkg would not know where the .deb files are (checkinstall just puts the .debs it creates in the current working directory, no place special where dpkg would find it. `dpkg -i` only installs the deb; it does not copy the deb to /var/cache/apt/archives as far as I know.)

However, I could be wrong, and there is an easy way for you to discover the answer. (Please tell us when you do).

Make a file with contents like this:

avast4workstation install

Save it as "installed-software".
Then run

dpkg --set-selections < installed-software
dselect

abhiroopb
June 10th, 2008, 04:51 PM
Just to test i uninstalled avast, and brasero.

I then added the following to the file "installed-software":


avast4workstation install
brasero install


I then ran dpkg, and dselect (with sudo).

When it opened up the prompt for dselect I choose 3 (install and upgrade wanted packages).

The following was the output (neither brasero NOR avast installed):


abhiroop@Vanimo:~$ sudo dpkg --set-selections < installed-software
abhiroop@Vanimo:~$ sudo dselect
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
nvidia-glx* virtualbox-ose-modules-2.6.22-14-generic*
The following NEW packages will be installed:
brasero
0 upgraded, 1 newly installed, 2 to remove and 0 not upgraded.
Need to get 1363kB of archives.
After unpacking 5181kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://archive.ubuntu.com gutsy-backports/main brasero 0.7.1-1~gutsy1 [1363kB]
Fetched 1363kB in 16s (82.8kB/s)
(Reading database ... 134148 files and directories currently installed.)
Removing nvidia-glx ...
Purging configuration files for nvidia-glx ...
dpkg-divert: mismatch on package
when removing `diversion of /usr/lib/libGL.so.1 to /usr/lib/nvidia/libGL.so.1.xlibmesa by nvidia-glx'
found `diversion of /usr/lib/libGL.so.1 to /usr/lib/nvidia/libGL.so.1.xlibmesa by nvidia-glx-new'
dpkg: error processing nvidia-glx (--purge):
subprocess post-removal script returned error exit status 2
Removing virtualbox-ose-modules-2.6.22-14-generic ...
Purging configuration files for virtualbox-ose-modules-2.6.22-14-generic ...
update-rc.d: /etc/init.d/vboxdrv exists during rc.d purge (use -f to force)
dpkg: error processing virtualbox-ose-modules-2.6.22-14-generic (--purge):
subprocess post-removal script returned error exit status 1
Errors were encountered while processing:
nvidia-glx
virtualbox-ose-modules-2.6.22-14-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
Some errors occurred while unpacking. I'm going to configure the
packages that were installed. This may result in duplicate errors
or errors caused by missing dependencies. This is OK, only the errors
above this message are important. Please fix them and run [I]nstall again
Press enter to continue.


It seems nvidia-glx, and virtualbox are giving problems. But I don't know what to do. I use nvidia-glx-new (I think), and NOT the OSE version of virtualbox. Whats happening?

unutbu
June 10th, 2008, 09:22 PM
Let's try to fix things:

sudo apt-get update # update the list of packages available
sudo apt-get -f install # correct broken dependencies

sudo apt-get install nvidia-glx-new # try to reinstall nvidia-glx-new
sudo apt-get install brasero
sudo apt-get purge virtualbox-ose-modules-2.6.22-14-generic

avast4workstation is not in the official repos, so you'll need the deb to reinstall this on.

abhiroopb
June 11th, 2008, 03:02 AM
All that worked, but it didn't take away the problem of using dselect. I think there is stills some prooblem with the two packages. So I deleted them and completely re-installed it all. Now it seems to ok. Anyway I guess to install packages not in repos you can take a look at something I discovered:

http://ubuntuforums.org/showthread.php?t=819396

nooblot
July 6th, 2008, 02:47 PM
how about just "apt-show-versions" ?

jnk0906
July 25th, 2008, 09:17 PM
The output file is formatted with package try per line, so manipulating the file is easy. Once you have the files from the initial and current states, you can run a text-file comparison between the two files to determine which lines are different. Alternately, you can import them into a simply database and run standard SQL queries to identify the new files. If you need to make these changes often then you might want to keep an updated database. SQLite might work well for this as you can store it anywhere. You can simply take the extra package names and append them to the "sudo apt-get remove [packageName1] [packageName2]" command. You may also want to run "sudo apt-get autoremove" afterward to remove the orphans that were previously installed as dependencies.

UPDATE: Sorry, this was in response to post number 10, but that was really old.

xak
October 14th, 2008, 03:26 PM
I've written a small script that I run to record my installed packages. Hopefully someone else will find it useful as well.

It only outputs the core packages, not their dependencies. I believe this is important as dependencies may change between distributions, and you don't want to be installing unnecessary packages.

The script uses deborphan and will automatically install it if you so desire ;-)

Bonus: I have this executing in my ~/.gnomerc file and outputting to a file in my homedir, so I always have an up-to-date list of packages every time my machine boots up. I'd rather have it record them on logout, however I don't want it placed in an init.d script or GDM (I want something user-specific). If anyone else knows how to get gnome to execute a script on logout, please share!

The core command my script uses is:
deborphan --all-packages --no-show-section | egrep --invert-match "linux-.*|.*ubuntu-(server|desktop|minimal|standard)"

The only downfall is it doesn't seem to list packages installed from 3rd party repositories (I have wine installed and it does not output the wine package on my system). Not sure why this is and I'd love to have it show these packages too...

And here is the whole script:
#!/bin/bash
# record manually-installed packages using deborphan
# (will install deborphan using aptitude if not installed)
#
# by Zach [xak .:at:. xak.us]


QUIET=no
if [ "$1" == "-y" ]; then
QUIET=yes
elif [ "$1" == "--help" ]; then
echo "Usage: $0 [-y]"
echo "-y indicates quiet and auto-install deborphan if necessary"
echo ""
echo "Prints installed debian packages, excluding their depenencies and base system packages"
exit -1
fi


if [ `which deborphan >/dev/null 2>&1 ; echo $?` == 0 ]; then
deborphan --all-packages --no-show-section | egrep --invert-match "linux-.*|.*ubuntu-(server|desktop|minimal|standard)"

else
if [ $QUIET == "no" ]; then
echo -n "deborphan not installed. install now? (yes/no) "
read q
fi
if [ $QUIET == "yes" ] || [ "$q" == "y" ] || [ "$q" == "Y" ] || [ "$q" == "yes" ] || [ "$q" == "Yes" ] || [ "$q" == "YES" ]; then
if [ $QUIET == "no" ]; then echo "" && echo "installing..."; fi
sudo aptitude install deborphan >/dev/null 2>&1
if [ $? == 1 ]; then
if [ $QUIET == "no" ]; then echo "install failed!"; fi
exit 2
else
if [ $QUIET == "no" ]; then echo "install succeeded"; fi
$0
fi
else
echo "cannot proceed without deborphan"
exit 1
fi
fi

Cheers!

:guitar:

simon_w
October 14th, 2008, 09:50 PM
Hey xak,

Thanks for the script. However, I think there may be a flaw in the logic here. See below.

First, I think your main command should look like this:

deborphan --all-packages --no-show-section --nice-mode | egrep -v "linux-.*|.*ubuntu-(server|desktop|minimal|standard)" | sort

1) standard practice is to use long-form options in scripts ('cos short-forms may be subject to change in the future)

2) adding --no-show-section removes the need for the pipe to awk (and the sort should go after the awk, but that doesn't matter if you do it this way)

3) you need parentheses "()" not brackets "[]" around 'server|desktop|..." etc. Using brackets in a regexp is interpreted as a character class, with the result that any of the characters inside are matched once and once only (including the pipe). The problem here is that it means that your regexp matches, e.g., 'ubuntu-restricted-extras', which is not a default package and so should not be excluded from this list, if I understand the logic).

try adding --color=auto to see what I mean
deborphan -a | egrep --color=auto ".*ubuntu-[server|desktop|minimal|standard]"
deborphan -a | egrep --color=auto ".*ubuntu-(server|desktop|minimal|standard)"

4) The reason why wine doesn't show up on your list is not because it's from a third-party repository. Deborphan will not report a package if you have another installed which depends on it, but, by default, it will also pass over a package if you have another installed which merely 'suggests' or 'recommends' it. (In the case of wine, it is 'suggested' by gnome-volume-manager. Go figure!). You should disable this feature of deborphan (using --nice-mode).

However, there is still a problem here: circular dependencies. Some packages depend on each other, and will therefore not make it onto this list using deborphan, no matter what you do. A quick example: I mainly use Gnome-based Ubuntu, but I usually install Amarok. The package amarok depends on amarok-xine, and amarok-xine depends on amarok, so it won't appear on this list. Thunderbird is another example from my system.

So although I thinks it's a smart idea to use deborphan in this way, I would urge caution.

Oh - and to execute a script on Gnome logout, call it from /etc/gdm/PostSession/Default.

Hope that helps - thanks for the idea!

Simon

xak
October 15th, 2008, 01:07 AM
1) standard practice is to use long-form options in scripts ('cos short-forms may be subject to change in the future)

2) adding --no-show-section removes the need for the pipe to awk (and the sort should go after the awk, but that doesn't matter if you do it this way)


I agree on long-form parameter names. The sort was to sort the list by package types, not on package names. I am a bit quirky sometimes in how I do things, but this was intentional ;-)

3) you need parentheses "()" not brackets "[]" around 'server|desktop|..." etc. Using brackets in a regexp is interpreted as a character class, with the result that any of the characters inside are matched once and once only (including the pipe). The problem here is that it means that your regexp matches, e.g., 'ubuntu-restricted-extras', which is not a default package and so should not be excluded from this list, if I understand the logic).


Good catch here as well! I will update the script.

4) The reason why wine doesn't show up on your list is not because it's from a third-party repository. Deborphan will not report a package if you have another installed which depends on it, but, by default, it will also pass over a package if you have another installed which merely 'suggests' or 'recommends' it. (In the case of wine, it is 'suggested' by gnome-volume-manager. Go figure!). You should disable this feature of deborphan (using --nice-mode).

However, there is still a problem here: circular dependencies. Some packages depend on each other, and will therefore not make it onto this list using deborphan, no matter what you do. A quick example: I mainly use Gnome-based Ubuntu, but I usually install Amarok. The package amarok depends on amarok-xine, and amarok-xine depends on amarok, so it won't appear on this list. Thunderbird is another example from my system.

So although I thinks it's a smart idea to use deborphan in this way, I would urge caution.


Well this just means my goal is set back a little. There must be a way to accomplish creating this list of packages. Any other ideas? Do you think the best way might be to diff the full installed-package list against a default distro package installation list? What about dependencies?


Oh - and to execute a script on Gnome logout, call it from /etc/gdm/PostSession/Default.


I'm aware of this as well, but I wanted a user-specific way of accomplishing this, like ~/.gnomerc, without modifying the system. The best ideas I have come up with so far are a script launched by .gnomerc or a session which waits for the gnome processes to die (very ugly approach), or sourcing a user's file such as ~/.gnome-logout from PostSession/Default (but this requires system modification).


Thanks a bunch for your comments and suggestions!

dazzlindonna
November 2nd, 2008, 09:16 AM
Quick newb question: When I run the first command, it creates the nice list, but next to each item is either the word "install" or a few say "deinstall". Why would a few of them say "deinstall"?

unutbu
November 2nd, 2008, 10:13 AM
The packages that say "deinstall" are those that were installed on your system at one point, but have since been removed.

rylangrayston
November 11th, 2008, 10:41 AM
thanks this is great
very smooth

loomsen
November 22nd, 2008, 08:08 PM
I agree on long-form parameter names. The sort was to sort the list by package types, not on package names. I am a bit quirky sometimes in how I do things, but this was intentional ;-)


##### SNIP ####
Thanks a bunch for your comments and suggestions!

OK, I gotta admit I only stumbled upon this thread and read a few keywords which made me think... You might want to take a look at
www.instalinux.com

It will generate a minimal installation image of a distro you'd like, basically a netinst.

I made a debian as well as a Intrepid for myself, and I have to say this is exactly what I've been looking for ever since. A basic yet minimalistic gnome-desktop, almost any apps were installed(no evolution, no firefox, no instant-messenger, basically really nothing)

The other way round compared to deborphan, but at least as much fun (in fact, it's even more fun than continuosly uninstalling pkges, imho)

Anyway, so, if you have the feeling your dist is getting somewhat bloated again, this way at least it was your fault :D

No, honestly, give it a try, it's great, I always wondered why ubuntu wouldn't provide sth like that. Even the debian netinstaller is too bloated imho, 135mb one could as get from the internet.

However, takes bout 2 mins to make your selection, and another minute to create your 10MB sized iso.

Have fun.


2nd)

Script to be run at shutdown:

Either you could make it a PostSession Script, here:
docter[~] locate Post | grep -i sessi
/etc/gdm/PostSession
/etc/gdm/PostSession/Default


Or, what I prefer, have a crontab doin it.

man cron

for crontab reference.

CoolDreamZ
February 14th, 2009, 05:21 AM
Very useful, thanks! If you want to see what versions of the packages you have installed try:

dpkg-query -l

simon_w
February 14th, 2009, 08:07 AM
@loomsen - I very much share your sentiment, I like to do things this way too. I prefer to build up from the minimal CD though https://help.ubuntu.com/community/Installation/MinimalCD, and install packages myself from there.

ruru
March 14th, 2009, 10:00 AM
Is there also a neat trick to dump a list of repositories and reload this in a fresh install? I use several 3rd-party repos so reinstalling my package list will throw errors...

unutbu
March 14th, 2009, 10:23 AM
ruru, if you save your /etc/apt directory to a USB flash drive, then do a fresh install, then copy the /etc/apt directory from the flash drive to the root partition of the fresh install, then you should be good to go.

Edit: You may need to open a terminal (Applications>Accessories>Terminal) and run

sudo apt-get update
to make the fresh install aware of the packages available).

ugm6hr
March 14th, 2009, 10:26 AM
ruru, if you save your /etc/apt directory to a USB flash drive, then do a fresh install, then copy the /etc/apt directory from the flash drive to the root partition of the fresh install, then you should be good to go.

Or even just your /etc/apt/sources.list file.

If you upgrade, you will obviously have to change all hardy references to intrepid etc.

unutbu
March 14th, 2009, 10:31 AM
ugm6hr, yes you are probably right :)

However, depending on the way the third-party repos are enabled, the necessary files might be located in /etc/apt/sources.list.d, rather than in sources.list. And then there are also the GPG keys stored in /etc/apt/trustdb.gpg... So, I figured what the heck, just save the entire /etc/apt directory ... :)

ugm6hr
March 14th, 2009, 10:37 AM
And then there are also the GPG keys stored in /etc/apt/trustdb.gpg... So, I figured what the heck, just save the entire /etc/apt directory ... :)

Good point.

I'd forgotten that.

ruru
March 14th, 2009, 10:48 AM
I had just saved /etc/apt/sources.list and was going to post this, but the point about the keys hadn't occurred to me either - so thanks for that!

cirorodrigues
March 24th, 2009, 01:00 PM
Hi. Two questions:
1) Does it work if any of applications was installed from a deb package downloaded directly to disk?
2) Do I need to setup any alternative repository before try reinstall ?

anyway, that's indeed a very interesting hack. Thanks.

cirorodrigues
March 24th, 2009, 01:17 PM
forget about this. I didn't read all the posts before this one...

noukist
March 26th, 2009, 06:39 AM
thanks man ;)

:fish: :fish:

loomsen
March 27th, 2009, 09:11 AM
And then there are also the GPG keys stored in /etc/apt/trustdb.gpg.

Actually, you should save your keyring rather than the database, due to the same reason your sources.list gets updatet with a new release.

Your reimportable keyring is
/etc/apt/trusted.gpg

apt-key add <path-to-backed-up>/trusted.gpg


and you're fine after a new release or whatever.

You could make a symlink for instance so you won't miss is when backin up...



@simon: me too in the meanwhile. Bootstrapping from a running system into a chroot is very nice too imho.

mfyahya
June 14th, 2009, 11:21 PM
This bash snippet will download the .deb package files for all installed packages on your system. Useful if you've deleted them from /var/cache/apt/archives/ with `apt-get clean` and if you want the package files for any reason.


dpkg --get-selections | awk '{ print $1};' | while read package; do apt-cache show "$package"| wget -c 'http://ae.archive.ubuntu.com/ubuntu/'`sed -ne '/^Filename/s/^Filename: //p'`; done

cw8jw
August 19th, 2009, 12:08 PM
Can this be done to show installed version levels, instead of just package names?

Thanx!

unutbu
August 19th, 2009, 12:22 PM
cw8jw, open a terminal (Applications>Accessories>Terminal) and type
aptitude -F '%?p %?V' search '~i'

You'll see output like this:

a2ps 1:4.14-1
acl 2.2.47-2
acpi 1.1-1ubuntu1
acpi-support 0.114-0intrepid2
...

fallingleaf
October 14th, 2009, 06:09 PM
I used this method to transfer all my installed apps over when I did a clean install of Karmic. The problem is that it also installs all the old kernels you might have installed and other system stuff that might not be compatible. The worst thing was that it installed grub 1 and uninstalled grub 2 so that a later kernel update failed because it was trying to update menu.lst which no longer exists in grub 2. It would be nice if there were an easy way to just reinstall apps and leave system stuff alone.

davidshere
December 3rd, 2009, 11:07 AM
Great time saver :)
Except one problem for me:
On "dselect" I got "command not found".
Same problem here on fresh install of 8.04.2. Instead, run:
david@bearcat:~$ sudo dselect
and you'll get:
The program 'dselect' is currently not installed. You can install it by typing:
sudo apt-get install dselect
So type that and you'll get
david@bearcat:~$ sudo apt-get install dselect
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
dselect
0 upgraded, 1 newly installed, 0 to remove and 236 not upgraded.
Need to get 405kB of archives.
After this operation, 2228kB of additional disk space will be used.
Get:1 http://.... hardy-updates/main dselect 1.14.16.6ubuntu4 [405kB]
Fetched 405kB in 3s (133kB/s)
(Reading database ... 95977 files and directories currently installed.)
Unpacking dselect (from .../dselect_1.14.16.6ubuntu4_i386.deb) ...
Setting up dselect (1.14.16.6ubuntu4) ...

The Real Dave
December 20th, 2009, 12:12 PM
Thank you OP! :D

bobarry
February 14th, 2010, 03:49 PM
I found out how to do this recently and thought it might be helpful to some people. To output this information to a file in your home directory you would use,


dpkg --get-selections > installed-software


And if you wanted to use the list to reinstall this software on a fresh ubuntu setup,


dpkg --set-selections < installed-software


followed by


dselect

Great trick. However I did it recently and I had to add the dselect program before it would work. It now has some options to pick from, but the default works fine.
You have to use sudo dselect.

Many Thanks
Bo Barry

Redsandro
April 30th, 2010, 09:00 AM
What do you need dselect for? According to this (http://savvyadmin.com/backup-and-restore-package-lists-in-ubuntu/), you can just type:
sudo dpkg install

eroeurbano
June 5th, 2010, 11:48 AM
Hi all,
I've installed Ubuntu 10.04 on two machine (work and home).
I finally could get to solve an issue I had with migrating
a drupal website by installing a few packages related to
php apache2 and mysql, on my home computer.

I now would like to get a list of the packages I've installed
related to these three softwares and install them also on my work
computer to install them and finally fix the problem there as well.

I'm very new to Ubuntu so I don't know if this an easy or silly task
(if so I'm sorry for the question).

Thanks to all in advance,
Cheers -Luca

cmcanulty
June 7th, 2010, 11:59 AM
dpkg --get-selections > installed-software
gives me nothing and I did run deselect first

Axilus
June 19th, 2010, 12:10 PM
After accidentally nuking my laptop this thread has been very helpful.

cmcanulty
June 19th, 2010, 12:15 PM
I thought mine was not working at all, not knowing that it doesn't show up in terminal but as a text file in your home folder.

JoelKrause
June 20th, 2010, 09:04 AM
This is really cool. Thanks.

kdford
July 13th, 2010, 09:34 PM
I know this is OLD, but can't you just sort the KNOWN fresh install package list, plus your package list (that has all your installed packages), and remove from your list of all installed packages, those that are IN the fresh install package list? That would leave you with the list of packages your CURRENT installation has, that are NOT part of the base install. You can then pipe that file into -remove or -purge. In theory it will work.

I started messing around with it, and thought of using sort and uniq but one issue with that is that if you have REMOVED a package that was in the fresh install, it could end up in your remove_these_packages.txt file. So.. If you had something like this...


ini-list.txt
packageA
packageB
packageD
packageC

cur-list.txt
packageB
packageD
packageC
packageE
package22

You could prefix them, using sed, so that they look like this

sed 's/^/cur-list-/' cur-list.txt
sed 's/^/ini-list-/' ini-list.txt

ini-list.txt
ini-list-packageA
ini-list-packageB
ini-list-packageD
ini-list-packageC

cur-list.txt
cur-list-packageB
cur-list-packageD
cur-list-packageC
cur-list-packageE
cur-list-package22Then, you could simply combine them together, like...

cat ini-list.txt cur-list.txt > ful-list.txtand use uniq with the -u switch to show only things that are NOT duplicated, like this...

uniq -u -s 9 ful-list.txt > difference_packages.txt(the -s 9 option tells uniq to IGNORE the first 9 characters when testing for uniqueness. This is necessary because you want to compare package names, but you have prefixed your package lines with text that you will later use to determine the origin of the package). This will remove all packages that you CURRENTLY have that are also in the initial (fresh) install. It will also leave you with packages that are in the fresh install that you do NOT have (if any)... Because you added the prefixes, you can now simply grep the file twice, once looking for cur-list- and again looking for ini-list-, and pipe the grep results into awk to remove the prefix. Then you will have two files, one is the packages you need to remove, the other is the packages that you need to install (if any)

You can remove these prefixes in a number of ways but sed would do the trick, like this...


cat difference_packages.txt | grep ini-list- | sed '9s/^.//' > to_install.txt
cat difference_packages.txt | grep cur-list- | sed '9s/^.//' > to_delete.txt
I have not tested any of that code, it is just from memory but you can work out the kinks if nicessary, I'm sure.

Hope that helps/makes sense.

Kevin

Redsandro
July 22nd, 2010, 11:34 AM
I haven't checked it but it sounds awesome. You are pretty terminal savvy. It would be greatly appreciated if you can put that in a script that makes the list.

cmuxed
August 3rd, 2010, 08:13 AM
This is great for when your system is running, however what if you don't have an up to date list of the installed applications on a system that has crashed beyond [my ability to] repair? I can access the file system drive of my old system but cannot boot it, does anyone know how I can get a list of the applications I had installed on that machine? Where is this information stored... some file or db somewhere?

Redsandro
August 3rd, 2010, 10:26 AM
[..] but can't you just sort the KNOWN fresh install package list [..]

Does anyone know where one would get a list of initial packages kdford calls ini-list.txt in the example, without reinstalling Ubuntu? Is it specified somewhere?

-edit-

@cmuxed

I'm not sure, but have you tried looking in
/var/lib/apt/lists/
and
/var/lib/dpkg/status

If you find the best reference of a list on a broken system, let us know. :)

cmuxed
August 5th, 2010, 03:42 AM
Ill take a look. Thanks

cmuxed
August 5th, 2010, 04:01 AM
@Redsandro,

I took a look in the /var/lib/apt/lists/ as you suggested and there are a lot of text files there what looks to be tracking the changes made with apt, lots of info! More than I need at this point in time but useful nevertheless, so I ran the following command to get a list just of their package names:

@%mypc%:~$ cat /media/%mounteddisk%/var/lib/apt/lists/*Packages* | grep "Package:" > /home/%myusername%/Desktop/oldpackages.txt

I got a nice list of all the packages I had installed!! Awesome. Thanks for the suggestion.

Redsandro
August 5th, 2010, 07:00 AM
Note that I don't exactly know what's in there, so maybe those packages that are downloaded but not installed or waiting to be removed are also mentioned in there.

I think the second 'link' has more info about installed or not, but it has a lot of other information you don't need so it would need some grepping through the data.

If the information you acquired from /var/lib/apt/lists/ is correct, I'm glad I could help nonetheless. :) Thanks for the command line. Let me quote it for future reference, might come in handy. :)
cat /media/%mounteddisk%/var/lib/apt/lists/*Packages* | grep "Package:" > /home/%myusername%/Desktop/oldpackages.txt

cmuxed
August 6th, 2010, 05:00 AM
@Redsandro

maybe those packages that are downloaded but not installed or waiting to be removed are also mentioned in there.

Yeah, you are right, the second 'link' does include the status of each package; installed or removed etc. I have modified my command to slightly increase the verbosity of the grep filter, which suits my cause for now. I don't intend to re-bloat my new installation with all the apps I had shoved into the old box, so will use this data as a guide and format as necessary.

Code as follows will show all packages installed or removed:

cat /media/%mounteddisk%/var/lib/apt/lists/*Packages* | grep -A 1 "Package:" > /home/%myusername%/Desktop/AllOldpackages.txtCode for just the installed packages:

cat /media/%mounteddisk%/var/lib/apt/lists/*Packages* | grep -B 1 "Status: install ok installed" > /home/%myusername%/Desktop/OldInstalledPackages.txtObviously don't use my crap file names!

Cheers

Redsandro
August 6th, 2010, 08:39 AM
@Redsandro
cat /media/%mounteddisk%/var/lib/apt/lists/*Packages* | grep -B 1 "Status: install ok installed" > /home/%myusername%/Desktop/OldInstalledPackages.txtObviously don't use my crap file names!

Cheers

So easy? :o

When I had to do something similar on some text, I actually wrote a PHP script to do regular expressions because apparently there was a flaw in my logic. :p

Thanks.

cmuxed
August 7th, 2010, 11:00 PM
@Redsandro

No probs mate. Thanks again for the lead, hopefully others will find this useful too. :D

borislavsabev
August 12th, 2010, 06:02 AM
I was looking for this!Thanks.

purplegirl5
August 12th, 2010, 07:40 AM
Just what I needed. Thanks.;)

cry8wolf9
September 8th, 2010, 05:13 PM
ok im trying to use a list i made to reinstall a bunch of packages but every time i use
dpkg --set-selections < ubuntu-files
i get this error

dpkg: operation requires read/write access to dpkg status area


also note it is not a fresh install i just want to reinstall some things

fallingleaf
September 8th, 2010, 05:41 PM
ok im trying to use a list i made to reinstall a bunch of packages but every time i use
dpkg --set-selections < ubuntu-files
i get this error

dpkg: operation requires read/write access to dpkg status area


also note it is not a fresh install i just want to reinstall some things

Need sudo for that command.

cry8wolf9
September 8th, 2010, 05:52 PM
ok that didnt do what i wanted is there a command that reinstalls already installed packages?

ramnarayan
November 19th, 2010, 03:10 AM
Thanks

was looking for this to migrate from 9.10 to 10.10
had such a smooth stable system that am reluctant to move but feel the Ubuntu fever for a new version :-)

ram

Redsandro
January 1st, 2011, 10:03 AM
Just as a note,

Some distro's cannot automatically get dselect (like Lubuntu)
apt-get install dselect
package dselect not found

You can download the .deb package from here:
http://packages.debian.org/sid/dselect

Scroll down and pick the right platform. Get a link and you can simply do e.g.:
wget http://ftp.de.debian.org/debian/pool/main/d/dpkg/dselect_1.15.8.7_i386.deb
dpkg -i dselect_1.15.8.7_i386.deb

(all as root)

sajansen
February 13th, 2011, 11:56 AM
i was wondering is tare a command that lists all installed packages except the standard ubuntu stuff?

cmcanulty
February 13th, 2011, 01:20 PM
http://www.ubuntugeek.com/create-backup-of-all-installed-packages-using-aptoncd-in-ubuntu.html
http://www.ubuntugeek.com/howto-reinstall-all-of-currently-installed-packages-in-fresh-ubuntu-install.html
http://www.arsgeek.com/2006/09/19/ubuntu-tricks-how-to-generate-a-list-of-installed-packages-and-use-it-to-reinstall-packages/
http://www.unixtutorial.org/2008/09/list-installed-packages-on-your-ubuntu-linux/

BHEJU
March 14th, 2011, 03:48 PM
Great tip.
Big Thanks to OP.

Cheers,

stchman
March 16th, 2011, 05:10 PM
You can also use the following command:


sudo dpkg -l > <file_name>

LeeU
July 26th, 2011, 08:46 PM
Thanks, danielv42 for the extra details! Fantastic!

Redsandro
July 27th, 2011, 02:00 AM
Thanks, danielv42 for the extra details! Fantastic!

lol nobody knows what you're talking about, I am guessing this quote from 2008:
I wanted a list of packages with their descriptions, so I used:

dpkg -l | grep '^[D|+i]' >> installed_dpkg_l.txt

Anyway, nowdays you can import/export your package selection or custom selections from synaptic. :) (Without descriptions though.)

cmcanulty
July 27th, 2011, 08:31 AM
In synaptic click file-save marking and be sure save full state is checked name file and it is in your home folder. To reinstall all just click in synaptic file-read markings.

Redsandro
July 27th, 2011, 09:13 AM
Yep, that's kind of what I meant. :)

j*tech
September 6th, 2011, 01:06 PM
How can I direct the output to my flash USB?

kdford
September 6th, 2011, 01:34 PM
How can I direct the output to my flash USB?

dpkg -l | grep '^[D|+i]' >> /media/SOME-USB_DRIVE/installed_dpkg_l.txt

j*tech
September 6th, 2011, 04:05 PM
Thnx

dcsoldschool53
September 7th, 2011, 09:37 AM
it still works like a charm, Thank you.

meowsus
September 19th, 2011, 08:58 PM
dpkg --get-selections > installed-software

This command will produce *all* packages currently on the system, which includes packages that were installed and then removed. For a clean list of packages installed on the system in it's current state, run:

dpkg --get-selections | grep -v deinstall > installed-software

madtom1999
October 10th, 2011, 06:30 AM
Over time I get a lot of unused packages accumulation.
Can one use popularity-contest to generate a list of recently used packages so I can do a fresh install/upgrade and then load what I use and then restore /home etc?

Todamont
December 12th, 2011, 09:59 PM
Great comment. I will install ALL the things! Muahaha!!!

Redsandro
December 12th, 2011, 10:22 PM
FTFY

http://weknowmemes.com/wp-content/gallery/x-all-the-things/x-all-the-things-template.jpg

InonS
January 2nd, 2012, 08:03 AM
I wasn't interested in listing all of the dependencies, but just the top packages, for which all the others would be installed automatically.
Here's my script:



dpkg --get-selections > installed-software
touch top_dependents # create file to list top dependents
while read PAK # read installed-software file, line-by-line
do
if [ "$(apt-cache rdepends $PAK | tail -1)" != "Reverse Depends:" ] # is the reverse depends (i.e. dependents) list empty? (can also be implemented using sed instead of tail)
then echo "$PAK has dependents" # user feedback. can be commented out
else
echo "$PAK is top dependent" # user feedback. can be commented out
echo $PAK >> top_dependents # append to top dependents list
fi
done < installed-software


Hope others make use of this. Feel free to tweak!

condos2012
January 2nd, 2012, 09:40 AM
wow, thanks for the script. it's very useful

InonS
January 2nd, 2012, 03:38 PM
CAUTION: If I have a package A installed which has some other package B dependent on it, but I did not install package B, the script might not show A as a top package (since the repositories will have package B listed as dependent on A). This means that the output of my script will not include any such package as A, and there may be MANY such packages.

Can anyone offer a way to have the script go only over packages installed localy, rather than checking dependencies on the repository?

I wasn't interested in listing all of the dependencies, but just the top packages, for which all the others would be installed automatically.
Here's my script:



dpkg --get-selections > installed-software
touch top_dependents # create file to list top dependents
while read PAK # read installed-software file, line-by-line
do
if [ "$(apt-cache rdepends $PAK | tail -1)" != "Reverse Depends:" ] # is the reverse depends (i.e. dependents) list empty? (can also be implemented using sed instead of tail)
then echo "$PAK has dependents" # user feedback. can be commented out
else
echo "$PAK is top dependent" # user feedback. can be commented out
echo $PAK >> top_dependents # append to top dependents list
fi
done < installed-software


Hope others make use of this. Feel free to tweak!

InonS
January 8th, 2012, 01:25 PM
Fixed: add " --installed " after the apt-cache command to limit the search to packages currently installed (as opposed to packages which exist in the repos but are not currently installed).

CAUTION: If I have a package A installed which has some other package B dependent on it, but I did not install package B, the script might not show A as a top package (since the repositories will have package B listed as dependent on A). This means that the output of my script will not include any such package as A, and there may be MANY such packages.

Can anyone offer a way to have the script go only over packages installed localy, rather than checking dependencies on the repository?

evil gnome
February 24th, 2012, 05:21 PM
I have a list of packages that I want to remove. what is the command to remove all packages within a text list?

oldfred
February 24th, 2012, 07:31 PM
this is a way to install:

cat list-of-packages.txt | xargs sudo apt-get install -y
cat package-list': you're printing the contents of the file package-list to the standard output
' | ': this is a pipe, it sends the standard output from the previous command to the standard input of the next.
'xargs sudo apt-get install ': xargs takes the standard input, and adds it on to the following command (sudo apt-get install) as arguments.

If you change install to remove or purge it should work. Have not tried it. See also:
man apt-get