Difference between revisions of "Package management"

From English Wiki
Jump to navigation Jump to search
m
m
Line 10: Line 10:
 
* Yum, an older manager for packages in Fedora  
 
* Yum, an older manager for packages in Fedora  
  
Here, then, is a summary of basic commands for these various package managers.  
+
Here, then, is a summary of basic commands for these various package managers, broken down by the major families of Linux distros.
  
  
 +
 +
== Installing from source code ==
 +
The traditional ways of installing programs includes uncompressing tarballs, compiling the code, and then running the installation files.
  
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
 +
|+ 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
 +
|}
 +
 +
 +
 +
== RHEL ==
 +
The Red Hat Enterprise Linux also includes Fedora, CentOS, and others. RPM is the main installation file type in RHEL, while other package managers like yum and yay have been used for other repositories.
 +
 +
 +
{| class="wikitable sortable"
 +
|+ RHEL (Red Hat / Fedora)
 +
! Command !! Function
 +
|-
 +
| 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 -qa || Query and print all installed packages
 +
|-
 +
| rpm -qa || List installed RPM packages
 +
|-
 +
| rpm -qa | 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
 +
|-
 +
| yay -S ''pkg'' || Install a package from the AUR (Arch user repository)
 +
|-
 +
| 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)
 +
|}
 +
 +
 +
== 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.
 +
 +
 +
{| class="wikitable sortable"
 +
|+ Debian / Ubuntu
 
! Command !! Function
 
! Command !! Function
 
|-
 
|-
Line 80: Line 151:
 
|-
 
|-
 
| dpkg-query -l || List installed packages
 
| dpkg-query -l || List installed packages
|-
+
 
| flatpak install ''packagename'' || Install a flatpak package
+
|}
|-
+
 
| flatpak list --app || List installed flatpack packages
+
 
|-
+
== Arch ==
| flatpak update || Update flatpak packages
+
Arch includes Manjaro and a number of similar Arch based distros.
|-
+
 
| flatpak uninstall <application ID> || Uninstall flatpak packages
+
{| class="wikitable sortable"
|-
+
! Command !! Function
| flatpak uninstall --all || Uninstall all flatpak packages
+
|+ Arch  
|-
 
| flatpak uninstall --unused || Cleanup unused flatpak package files
 
|-
 
| paccache -r || Clean up old package files in pacman (Arch) (keeps 3 recent versions of packages by default)
 
|-
 
| paccache -rk ''x'' || Clean up all old package files except for the last ''x'' number of versions (e.g., -rk 1 to keep only the last version)
 
 
|-
 
|-
 
| packman -Qq || List user-installed packages
 
| packman -Qq || List user-installed packages
Line 115: Line 180:
 
| pamac update || Update Arch (AUR) packages
 
| pamac update || Update Arch (AUR) packages
 
|-
 
|-
| rpm -e pkg.rpm || Remove or uninstall an RPM package
+
| ls /var/cache/pacman/pkg/ <nowiki>|</nowiki> wc -l || Check how many cached packages are in the cache folder
 
|-
 
|-
| rpm -i –force || Forcibly install an RPM package
+
| du -sh /var/cache/pacman/pkg/ || check the total disk space used by the cache folder
 
|-
 
|-
| rpm -i –nodeps || Install using the ‘no dependencies’ flag
+
| paccache -r || Clean up old package files in pacman (Arch) (keeps 3 recent versions of packages by default)
 
|-
 
|-
| rpm -i pkg.rpm || Install package from a local file
+
| 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
 
|-
 
|-
| rpm -i pkg.rpm || Download an RPM package
+
| 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.<ref>https://ostechnix.com/recommended-way-clean-package-cache-arch-linux.</ref> 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).
 +
 
 +
 
 +
== 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.
 +
 
 +
{| class="wikitable sortable"
 +
! Command !! Function
 
|-
 
|-
| rpm -qa || Query and print all installed packages
+
| flatpak install ''packagename'' || Install a flatpak package
 
|-
 
|-
| rpm -qa || List installed RPM packages
+
| flatpak list --app || List installed flatpack packages
 
|-
 
|-
| rpm -qa | grep ''file'' || Query and search for a particular installed package
+
| flatpak update || Update flatpak packages
 
|-
 
|-
| rpm -qi || Provide information on an RPM package
+
| flatpak uninstall <application ID> || Uninstall flatpak packages
 
|-
 
|-
| rpm -U || Upgrade an RPM package
+
| flatpak uninstall --all || Uninstall all flatpak packages
 
|-
 
|-
| rpm –rebuild ''file'' || Rebuild a package if corrupted by another installation process
+
| flatpak uninstall --unused || Cleanup unused flatpak package files
 
|-
 
|-
 
| snap list || List installed snap packages
 
| snap list || List installed snap packages
|-
+
 
| tar zxvf sourcecode.tar.gz; cd ''sourcecode_folder''; ./configure; make; make install || Compile and install a package from source code
 
|-
 
| yay -S ''pkg'' || Install a package from the AUR (Arch user repository)
 
|-
 
| 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)
 
 
|}
 
|}
  
Line 169: Line 241:
  
 
==See also==
 
==See also==
 +
 +
===References===
 +
<references/>
 +
 +
===Other pages ===
  
 
<categorytree mode=pages>Linux</categorytree>
 
<categorytree mode=pages>Linux</categorytree>

Revision as of 10:19, 12 November 2022

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 Redhad and others in the 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


2 RHEL

The Red Hat Enterprise Linux also includes Fedora, CentOS, and others. RPM is the main installation file type in RHEL, while other package managers like yum and yay have been used for other repositories.


RHEL (Red Hat / Fedora)
Command Function
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 -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
yay -S pkg Install a package from the AUR (Arch user repository)
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)


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
dnf install pkg.rpm Using the DNF package manager to install a package in Fedora
dnf list installed List installed packages
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


4 Arch

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

Command Function
Arch
packman -Qq List user-installed packages
pacman -R pkg Remove a package with pacman
pacman -Rcns pkg Remove a package and all its dependencies
pacman -Rdd “pkg” Remove a package without breaking dependencies
pacman -Sc Clean up all old package files (unused packages)
pacman -Scc Remove all cached packages
pactree pkg View a list of dependencies associated with a package, displayed as a tree diagram (Arch based distros)
pactree -d 1 pkg 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



6 See also

6.1 References

6.2 Other pages