Debian Commands
Useful commands on a Debian box:
Packages management
Working on the available packages DB
- apt-get update
- Updates internal DBs of available packages (based on /etc/apt/source.list)
- apt-cache search keywords
- Look for packages containing keywords in their description
- Works offline
- DebTags
- New powerful way to find packages
- Works offline
- apt-cache show package
- Show detailed description of a package
- Works offline
- apt-cache showpkg package
- Shows which version of the package is contained in which feed
- Works offline
- Package cron-apt
- Works as a cron operation in background
- By default, will populate /var/cache/apt with the last versions of the packages and will send a mail.
- Works online (but, as it's a cron task, deals with offline situations)
- Now you can apt-get upgrade when you want, even offline :-)
- Useful files
- /etc/apt/sources.list : list of the feeds
- /etc/apt/apt.conf : configuration of apt, cf "man apt.conf"
- Apt pinning
- Package netselect-apt
- Choose the fastest Debian mirror with netselect
- Useful to get a good sources.list (but only for the official feeds)
Installing/removing packages
- apt-get upgrade
- Upgrades all possible already installed packages with a newer version if possible (i.e. this does not impact other dependancies)
- Usually follows apt-get update
- apt-get dist-upgrade
- Upgrades all possible already installed packages with a newer version and manages the dependancies (i.e. install/remove some dependances, especially libraries)
- Usually to migrate from the current stable becoming the old-stable to the new stable (e.g. from Woody to Sarge) but useful also to maintain the testing or unstable distributions as new library dependancies happen quite often
- apt-get install package
- Installs a package
- dpkg -i package-filename
- Installs a locally downloaded/generated package file (*.deb)
- apt-get remove package
- Removes a package from the system
- apt-get clean
- Removes all cached package files (/var/cache/apt/archives/*.deb)
Using signature verifications on packages
To get the Debian keyring if needed:
apt-get install debian-keyring
To re-install the Debian maintainer keys for apt-get:
wget http://ftp-master.debian.org/ziyi_key_2005.asc gpg --no-default-keyring --keyring /etc/apt/trusted.gpg --import ziyi_key_2005.asc
If you get the following error when apt-get update:
W: GPG error: http://myprox sarge Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 07DC563D1F41B907
That's because of the Marillat feeds, you need to import his key
gpg --no-default-keyring --keyring /etc/apt/trusted.gpg --keyserver keyring.debian.org --recv-keys 07DC563D1F41B907
or, if you got it in a file:
gpg --no-default-keyring --keyring /etc/apt/trusted.gpg --import marillat.asc
or:
gpg --keyserver pgp.mit.edu --recv-keys 1F41B907; gpg --armor --export 1F41B907 | apt-key add - apt-key list
Other sources of packages
If you don't find your package on the regular Debian feeds, try
- Unofficial APT repositories
- alien package.rpm
This transforms a package.rpm (for RedHat, Mandrake,...) into a package.deb that you can install with dpkg -i - To create a .deb, see man dpkg-source
- See also srcinst, not yet tried...
If you want to recompile a package
apt-get build-dep package apt-get source package cd package-dir dpkg-buildpackage -rfakeroot -uc -b
Inside a debian package
ar x package.deb
This gives 3 files: control.tar.gz data.tar.gz debian-binary
Fixing package dependancies
When installing a non-official package, it may happen that the dependancies are wrong.
dpkg-deb -x skype_1.2.0.18-1_i386.deb skype_1.2.0.18-1_i386 mkdir skype_1.2.0.18-1_i386/DEBIAN dpkg-deb -e skype_1.2.0.18-1_i386.deb skype_1.2.0.18-1_i386/DEBIAN
Edit the file skype_1.2.0.18-1_i386/DEBIAN/control and change the dependancies:
Change libqt3c102-mt (>= 3:3.3.3.2) into libqt3-mt (>= 3:3.3.5)
dpkg-deb -b skype_1.2.0.18-1_i386 sudo dpkg -i skype_1.2.0.18-1_i386.deb
Re-packaging Perl CPAN modules not yet available in Debian
apt-get install dh-make-perl
Example: dh-make-perl --build --cpan HTML::Template::JIT
First time it will auto-configure the CPAN database so it's quite slow
Installing not packaged softwares
apt-get install installwatch
Installwatch can be used to track the changes made during the installation of local (i.e. non-deb) software.
Working on already installed packages
dpkg -L package
Shows all the installed files on the system of an installed package
Useful to see which commands the package contains, if it contains documentation etc
dpkg -S partial filename
Searches in the installed list of packages which one(s) contains the searched filename
Useful when you find a file/program on your system but don't know from where it came
dlocate partial filename
Much faster than dpkg -S, uses a DB as locate, requires package dlocate to be installed
dpkg --get-selections
Displays the list of installed (and removed) packages
dpkg -l ' regexp '
Displays the matching packages
dpkg-reconfigure package
Restart the configuration step which usually follows a package installation
The graphical interface (text, ncurses, KDE, etc) for the configuration of a package is handled by debconf so this can be changed by...
dpkg-reconfigure debconf (install libqt-perl to get the KDE gui working)
update-alternatives or galternatives (X11)
Allows to manipulate the /etc/alternatives directory and to choose which application to run while the system contains multiple possibilities
Example:
$ update-alternatives --display x-session-manager x-session-manager - status is auto. link currently points to /usr/bin/startkde /usr/bin/icewm-session - priority 10 /usr/bin/startkde - priority 40 Current 'best' version is /usr/bin/startkde.
To choose manually:
$ update-alternatives --config x-session-manager
dpkg-repack package
apt-get install dpkg-repack
Recreates a .deb from an already installed package (and integrates possible changes e.g. in /etc), usefull if the original .deb is not available anymore.
deborphan
Gives a list of libraries apparently not needed anymore by any installed programs (beware if you installed locally some non-debian sources)
apt-get install deborphan deborphan deborphan|xargs apt-get remove -y
debian-goodies
apt-get install debian-goodies dgrep - Search all files in specified packages for a regex dglob - Generate a list of package names which match a pattern debget - Fetch a .deb for a package in APT's database dpigs - Show which installed packages occupy the most space debman - Easily view man pages from a binary .deb without extracting checkrestart - Help to find and restart processes which are using old versions of upgraded files (such as libraries) popbugs - Display a customized release-critical bug list based on packages you use (using popularity-contest data)
Changing SUID bit on an executable
e.g. artswrapper:
dpkg-statoverride --add --update root root 4755 /usr/bin/artswrapper
To revert the change:
dpkg-statoverride --remove /usr/bin/artswrapper; chmod 0755 /usr/bin/artswrapper
Flagging a package as hold
echo "package hold" | dpkg --set-selections
to revert:
echo "package install" | dpkg --set-selections
Errors recovery
In case of sth like:
E: Unable to parse package file /var/lib/dpkg/status (1) E: The package lists or status file could not be parsed or opened.
Sounds like /var/lib/dpkg/status has become corrupted in some way.
Luckily dpkg (or apt?) does keep backups of that file (/var/backups/dpkg.status.*) and you may be able to recover by reverting to that backup. *BUT* that is likely to put /var/lib/dpkg/status
"out-of-sync" with what *actually* is installed on the machine.
What packages did you last install/deinstall ? A diff between
/var/lib/dpkg/status and /var/backups/dpkg.status.* may refresh your memory. Chances are that you have to re-install (/re-de-install) them to get things back in sync.
Bug reports
apt-get install reportbug reportbug [--email=my@email] package