In this post, we will discuss the 2 common package managers in Linux. They are the following:
1. RPM-based - rpm,yum
2. Debian-based - dpkg,apt-get,dselect,aptitude,apt-cache
RPM
Examples of systems that uses RPM-based package managers are Red Hat, Fedora, and Centos. The "rpm" command is to install packages directly. It doesn't handle dependency requirements so you need to install the needed packages (if there is any) before installing the package you want. For example, if you want to install packageA but it needs packageB, you need to install packageB first before proceeding with packageA. Here are the common uses of "rpm" command.
* Installing/Upgrading *
rpm -i <filename.rpm> # installs a package (install only if it doesn't exist)
rpm -ivh <filename.rpm> # same as the above, but increases verbosity (-v) and hashes as progress indicator (-h)
rpm -ivh <filename.rpm> --force # installs a package even if it exists (package reinstall)
rpm -Fvh <filename.rpm> # freshens a package (upgrade a package if ONLY an older version exists)
rpm -Uvh <filename.rpm> # installs a package if that doesn't exist or upgrade a package if it exists
rpm -ivh <filename.rpm> --nodeps # installs a package ignoring dependency checking (use this with caution because the program you will install might not work)
rpm -i <package name> --test # do a dry-run instead of installing actual package
* Removing *
rpm -e <filename> -- removes a package
* Querying *
rpm -qi <package name> # queries a package (-q) by printing information (-i); takes only package name and not filename (file.rpm)
rpm -ql <package name> # lists files associated in the package (-l)
rpm -qf <package name> # shows you on what package the file/directory/script came from; example is rpm -qf $(which cp)
rpm -qi <package name> --change-log # prints change log of the given package
rpm -qi <package name> --scripts # prints scripts that ran when the package was installed
rpm -q[other query options]p file_name.rpm # queries a package filename instead (-p) of package name; example is rpm -qip my-program.rpm
YUM
There is also an RPM-based tool that handles dependency conflicts automatically and that is YUM (Yellowdog Updater Modified). "yum" command is the one we used which can also do what "rpm" command can. This is the best package management tool to use if you are using the Linux distributions mentioned above. The main disadvantage of this is you need a repository before you can do any transactions whereas RPM don't. Repositories are the ones inside /etc/yum.repos.d directory and will be discussed on a separate post in this blog. YUM commands that are commonly used are:
* Installing/Upgrading *
yum install # installs a package or multiple packages
yum install <package name(s)> -y # same as above but answers "y" to all installation questions
yum update # updates all installed packages on the system
yum update <package name(s)> # updates a single or multiple packages
yum localinstall <filename.rpm> # installs a local rpm file using your yum repository to resolve dependencies
* Removing *
yum remove <package name(s)> # removes packages and all packages where the package depends on
yum erase <package name(s)> # same as above
* Querying *
yum list # lists ALL installed packages and shows you if there is a newer version for each of those
yum list # lists ALL installed packages and shows you if there is a newer version for each of those
yum list <package name> # lists installed packages and shows you if there is a newer version for that
yum list available <package name> # lists all available packages for update
yum list available <package name> # lists all available packages for update
yum search *pattern* # searches all package names that contains the string; prints both installed and available packages
yum search all *pattern* # deeper search compare to the above command (searches also contents not only package names)
yum provides <file/directory> # shows what package owns the file/directory
yum whatprovides */<file/directory> # use this when you don't get a result from the above command
yum info <package name> # shows info on a package (similar to rpm -qi)
yum check-update # checks whether there are updates available
yum --disablerepo=* --eablerepo=<repo ID> list <pacakge name> # list package on a particular repo
yum --disablerepo=* --eablerepo=<repo ID> list <pacakge name> # list package on a particular repo
DPKG
Aside from RPM-based systems, we also have Debian-based systems. Examples of these are Ubuntu and of course Debian. The package management tools they use are apt-get, aptitude, dselect, and dpkg. "apt-get" is similar to yum where you need a repository which is defined under /etc/apt/sources.lst, "dpkg" is similar to rpm, "dselect" is a menu based tool, and aptitude is a combination of dselect's menu based and apt-get's cli features. Debian packages by convention ends with .deb. Let's start with dpkg. Here are the common commands for dpkg.
* Installing/Upgrading/Configuring*
dpkg -i <package name> # installs a package
dpgk -i <package name> --ignore-depends=<package> # ignore dependency conflict (similar to --nodeps in rpm)
dpkg -i <package name> --no-act # tests for dependency only (similar to --test in rpm)
dpkg -iG <package name> # doesn't install a package if a newer version of same package is already installed
dpkg -iE <package name> # doesn't install a package if same version of package is already installed
* Removing *
dpkg -r <package name> # removes a package while retaining its configuration files
dpkg -P <package name> # removes a package and configuration files
* Querying *
dpkg -P <package name> # displays information about an installed package
dpkg -I <uninstalled package name> # displays information about an uninstalled package
dpkg --get-selections # displays current installed packages
dpkg -l <pattern> # list installed packages matching the pattern string
dpkg -L <package name> # lists files associated with the package (similar to rpm -ql)
One command that is very useful if you want to return the package to its original state (fresh install with default settings) is "dpkg-reconfigure". For example, the command below will reconfigure the samba package, asking the packages initial installation questions and restarting its daemons.
dpkg-reconfigure samba
APT-GET
Similar to yum , Debian-based systems have the tool called "apt-get" which automatically handle dependency conflicts. Before using it, make sure you have the appropriate sources inside /etc/apt/sources.lst. Here are the common usage of that command:
* Installing/Upgrading *
apt-get install <package name> # installs a package
apt-get install <package name> -y # installs a package assuming "y" to all questions
apt-get install <package name> -s # doesn't install, simulates a dry-run
apt-get install <package name> -s # doesn't install, simulates a dry-run
apt-get install <package name> --no-upgrade # don't upgrade a package if an older version exists
apt-get install <package name> -d # downloads a package but doesn't install it
apt-get install <package name> -s # performs a simulation/dry-run without installing any package or configuring any file
apt-get install /path/to/deb/package -f # installs a .deb package and resolves dependencies through APT repositories
apt-get upgrade # upgrades all installed packages to newer versions
apt-get dist-upgrade # similar to above command but performs "smart" conflict resolution
* Removing *
apt-get remove <package name> # removes a package
* Configuring *
apt-get dselect-upgrade # performs any changes in package status left undone after running deselect
apt-get clean # performs housekeeping (like yum clean)
apt-get autoclean # similar to the above command but removes about packages that can no longer be downloaded
* Querying *
apt-get check # checks package database for consistency and broken package installations
apt-file search /path/to/file # searches for package containing a file
APT-CACHE
We also have apt-cache. Its only purpose is to provide information about Debian package database. Here are sample commands:
apt-cache show <package name> # displays descripion of package
apt-cache showpkg <package name> # same as above but displays dependency information instead
apt-cache show <package name> # displays descripion of package
apt-cache stats # displays package statistics (how many installed, dependencies recorded, etc..)
apt-cache unmet # displays information about unmet dependencies
apt-cache depends <package name> # shows on what packages the one you specified depend on
apt-cache pkgnames # displays all installed packages
apt-cache pkgnames <string> # displays list of installed packages matching the string specified
DSELECT
A menu-based package manager also exists for Debian-based systems. That is "dselect". When invoked, it will display you the following menu.
0. [A]ccess Choose the access method to use.
1. [U]pdate Update list of available packages, if possible.
2. [S]elect Request which packages you want on your system.
3. [I]nstall Install and upgrade wanted packages.
4. [C]onfig Configure any packages that are unconfigured.
5. [R]emove Remove unwanted software.
6. [Q]uit Quit dselect.
APTITUDE
A tool that combines dselect's menu based gui and apt-get's cli is "aptitude". Here are the common usage:
aptitude search <package name> # searches packages related to the one you specified (apt-get seems not to have this feature)
aptitude update # update package list from APT repository
aptitude install <package name> # installs a package
aptitude install <package name>- # removes a package (w/ leading dash)
aptitude remove <package name> # same as above
aptitude full-upgrade # upgrades all installed packages
aptitude safe-upgrade # conservative version of the above command
aptitude autoclean # removes already-downloaded packages that are no longer available
aptitude help # shows complete options
No comments:
Post a Comment