How To Install A Package In Linux

How To Install A Package In Linux

Reading time1 min
#Linux#OpenSource#Software#PackageManagement#LinuxPackages

Mastering Package Installation on Linux: Beyond Apt and Yum

Not all Linux environments fit the typical apt/yum mold. Enterprise stack on CentOS 7, rolling labs on Arch, headless containers, custom build servers—each presents unique software installation challenges. Package management strategy impacts maintainability, security patching, and future migration. Over-reliance on just apt or yum often leads to stale software and brittle systems.


When Apt and Yum Fall Short

Consider these recurring problems:

  • The app isn’t in your distro’s main repos.
  • Maintainers lag three releases behind upstream; you need a critical bugfix.
  • Default packages ship without necessary compile-time flags (e.g., OpenSSL support).
  • You’re scripting deployment for containerized Alpine, not Ubuntu or RHEL.

Workarounds exist. Each has trade-offs.


Alternatives: Targeted Package Management

Arch-Based? Use pacman and the AUR

pacman delivers a balance: fast binary installs and robust dependency tracking.
Arch-based systems (e.g., Manjaro, Arch Linux ARM) rely on it.

sudo pacman -S neofetch

For packages outside the official repos, the AUR (Arch User Repository) is the de facto solution. Use an AUR helper like yay:

yay -S google-chrome

Caution: AUR packages are user-contributed. Review PKGBUILDs for privilege escalations or embedded curl|bash patterns before install.


openSUSE: zypper for Enterprise Environments

zypper excels at transactional updates and advanced dependency resolution.

sudo zypper install vim

Noteworthy feature: zypper can roll back to pre-update snapshots (when using Btrfs). For mission-critical systems, this is invaluable.


Containerized Apps: Snap and Flatpak

Snap (Canonical) and Flatpak (GNOME/Red Hat) introduce distro-agnostic packaging. Both isolate app dependencies, albeit with higher disk usage.

Snap Example

Install snapd (if missing) and VLC:

sudo apt install snapd
sudo snap install vlc --classic

Notes:

  • Snap packages often have longer cold-start times due to confinement overhead.
  • Auto-updates run in the background: manual pinning isn’t standard.

Flatpak Example

On Fedora 39 or Ubuntu 22.04+:

sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install flathub org.gimp.GIMP
flatpak run org.gimp.GIMP

Gotcha: Host/user theme consistency isn’t guaranteed—some Flatpak apps look visually off until corresponding host themes are installed as Flatpak extensions.


AppImage: Portable, No-Install Binaries

No root? No problem. Download, set executable permissions, and run:

wget https://github.com/obsproject/obs-studio/releases/download/30.0.2/OBS-Studio-30.0.2-x86_64.AppImage
chmod +x OBS-Studio-30.0.2-x86_64.AppImage
./OBS-Studio-30.0.2-x86_64.AppImage

No dependency pollution; ideal for isolated testing, but no centralized update mechanism. Not suited for system-wide deployment.


The Old-School: Compiling from Source

Sometimes you want maximum control—a particular OpenSSL version, build with custom --enable-feature flags, or bleeding-edge git master.

Typical flow:

  1. Install build dependencies.
    On Ubuntu 22.04:
    sudo apt update && sudo apt install build-essential git pkg-config libssl-dev
    
  2. Fetch upstream code.
    git clone https://github.com/example/project.git
    cd project
    
  3. Configure (or CMake):
    ./configure --prefix=/usr/local --enable-optimizations
    # or
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local .
    
  4. Build and install.
    make -j$(nproc)
    sudo make install
    
  5. Verify:
    /usr/local/bin/project --version
    

Tip:
Prefer checkinstall over make install to generate and register a local .deb or .rpm for future removal:

sudo checkinstall --pkgname=project --pkgversion=1.0

Known issue:
Manual builds bypass your package manager; orphaned libraries can accumulate. Maintain a build log or automation (e.g., Ansible playbook) for reproducibility.


Reference Table: Package Managers and Install Methods

Tool/MethodCommand ExampleTypical Use CaseDistros Covered
aptsudo apt install htopMainline installs, security patchesUbuntu, Debian
yum / dnfsudo dnf install htopEnterprise-grade, system-wide updatesRHEL, Fedora, CentOS
pacmansudo pacman -S htopRolling, minimal base, rapid turnaroundArch, Manjaro
zyppersudo zypper install htopSnapshot + rollback, large enterprise stacksopenSUSE
snapsudo snap install --classic codeSandboxed, auto-updated desktop/server appsCross-distro
flatpakflatpak install flathub ...UI-heavy, sandboxed, cross-distro desktopCross-distro
AppImage./AppName-x86_64.AppImageSingle-binary, portable, no install overheadMost desktop distros
Source Build./configure && make && make installCustom compile-time features or patchesAny w/ build tools

Non-Obvious Tips and Pitfalls

  • Source-built binaries may shadow distro-packaged binaries if PATH isn’t curated—review /usr/local/bin vs /usr/bin.
  • Automate post-installation QA: ldd your-binary will catch missing shared libs.
  • For security: always check hash/signature of AppImages or source tarballs before execution.
  • Pin major apps to proven stable versions, but monitor for CVEs; package managers often lag (see the OpenSSL 3.0.7 debacle).
  • Flatpak and Snap eat disk space quickly—periodically clear unused runtimes.

Package installation defines the maintainability of your Linux hosts. Knowing the right toolchain—and when to escape the defaults—translates directly into uptime and operational agility. For anything outside the happy path, invest in reproducibility: scripts, logs, and version pinning. The quickest fix is rarely the most future-proof.


Questions or production horror stories about package upgrades? Leave details—real-world cases drive smarter solutions.