Best way to remove all packages acquired during a failed compile?

Hello everyone. I attempted to compile a rather large game (quake3-rally) with a lot of dependencies that installed along with it. Is there a way to safely uninstall all that was acquired during the compile with a single command without having to go through the terminal history and naming each package individually? Sometimes I can’t even get to the terminal history because of closing the terminal. I’ve read man pacman on it but I’m nervous to experiment after reading. I retried the compile many times after finding and installing dependencies that paru couldn’t seem to find, and I tried to compile with both paru and with makepkg, getting some dependencies with both. So, the package list would be a cluster-mess to get together.

Or, maybe there’s a better way I could do in the future to compile that would make it easier to get rid of it all. I’m all ears. I just don’t want to be left with gigabytes of stuff I’ll never use again, but if that’s the answer please let me know. I really have no idea.

I’m hoping for something simple like

sudo pacman -Rsc quake3-rally

except that quake3-rally never actually got installed…

or, maybe the best answer is to take a snapshot before the compile that I could revert to.

EDIT: Now that I think about it, it probably made spapshots a few times automatically. Is reverting to a snapshot the best answer?

Thank you for any help or insight.

╭─user@gbox in ~ 
 ╰─λ garuda-inxi
System:
  Kernel: 6.10.10-zen1-1-zen arch: x86_64 bits: 64 compiler: gcc v: 14.2.1
    clocksource: tsc avail: hpet,acpi_pm
    parameters: BOOT_IMAGE=/@/boot/vmlinuz-linux-zen
    root=UUID=e18dd1e4-3ee8-4352-8bd3-58066522e6ff rw rootflags=subvol=@
    quiet loglevel=3 modprobe.blacklist=iTCO_wdt ibt=off
  Desktop: KDE Plasma v: 6.1.5 tk: Qt v: N/A info: frameworks v: 6.6.0
    wm: kwin_wayland with: krunner vt: 1 dm: SDDM Distro: Garuda
    base: Arch Linux
Machine:
  Type: Laptop System: Dell product: Precision 7510 v: N/A
    serial: <superuser required> Chassis: type: 9 serial: <superuser required>
  Mobo: Dell model: N/A serial: <superuser required> part-nu: 06D9
    uuid: <superuser required> UEFI: Dell v: 1.31.3 date: 03/09/2023
Battery:
  ID-1: BAT0 charge: 67.6 Wh (100.0%) condition: 67.6/91.0 Wh (74.3%)
    volts: 12.9 min: 11.4 model: Samsung SDI DELL TWCPG77 type: Li-ion
    serial: <filter> status: full
CPU:
  Info: model: Intel Core i7-6820HQ bits: 64 type: MT MCP arch: Skylake-S
    gen: core 6 level: v3 note: check built: 2015 process: Intel 14nm family: 6
    model-id: 0x5E (94) stepping: 3 microcode: 0xF0
  Topology: cpus: 1x dies: 1 clusters: 4 cores: 4 threads: 8 tpc: 2
    smt: enabled cache: L1: 256 KiB desc: d-4x32 KiB; i-4x32 KiB L2: 1024 KiB
    desc: 4x256 KiB L3: 8 MiB desc: 1x8 MiB
  Speed (MHz): avg: 800 min/max: 800/3600 scaling: driver: intel_pstate
    governor: powersave cores: 1: 800 2: 800 3: 800 4: 800 5: 800 6: 800 7: 800
    8: 800 bogomips: 43198
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
  Vulnerabilities: <filter>
Graphics:
  Device-1: Intel HD Graphics 530 vendor: Dell driver: i915 v: kernel
    arch: Gen-9 process: Intel 14n built: 2015-16 ports: active: eDP-1
    empty: DP-4, DP-5, DP-6, HDMI-A-1, HDMI-A-2, HDMI-A-3 bus-ID: 0000:00:02.0
    chip-ID: 8086:191b class-ID: 0300
  Device-2: NVIDIA GM107GLM [Quadro M2000M] vendor: Dell driver: nvidia
    v: 560.35.03 alternate: nouveau,nvidia_drm non-free: 550.xx+ status: current
    (as of 2024-09; EOL~2026-12-xx) arch: Maxwell code: GMxxx
    process: TSMC 28nm built: 2014-2019 ports: active: none
    empty: DP-1, DP-2, DP-3, VGA-1 bus-ID: 0000:01:00.0 chip-ID: 10de:13b0
    class-ID: 0300
  Device-3: Realtek Integrated_Webcam_HD driver: uvcvideo type: USB rev: 2.0
    speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 1-11:4 chip-ID: 0bda:5686
    class-ID: 0e02 serial: <filter>
  Display: wayland server: X.org v: 1.21.1.13 with: Xwayland v: 24.1.2
    compositor: kwin_wayland driver: X: loaded: modesetting,nvidia
    unloaded: nouveau alternate: fbdev,intel,nv,vesa dri: iris
    gpu: i915,nvidia display-ID: 0
  Monitor-1: eDP-1 res: 1829x1029 size: N/A modes: N/A
  API: EGL v: 1.5 hw: drv: intel iris drv: nvidia platforms: device: 0
    drv: nvidia device: 2 drv: iris device: 3 drv: swrast gbm: drv: nvidia
    surfaceless: drv: nvidia wayland: drv: iris x11: drv: iris
    inactive: device-1
  API: OpenGL v: 4.6.0 compat-v: 4.5 vendor: intel mesa v: 24.2.3-arch1.1
    glx-v: 1.4 direct-render: yes renderer: Mesa Intel HD Graphics 530 (SKL GT2)
    device-ID: 8086:191b memory: 15.19 GiB unified: yes display-ID: :1.0
  API: Vulkan v: 1.3.295 layers: 11 device: 0 type: integrated-gpu
    name: Intel HD Graphics 530 (SKL GT2) driver: mesa intel v: 24.2.3-arch1.1
    device-ID: 8086:191b surfaces: xcb,xlib,wayland device: 1
    type: discrete-gpu name: Quadro M2000M driver: nvidia v: 560.35.03
    device-ID: 10de:13b0 surfaces: xcb,xlib,wayland device: 2 type: cpu
    name: llvmpipe (LLVM 18.1.8 256 bits) driver: mesa llvmpipe
    v: 24.2.3-arch1.1 (LLVM 18.1.8) device-ID: 10005:0000
    surfaces: xcb,xlib,wayland
Audio:
  Device-1: Intel 100 Series/C230 Series Family HD Audio vendor: Dell
    driver: snd_hda_intel v: kernel alternate: snd_soc_avs bus-ID: 0000:00:1f.3
    chip-ID: 8086:a170 class-ID: 0403
  Device-2: NVIDIA GM107 High Definition Audio [GeForce 940MX] vendor: Dell
    driver: snd_hda_intel v: kernel bus-ID: 0000:01:00.1 chip-ID: 10de:0fbc
    class-ID: 0403
  API: ALSA v: k6.10.10-zen1-1-zen status: kernel-api with: aoss
    type: oss-emulator tools: N/A
  Server-1: sndiod v: N/A status: off tools: aucat,midicat,sndioctl
  Server-2: PipeWire v: 1.2.4 status: active with: 1: pipewire-pulse
    status: active 2: wireplumber status: active 3: pipewire-alsa type: plugin
    4: pw-jack type: plugin tools: pactl,pw-cat,pw-cli,wpctl
Network:
  Device-1: Intel Ethernet I219-LM vendor: Dell driver: e1000e v: kernel
    port: N/A bus-ID: 0000:00:1f.6 chip-ID: 8086:15b7 class-ID: 0200
  IF: enp0s31f6 state: down mac: <filter>
  Device-2: Intel Wireless 8260 driver: iwlwifi v: kernel
    bus-ID: 0000:02:00.0 chip-ID: 8086:24f3 class-ID: 0280
  IF: wlp2s0 state: up mac: <filter>
  Info: services: NetworkManager, systemd-timesyncd, wpa_supplicant
RAID:
  Hardware-1: Intel SATA Controller [RAID mode] driver: intel_nvme_remap
    v: N/A port: f060 bus-ID: 0000:00:17.0 chip-ID: 8086:2822 rev: N/A
    class-ID: 0104
Drives:
  Local Storage: total: 931.51 GiB used: 25.94 GiB (2.8%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Fanxiang model: S690Q 1TB
    size: 931.51 GiB block-size: physical: 512 B logical: 512 B tech: SSD
    serial: <filter> fw-rev: VF001C30 temp: 34.9 C scheme: GPT
Partition:
  ID-1: / raw-size: 32 GiB size: 32 GiB (100.00%) used: 21.62 GiB (67.6%)
    fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
  ID-2: /boot/efi raw-size: 1024 MiB size: 1022 MiB (99.80%)
    used: 27.4 MiB (2.7%) fs: vfat dev: /dev/nvme0n1p3 maj-min: 259:3
  ID-3: /home raw-size: 447.65 GiB size: 447.65 GiB (100.00%)
    used: 4.3 GiB (1.0%) fs: btrfs dev: /dev/nvme0n1p5 maj-min: 259:5
  ID-4: /var/log raw-size: 32 GiB size: 32 GiB (100.00%)
    used: 21.62 GiB (67.6%) fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
  ID-5: /var/tmp raw-size: 32 GiB size: 32 GiB (100.00%)
    used: 21.62 GiB (67.6%) fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
Swap:
  Kernel: swappiness: 2 (default 60) cache-pressure: 100 (default) zswap: no
  ID-1: swap-1 type: zram size: 31.11 GiB used: 0 KiB (0.0%) priority: 100
    comp: zstd avail: lzo,lzo-rle,lz4,lz4hc,842 max-streams: 8 dev: /dev/zram0
Sensors:
  System Temperatures: cpu: 59.0 C pch: 48.5 C mobo: 46.0 C
  Fan Speeds (rpm): cpu: 2623 fan-2: 2614
Info:
  Memory: total: 32 GiB available: 31.11 GiB used: 4.67 GiB (15.0%)
  Processes: 310 Power: uptime: 37m states: freeze,mem,disk suspend: deep
    avail: s2idle wakeups: 0 hibernate: platform avail: shutdown, reboot,
    suspend, test_resume image: 12.4 GiB services: org_kde_powerdevil,
    power-profiles-daemon, upowerd Init: systemd v: 256 default: graphical
    tool: systemctl
  Packages: pm: pacman pkgs: 1933 libs: 547 tools: octopi,paru Compilers:
    clang: 18.1.8 gcc: 14.2.1 Shell: garuda-inxi default: fish v: 3.7.1
    running-in: konsole inxi: 3.3.36
Garuda (2.6.26-1):
  System install date:     2024-09-20
  Last full system update: 2024-09-23
  Is partially upgraded:   Notype or paste code here
  Relevant software:       snapper NetworkManager dracut nvidia-dkms
  Windows dual boot:       Probably (Run as root to verify)
  Failed units:

A safe way to remove orphans like this is with the cleanup Fish function which is included in the default Fish config. garuda-fish-config/config.fish · main · Garuda Linux 🦅 / PKGBUILDs · GitLab

# Cleanup local orphaned packages
function cleanup
    while pacman -Qdtq
        sudo pacman -R (pacman -Qdtq)
        if test "$status" -eq 1
           break
        end
    end
end

This is safer than the method suggested in the ArchWiki because pacman -Rns removes the orphaned packages and their unneeded dependencies recursively, which might remove packages that are optional dependencies of other installed packages.

The Fish function removes only true orphans (without touching any dependencies), then when it finishes it checks again and removes any new orphans, and so on until there are no remaining orphaned packages. This way only actual orphaned packages are removed.

If you would prefer a Bash solution you could use a one-liner like this:

while pacman -Qdtq &>/dev/null; do sudo pacman -R $(pacman -Qdtq) || break; done

It may be worth mentioning that certain things can cause packages you want to keep to become orphans. Always be sure to carefully inspect the package removal list to be sure you don’t accidentally remove something you need.

If a package you want to keep becomes an orphan, you can mark it as explicitly installed to drop it’s orphaned status.

sudo pacman -D --asexplicit [some_package]
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.