Package management with apt
In the beginning there was the .tar.gz. Users had to compile each program that they wanted to use on their GNU/Linux systems. When Debian was created, it was deemed necessary that the system include a method of managing the packages installed on the machine. The name dpkg was given to this system. Thus the famous 'package' first came into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm' system.
A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed a rapid, practical, and efficient way to install packages that would manage dependencies automatically and take care of their configuration files while upgrading. Here again, Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has since been ported by Conectiva for use with rpm and has been adopted by some other distributions.
Debian APT HOWTO
All these commands require sudo!
apt-get update - Run this after changing /etc/apt/sources.list or /etc/apt/preferences. You also must run it periodically to make sure your source list is up-to-date.
apt-get install packagename - installs a new package (but see aptitude, below)
apt-get remove packagename - removes a installed package (configfiles remain)
apt-get --purge remove packagename - removes a installed package (configfiles will also be removed)
apt-get upgrade - upgrades all installed packages
apt-get dist-upgrade - upgrades the entire system to a newer release
apt-cache search string - Searches for string in the list of known packages
dpkg -l package-name-pattern - List packages matching pattern
aptitude - Curses viewer of packages installed or available. Aptitude can be used from the command-line in a similar way to apt-get, but only for some commands - install and remove being the most common. However, because aptitude keeps track of more information than apt-get does, it can be considered better at install and remove operations.
apt-cache showpkg pkgs - Show information about packages.
apt-cache dumpavail - Prints out an available list.
apt-cache show pkgs - Displays package records, similar to dpkg --print-avail.
apt-cache pkgnames - Fast listing of every package in the system.
dpkg -S file - Which installed package owns the file?
dpkg -L package - List files in the package.
apt-file search filename - Search for a package (need not be installed) containing files including the string. apt-file is a package of its own, which you may have to apt-get install first, then run apt-file update. If apt-file search filename shows you too much, try apt-file search filename | grep -w filename (which shows you only the files that contain filename as a whole word) or variants like apt-file search filename | grep /bin/ only files located in directories like /bin or /usr/bin, useful if you're looking for a particular executable).
* apt-get autoclean - Run this periodically to clean out .deb archives from packages which are no longer installed on the system. You can regain lots of disk space that way. If you're really desperate for disk space, apt-get clean is more radical, and will remove .deb files even for packages currently installed. But most of the time you probably don't need the .debs any more, so it might be worth it if you're strapped for megabytes.
deborphan and debfoster are great for finding orphaned and unneeded packages which can be removed.
You can pull from a different repository by editing /etc/apt/sources.list to replace "stable" with "unstable" (or whatever) then doing apt-get update. That gets old, though, so here's a better way: pinning. Here's a sample unstable preferences file.
Speeding up your work at the command line
The command line is powerful, but typing is slow, so make your commands shorter. You might put this in your *~/.bashrc*
alias acs='apt-cache search'
alias agu='sudo apt-get update'
alias agg='sudo apt-get upgrade'
alias agd='sudo apt-get dist-upgrade'
alias agi='sudo apt-get install'
alias agr='sudo apt-get remove'
But see aptitude, above, for a reason to use "alias agi='sudo aptitude install'"