How to Install Software on Linux

How to Install Software on Linux

Reading time1 min
#Linux#Ubuntu#Software#PackageManagement#Snap#Flatpak

How to Install Software on Linux

Linux does not install programs by downloading an installer from a website. Each distribution has a package manager that downloads software from signed repositories, resolves dependencies and updates everything together. Use it first, and reach for other methods only when it does not have what you need.

A sensible order of preference:

  1. The distribution's package manager (apt, dnf, pacman, zypper).
  2. The vendor's own signed repository, which then updates with the rest of the system.
  3. Flatpak or Snap, mostly for desktop applications or newer versions.
  4. A single .deb, .rpm or AppImage file.
  5. A tarball: a prebuilt binary or source code you compile.

Desktop users can do most of this in a GUI: App Center on Ubuntu, GNOME Software on Fedora and Debian GNOME, Discover on KDE. The terminal commands below are what those tools run underneath, and they work on servers too.

Which package manager you have

cat /etc/os-release

The ID and ID_LIKE lines tell you the family.

FamilyToolInstallSearchRemoveUpdate everything
Debian, Ubuntu, Mintaptsudo apt install tmuxapt search tmuxsudo apt remove tmuxsudo apt update && sudo apt upgrade
Fedora, RHEL 8+, Rocky, Alma, Amazon Linux 2023dnfsudo dnf install tmuxdnf search tmuxsudo dnf remove tmuxsudo dnf upgrade
Arch, Manjaropacmansudo pacman -S tmuxpacman -Ss tmuxsudo pacman -Rs tmuxsudo pacman -Syu
openSUSE, SLESzyppersudo zypper install tmuxzypper search tmuxsudo zypper remove tmuxsudo zypper update

On Arch, install new packages with sudo pacman -Syu tmux rather than -Sy tmux: refreshing the database without upgrading leaves a partially upgraded system.

Ubuntu and Debian: apt

sudo apt update              # refresh package lists first
apt show tmux                # version, size, description
sudo apt install tmux
sudo apt purge tmux          # remove including config files
sudo apt autoremove          # drop dependencies nothing needs any more

apt and apt-get use the same engine. apt is the friendlier interactive command; apt-get has a stable interface, so use it in scripts and Dockerfiles.

To install a specific version and keep it from being upgraded:

apt policy my-package                    # available versions
sudo apt install my-package=1.2.3-1      # exact string from apt policy
sudo apt-mark hold my-package

Third-party repositories should use a dedicated keyring referenced with Signed-By, not apt-key, which is deprecated:

sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://example.com/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg
sudo tee /etc/apt/sources.list.d/example.sources > /dev/null <<'EOF'
Types: deb
URIs: https://example.com/apt
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/example.gpg
EOF
sudo apt update

PPAs (sudo add-apt-repository ppa:owner/name) are Ubuntu-only community repositories. Their packages run as root like any other, so add only ones you trust.

Installing apt or apt-get

You do not. Every Debian and Ubuntu system ships with apt, and apt-get is part of the same package. On Fedora, RHEL or Arch, installing apt would manage a separate package database the system ignores, so use the native tool instead.

If apt itself is broken on Ubuntu, repair it with sudo dpkg --configure -a and sudo apt --fix-broken install. If the binary is damaged, download the apt and libapt-pkg packages for your exact release from packages.ubuntu.com or packages.debian.org and install them with sudo dpkg -i.

In Docker images, "Unable to locate package" usually means the package lists are empty: run apt-get update before apt-get install.

Fedora and RHEL family: dnf

dnf search tmux
dnf info tmux
sudo dnf install tmux
dnf provides '*/bin/rg'      # which package ships a file
sudo dnf upgrade

On RHEL 8 and later, Rocky, AlmaLinux, Fedora and Amazon Linux 2023, yum is only a link to dnf, so there is nothing to install. Fedora 41 and later use dnf5 with the same everyday commands. Do not install yum on Ubuntu: it would not manage Ubuntu's packages.

Many extra tools for the RHEL family live in EPEL. On Rocky Linux and AlmaLinux:

sudo dnf config-manager --set-enabled crb
sudo dnf install epel-release

Snap

Snaps are self-contained, sandboxed packages from Canonical's store that update automatically. Ubuntu ships snapd preinstalled.

snap find vlc
sudo snap install vlc
sudo snap install code --classic    # classic: no sandbox, full system access
snap list
sudo snap refresh                   # update now instead of waiting
sudo snap remove vlc

On other distributions install the daemon first:

sudo apt install snapd                         # Debian
sudo dnf install snapd                         # Fedora
sudo ln -s /var/lib/snapd/snap /snap           # Fedora, needed for classic snaps

Log out and back in (or reboot) so /snap/bin ends up in your PATH.

Flatpak

Flatpak is the cross-distribution format most desktop apps target, with Flathub as the main repository. Fedora ships it; on Ubuntu and Debian install it and add Flathub:

sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
flatpak install flathub org.videolan.VLC
flatpak run org.videolan.VLC
flatpak update
flatpak uninstall --unused

Log out and back in after the first install so the apps show up in the menu.

AppImage

An AppImage is a single executable file that bundles the app and its libraries:

chmod +x My-App-1.2.3-x86_64.AppImage
./My-App-1.2.3-x86_64.AppImage

Many AppImages need FUSE 2. On Ubuntu 24.04 and later install libfuse2t64, on 22.04 libfuse2. AppImages do not update themselves and do not add a menu entry, so keep them in one place such as ~/Applications.

Tarballs with a prebuilt binary

Many CLI tools ship as a .tar.gz with one binary inside:

curl -LO https://example.com/releases/my-tool-1.2.3-linux-amd64.tar.gz
curl -LO https://example.com/releases/my-tool-1.2.3-linux-amd64.tar.gz.sha256
sha256sum -c my-tool-1.2.3-linux-amd64.tar.gz.sha256
tar -xf my-tool-1.2.3-linux-amd64.tar.gz
sudo install -m 0755 my-tool /usr/local/bin/my-tool

tar -xf detects gzip, xz, bzip2 and zstd compression by itself. Applications that come with their own directory tree go under /opt with a symlink:

sudo tar -xf my-app-1.2.3-linux-x64.tar.gz -C /opt
sudo ln -s /opt/my-app-1.2.3/bin/my-app /usr/local/bin/my-app

Tarballs with source code

Read the project's README or INSTALL first. Classic autotools projects build like this:

sudo apt install build-essential     # Fedora/RHEL: sudo dnf install gcc gcc-c++ make
tar -xf my-app-1.2.3.tar.gz
cd my-app-1.2.3
./configure --prefix=/usr/local
make -j"$(nproc)"
sudo make install

Projects using CMake or Meson have their own commands. When configure complains about a missing header, install the matching development package (-dev on Debian/Ubuntu, -devel on Fedora/RHEL). The package manager does not track files from make install, so keep the build directory: sudo make uninstall works only if the project provides that target.

Where programs get installed

  • /usr/bin, /usr/lib: owned by the package manager. Never copy files there by hand.
  • /usr/local/bin: programs you install manually for all users. The default prefix of most source builds, and in PATH everywhere.
  • /opt/app-name: self-contained vendor applications with their own directory tree.
  • ~/.local/bin: per-user programs, no sudo. Tools such as pipx use it. Ubuntu's default ~/.profile adds it to PATH when the directory exists.
  • /snap/bin and /var/lib/flatpak: Snap and Flatpak.

To find what you are actually running and where it came from:

command -v tmux
dpkg -S "$(command -v tmux)"     # Debian/Ubuntu: owning package
rpm -qf "$(command -v tmux)"     # Fedora/RHEL: owning package

Quick reference

sudo apt update && sudo apt install name     # Debian, Ubuntu
sudo dnf install name                        # Fedora, RHEL, Rocky, Alma, AL2023
sudo pacman -Syu name                        # Arch
sudo zypper install name                     # openSUSE
sudo snap install name                       # Snap
flatpak install flathub app.id               # Flatpak
chmod +x App.AppImage && ./App.AppImage      # AppImage
sudo install -m 0755 tool /usr/local/bin/    # single binary from a tarball
./configure && make && sudo make install     # source build