Package management

From English Wiki
Revision as of 05:26, 28 September 2023 by Kentlee7 (talk | contribs) (→‎Arch)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In Linux, it is less common these days to install a program by compiling code from a tarball (a compressed tar file). While GUI based installers are handy, using commands and package managers in the command line interface (CLI) can be more convenient, especially if the GUI package manager is misbehaving. Different distros use different package managers for installing programs, with some more common ones being as follows.

  • Apt for Debian-based distros (including Ubuntu and Mint)
  • DPKG, an older package manager in Debian (useful also for fixing some installation problems if you have trouble with apt)
  • DNF in Fedora and related distros
  • RPM (Redhat Package Manager), a standard installation file format and program installation utility in Redhat and others in the RHEL/Fedora family
  • Pacman for core packages in Arch and Arch-based distros (like Manjaro)
  • Pamac in Arch and Arch-based distros, for installing packages from the AUR (Arch User Repository), a secondary repository, e.g., for packages that were not originally developed natively for Arch but have been adapted for Arch
  • Flatpak, for various distros (these are packaged in a way that they can run on many multiple distros without compatability or dependency problems)
  • Yay, an older manager for AUR packages in Arch
  • Yum, an older manager for packages in Fedora

Here, then, is a summary of basic commands for these various package managers, broken down by the major families of Linux distros.


1 Installing from source code

The traditional ways of installing programs includes uncompressing tarballs, compiling the code, and then running the installation files.

Source code installation
Command Function
tar zxvf sourcecode.tar.gz
cd sourcecode_folder
./configure
make
make install
Compile and install a package from source code (by entering each command at a time in sequence)

2 RHEL

The Red Hat Enterprise Linux includes Red Hat (for servers), Fedora, CentOS / CentOS Stream, and others. RPM is the main installation file type in RHEL, and which can be managed manually with rpm commands. In Fedora, dnf is the main package manager, while other package managers like yum have been used for other repositories.

RHEL (Red Hat / Fedora)
Command Function
dnf install packagename Install a package
dnf install pkg.rpm Using the DNF package manager to install an RPM package in Fedora
dnf list installed List installed packages
dnf remove packagename Remove an installed package
dnf search packagename Search the repositories for a package
dnf autoremove Remove packages that are installed as dependencies that are no longer required by currently installed programs
dnf check-update Check for updates, but without downloading or installing the packages
dnf clean Clean temporary files; arguments: clean packages, clean metadata, clean all
dnf downgrade Revert to the previous version of a package
dnf info Look up basic information about a package, including name, version, release, and description
dnf list Prints a list of installed packages
dnf provides Find a package that provides a given specification
dnf reinstall Reinstall a currently installed package
dnf remove Remove a package.
dnf repoquery Find information on packages in DNF repositories.
dnf upgrade Checks the repositories for newer packages and update them
dnf upgrade --exclude=packagename Exclude a particular package from an upgrade
dnf install dnf-plugins-core-PLUGIN_NAME or
dnf install dnf-plugins-extras-PLUGIN_NAME
Install dnf extensions and plugins to extend dnf functionality
dnf install 'dnf-command(versionlock)' Install the dnf version lock plugin
dnf repoquery whatprovides component-name Find a dnf package that provides a dependency, file or program; e.g.,
dnf repoquery whatprovides *gimp*dev* to find the package with Gimp developer libraries.
dnf versionlock add package Lock the currently installed version of a package
dnf versionlock delete package Remove the version lock from a package
dnf -l Show a list of files in a package.
rpm -e pkg.rpm Remove or uninstall an RPM package
rpm -i –force Forcibly install an RPM package
rpm -i –nodeps Install using the ‘no dependencies’ flag
rpm -i pkg.rpm Install package from a local file
rpm -i pkg.rpm Download an RPM package
rpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE}\t%{SUMMARY}\n' Find installed public keys for software repos (e.g., in order to find the desired key to remove)
rpm -qa Query and print all installed packages
rpm -qa List installed RPM packages
grep file Query and search for a particular installed package
rpm -qi Provide information on an RPM package
rpm -U Upgrade an RPM package
rpm –rebuild file Rebuild a package if corrupted by another installation process
yum info pkg Display a description and summary information about a package in RHEL distributions
yum install pkg Install package .
yum install pkg.rpm Install a package in Yum
yum list --available List all available packages on RPM-based distributions
yum list --installed List all installed packages on RPM-based distributions
yum list installed List installed packages
yum remove pkg Uninstall or remove a package from your system.
yum remove pkg Remove a package on RPM-based distributions
yum search keyword Trace a package installation based on specific keywords.
yum update Update all system packages to the latest version (RPM-based distributions)


2.1 Install KDE

Many users will want to install KDE, which can be done in dnf.

$ sudo dnf update
$ sudo dnf install @kde-desktop 

In some distributions, yum may be used.

# yum groupinstall "KDE Plasma Workspaces" 


2.2 Group package installation

It is possible to install a group of packages all at once. To see a list of possible package group, type

dnf group list

. Some packages are hidden, so a --hidden flag can be used to see some hidden groups. The --installed flag can show which groups are already installed.

$ sudo dnf group list $ dnf group list --hidden

$ dnf group list --installed

Groups can be installed with a dnf command with the group, or with an @ ampersand.

$ sudo dnf install @virtualization
$ sudo dnf group install virtualization
$ sudo dnf group install "System Tools" 

It is possible to upgrade a package group rather than all packages, or to remove a group.

$ sudo dnf group upgrade virtualization
$ sudo dnf group remove virtualization 

3 Debian & Ubuntu

The Debian family includes Ubuntu and distros built off of Ubuntu, such as Mint and Pop!OS. Older Debian systems relied on dpkg, while apt-install or apt are the default for newer Ubuntu and Ubuntu-based distros.


Debian / Ubuntu
Command Function
add-apt-repository ppa:PPA_NAME; apt update Add repository (Debian)
apt Debian package manager
apt --fix-broken install Fix broken packages
grep -v automatic List user-installed packages
apt autoremove Remove installation packages that are no longer needed
apt install pkg Install a package with apt in Debian based systems
apt list --installed List user-installed packages
apt remove Remove a package
apt search Search for a package in the database
apt show Show detailed information about a package
apt-get --fix-broken install Check and fix broken packages
apt-get -f install Fix broken dependencies
apt-get autoremove Remove all unwanted packages
apt-get check && apt-get purge program-name Check and fix broken packages
apt-get clean / autoclean / autoremove Clean up package installation files
apt-get install pkg Install a package (older Debian command)
apt-get remove pkg Remove a package o
apt-get update Update the repository
apt-get upgrade pkg Upgrade a specific package
dpkg --configure -a ; apt-get update Fix uninstalled packages and update
dpkg --install pkg_file Install package in Debian
dpkg --list List packages
dpkg --remove -force --force-remove-reinstreq pkg-name Check and fix broken packages
dpkg --search file_name Find installed packages
dpkg --status packag­e_name Package status
dpkg -i pkg.deb Install .deb package
dpkg -l List installed packages
grep -i installed Get a list of all packages (in a Debian based distribution)
dpkg –get-selection List user-installed packages
dpkg-query -l List installed packages

3.1 Group package installation

In Ubuntu based distros, the program tasksel can be used to install groups. This can be used to install KDE and other package groups. Package groups can be installed from the command line, or one can invoke tasksel from the command line, which brings up a text user interface (TUI), where one can select package groups to install.

$ sudo apt install tasksel
$ sudo tasksel install kde-desktop
$ sudo tasksel  


4 Arch

Arch includes Manjaro and a number of similar Arch based distros.

Command Function
Arch
pacman -S pkg-name Install a new package
pacman -S extra/pkg-name Install a package from the extras repository
pacman -S pkg-gr, e.g.,
pacman -S gnome
Install the gnome package group
pacman -S plasma-{desktop,mediacenter,nm} To install a number of packages sharing similar name patterns
pacman -Qq List user-installed packages
pacman -R pkg-name Remove a package with pacman
pacman -Rcns pkg-name Remove a package and all its dependencies
pacman -Rddpkg-nam Remove a package without breaking dependencies
pacman -Sc Clean up all old package files (unused packages)
pacman -Scc Remove all cached packages
pactree pkg-name View a list of dependencies associated with a package, displayed as a tree diagram (Arch based distros)
pactree -d 1 pkg-name View a list of direct dependencies associated with a package, displayed as a tree diagram (Arch based distros)
pamac update Update Arch (AUR) packages
ls /var/cache/pacman/pkg/ | wc -l Check how many cached packages are in the cache folder
du -sh /var/cache/pacman/pkg/ check the total disk space used by the cache folder
paccache -r Clean up old package files in pacman (Arch) (keeps 3 recent versions of packages by default)
paccache -rk 1 Clean up all old package files except for the last x number of versions, e.g., -rk 1 to keep only the last version
paccache -ruk0 Remove all cached versions of uninstalled packages


To automatically clean the package cache in Arch, one can create a script for automatic cleanup after running pacman. This task can be automated with pacman hooks to automatically clean the package cache after every pacman transaction.[1] First, create a file called /etc/pacman.d/hooks/clean_package_cache.hook:

sudo mkdir /etc/pacman.d/hooks
sudo nano /etc/pacman.d/hooks/clean_package_cache.hook

Then add the following lines to the above file.

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *
[Action]
Description = Cleaning pacman cache...
When = PostTransaction
Exec = /usr/bin/paccache -r


Then save and close the file, and thereafter, the package cache will be cleaned automatically after every pacman transactions (like upgrade, install, remove).

5 Containerized packages

These are intended for cross-platform installation, as they run on package managers that provide for sandboxed dependencies so the files can be installed on most distros, regardless of the package management architecture and dependencies.

Command Function
flatpak install packagename Install a flatpak package
flatpak list --app List installed flatpack packages
flatpak update Update flatpak packages
flatpak uninstall <application ID> Uninstall flatpak packages
flatpak uninstall --all Uninstall all flatpak packages
flatpak uninstall --unused Cleanup unused flatpak package files
snap list List installed snap packages


AppImages is a newer format, which may work better in terms of graphical integration and functionality, and some prefer them because they are not sponsored by a major company (Snap, for example, is sponsored by Canonical, the company that makes Ubuntu). AppImages should be downloaded and placed inside this directory:

/home/USER/Applications/ 

From there they can be installed using the AppImage installer. AppImage applications can be found at from the websites or companies for individual applications, when available, and many can be found indexed at the official repository, http://www.appimagehub.com.

6 See also

6.1 References

6.2 Other pages