Skip to content

Linux & shell: Package & software versions (any distro)

29 Linux & shell commands: Package & software versions (any distro). Click a command to see what each part does.

Index
29 items
Click a command to see what each part does.

Package & software versions (any distro)29

  • hostnamectlOS, version and kernel in one view

    What each part does

    1. hostnamectlhostname, operating system and version, kernel, architecture, virtualization (systemd systems)
  • <program> --versionVersion of any program

    What each part does

    1. <program> --versionmost tools print their version; some use -v or -V (nginx -v, java -version, python3 -V)
  • dpkg -S "$(command -v <program>)"Where is a command, and which package installed it? (Debian / Ubuntu)

    What each part does

    1. command -v <program>full path of the program the shell would run
    2. dpkg -S <path>the package that owns that file
  • rpm -qf "$(command -v <program>)"Which package installed a command? (RHEL / Fedora / Amazon Linux)

    What each part does

    1. command -v <program>full path of the program
    2. rpm -qf <path>package (name-version-release) that owns that file
  • dpkg-query -W -f='${Package} ${Version} ${Status}\n' <package>Installed version of one package (Debian / Ubuntu)

    What each part does

    1. dpkg-query -Wshow installed package info
    2. -f='${Package} ${Version} ${Status}\n'output format: name, version, install status
    3. <package>package name; wildcards work, e.g. 'openssl*'
  • apt-cache policy <package>Installed vs available version (Debian / Ubuntu)

    What each part does

    1. apt-cache policyInstalled: version now, Candidate: what apt install/upgrade would get, plus the version table per repo
    2. <package>package name
  • apt list -a <package>All versions the repos offer (Debian / Ubuntu)

    What each part does

    1. apt list -aevery available version, marked [installed] / [upgradable]
  • sudo apt update && apt list --upgradablePackages with updates available (Debian / Ubuntu)

    What each part does

    1. apt updaterefresh package lists first, or the answer is stale
    2. apt list --upgradableinstalled packages with a newer version: name, new version, [upgradable from: old]
  • dpkg-query -W -f='${Package}\t${Version}\n' | sortEvery installed package with its version (Debian / Ubuntu)

    What each part does

    1. dpkg-query -W -f='...'name TAB version for every installed package
    2. | sortalphabetical; redirect to a file to diff two servers
  • rpm -q <package>Installed version of one package (RHEL / Fedora / Amazon Linux / SUSE)

    What each part does

    1. rpm -q <package>name-version-release.arch, or 'package ... is not installed'
  • rpm -qi <package>Details of an installed package (RHEL family)

    What each part does

    1. rpm -qiversion, release, install date, vendor, build date, summary
  • dnf list --showduplicates <package>Installed and available versions (RHEL / Fedora)

    What each part does

    1. dnf listInstalled Packages section and Available Packages section
    2. --showduplicatesevery available version, not just the newest (to pick one to install or downgrade)
  • dnf check-updatePackages with updates available (RHEL / Fedora)

    What each part does

    1. dnf check-updatelist pending updates; exit code 100 means updates exist, 0 means none (yum check-update on older systems)
  • dnf updateinfo list --securityPending security updates only (RHEL / Fedora)

    What each part does

    1. dnf updateinfo listadvisories for available updates
    2. --securityonly security fixes, with severity and advisory ID
  • rpm -qa --last | head -30Every installed package, newest installs first (RHEL family)

    What each part does

    1. rpm -qaall installed packages
    2. --lastsorted by install/update time, newest first, with the date
    3. | head -30the 30 most recent
  • dnf history; dnf history info <id>What changed recently? (RHEL / Fedora)

    What each part does

    1. dnf historyevery install/upgrade/remove transaction with date and user
    2. dnf history info <id>exact packages and versions in that transaction; dnf history undo <id> reverts it
  • grep -E ' (install|upgrade) ' /var/log/dpkg.logWhat was installed or upgraded recently? (Debian / Ubuntu)

    What each part does

    1. grep -E ' (install|upgrade) 'only install and upgrade lines (date, package, old and new version)
    2. /var/log/dpkg.logdpkg's log; older months are in dpkg.log.1 and .gz files (zgrep)
  • apk info -v <package>; apk policy <package>Installed version of one package (Alpine)

    What each part does

    1. apk info -v <package>installed name-version
    2. apk policy <package>installed and available versions per repository
  • apk update && apk version -l '<'Packages with updates available (Alpine)

    What each part does

    1. apk updaterefresh the index
    2. apk version -l '<'only packages whose installed version is older than the repo's
  • zypper info <package>Installed version of one package (SUSE)

    What each part does

    1. zypper infoversion, repository, installed status of a package
  • snap list; flatpak list --columns=application,versionSnap and Flatpak packages with versions

    What each part does

    1. snap listsnaps: name, version, revision, channel
    2. flatpak list --columns=...flatpak apps and their versions
  • python3 -m pip list; python3 -m pip show <package>Python packages and versions

    What each part does

    1. python3 -m pip listevery package in this Python environment with its version (add --outdated for updates)
    2. pip show <package>version, location and dependencies of one package
  • node --version; npm ls -g --depth=0Global Node.js packages and versions

    What each part does

    1. node --versionNode.js version
    2. npm ls -g --depth=0globally installed npm packages, top level only
  • ldd --version | head -1; openssl version -a | head -2Core library versions (glibc, OpenSSL)

    What each part does

    1. ldd --versionthe C library (glibc) version; matters for binary compatibility and CVEs
    2. openssl version -aOpenSSL version and build date
  • sudo apt install <package>=<version>Install a specific version (Debian / Ubuntu)Caution

    What each part does

    1. <package>=<version>exact version from apt list -a; add --allow-downgrades to go back
  • sudo dnf install <package>-<version>Install a specific version (RHEL / Fedora)Caution

    What each part does

    1. <package>-<version>exact version from dnf list --showduplicates; dnf downgrade to go back
  • sudo apt-mark hold <package>; sudo dnf versionlock add <package>Stop a package from being upgraded

    What each part does

    1. apt-mark holdDebian / Ubuntu: keep the current version (apt-mark unhold to release)
    2. dnf versionlock addRHEL / Fedora: same idea (needs the versionlock plugin)
  • dnf provides '*/<file>'; apt-file search <file>Which package provides a file you don't have?

    What each part does

    1. dnf provides '*/<file>'RHEL family: packages containing that file
    2. apt-file search <file>Debian / Ubuntu (install apt-file and run apt-file update first)
  • ansible all -i <inventory> -m shell -a "rpm -q <package> 2>/dev/null || dpkg-query -W <package>"Check a package version across many servers

    What each part does

    1. ansible all -i <inventory>every host in the inventory
    2. -m shell -a "..."run the command on each one
    3. rpm -q <package> || dpkg-query -W <package>works on both RHEL- and Debian-family hosts

    Tip Without Ansible: for h in <host1> <host2>; do echo "$h: $(ssh $h 'rpm -q <package> 2>/dev/null || dpkg-query -W <package>')"; done

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…