Skip to content

Package management

Commands

add-apt-repository

APT repositories (/etc/apt/sources.list) are made of three parts, delimited by whitespace:

  • Source type: deb for binary packages or deb-src for source packages
  • Base URL of the source: beginning with http://, ftp://, file://, or even cdrom:
  • Name of the chosen distribution followed by sections that differentiate packages by license. Kali contains main, non-free, and contrib.
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ bionic main restricted
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ bionic universe
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ bionic-updates universe
add-apt-repository "deb http://security.ubuntu.com/ubuntu trusty-security main universe" # Ubuntu
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # Docker
add-apt-repository "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" # gcloud
add-apt-repository "deb http://security.ubuntu.com/ubuntu trusty-security main universe" # mailx
add-apt-repository "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" # MongoDB
add-apt-repository -y "ppa:kgilmer/regolith-stable" # Regolith Linux

apt-key

apt-key is typically used by piping a GPG key from curl.

# Google Cloud SDK
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - 
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

# Docker in WSL
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 

Add key specified by apt in error message

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68980A0EA10B4DE8

Install key from Mono

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

apt

dnf

View history of dnf commands

dnf history
dnf history userinstalled # View all packages installed by user

Package groups can be specified using the group command or by prefixing the package group name with @

dnf info @virtualization # dnf group info virtualization
dnf install @virtualization # dnf group install virtualization
dnf install --with-optional @virtualization # Include optional packages

Remove the configuration backend supporting the use of legacy ifcfg files in NetworkManager.

dnf remove NetworkManager-initscripts-ifcfg-rh

Modules are special package groups representing an application, runtime, or a set of tools. The Node.js module allows you to select several streams corresponding to major versions.

dnf module install nodejs:12

Global dnf configuration is stored in either /etc/yum.conf or /etc/dnf.conf.

[main]
; Exclude packages from updates permanently
exclude=kernel* php*
; Suppress confirmation
assumeyes=True

The configuration can be dumped from the command-line (as root)

dnf config-manager --dump

Repos

Repositories are INI files placed in /etc/yum.repos.d/, but they can also be displayed and manipulated from the command-line.

Repositories
# Display repos
dnf repolist # -v

# Display enabled repos
dnf repolist --enabled

# Display a single repo
dnf repoinfo docker-ce-stable

# Add repo
dnf config-manager --add-repo $REPO-URL

# Disable repo
dnf config-manager --set-disabled $REPO-NAME
Example repos
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/fedora/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/fedora/gp

[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

Modules are collections of packages that are installed together. They often also have profiles available, which are variants of the module: i.e. client, server, common, devel, etc.

dnf module list php
dnf module install php:7.4/devel
dnf module reset php

flatpak

Flatpak is one of several recent containerized application distribution solutions for Linux.

Flatpak runtimes are compiled reproducibly using BuildStream and they are installed in /var/lib/flatpak/runtime. Like Steam, flatpak uses BubbleWrap to implement sandboxing.

Flathub is the de facto Flatpak repo, but it must be added to flatpak installations manually.

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

# Confirming success
flatpak remotes 

Display installed flatpak applications, including runtime

flatpak list --app --runtime

Output columns can also be specified individually after --column (comma-delimited)

flatpak list --app --columns=name,application,runtime

Flatpak applications sometimes do not adopt the system theme. The workaround involves first granting some or all applications access to the themes folder.

flatpak override --filesystem=$HOME/.themes

Then apply the theme by setting the GTK_THEME environment variable. The value of this variable must be the folder name of a theme installed to the themes folder (typically ~/.themes).

flatpak override --env=GTK_THEME=my-theme 

The value of the current theme can be retrieved using gsettings

gsettings get org.gnome.desktop.interface gtk-theme

pacman

pacman -Q # --query

Display all orphaned dependencies (no longer needed)

pacman -Qdt # --query --deps --unrequired

Display only explicitly installed packages and versions

pacman -Qe # --query --explicit

Display explicitly installed packages, limiting output to program names

pacman -Qeq # pacman --query --explicit --quiet

Display all packages installed from the AUR

pacman -Qm # --query --foreign

Display all packages installed from main repos

pacman -Qn # --query --native

Find which package owns {file}

pacman -Qo file # --query --owns

List all install packages, filtering output to packages that are out-of-date on the local system

pacman -Qu # --query --upgrades

Remove $PACKAGE

pacman -R $PACKAGE # --remove package

Remove $PACKAGE, dependencies, and config files

pacman -Rns $PACKAGE # --remove --recursive --nosave

Remove $PACKAGE as well as its dependencies

pacman -Rs # --remove --recursive

Install $PACKAGE from the AUR

pacman -S $PACKAGE # --sync

Remove all packages from the cache as well as unused sync databases

pacman -Scc # --sync --clean --clean

Display information about {package}

pacman -Si $PACKAGE # --sync --info package

Search for $PACKAGE in AUR repos

pacman -Ss $PACKAGE # --sync --search package

Search for packages matching $PATTERN

pacman -Ss $PATTERN # --sync --search pattern

Update package database

pacman -Sy #  --sync --refresh

Update all packages from AUR and official repos

pacman -Syu # --sync --refresh --sysupgrade

Force refresh of all package databases, even if they appear to be up-to-date

pacman -Syy # --sync --refresh --refresh

Download program updates but don't install them

pacman -Syyuw # --sync --refresh --refresh --sysupgrade --downloadonly

Get number of total installed packages

pacman -Q | wc -l

rpm

Query repos for information on a package

rpm -qi $PACKAGE # --query --info

Upgrade or install a package, with progress bars

rpm -Uvh $PACKAGE # --upgrade --verbose --hash

Display version of Fedora

rpm -E %fedora

Import a keyring

rpm --import "https://build.opensuse.org/projects/home:manuelschneid3r/public_key"

snap

Snap is one of several recent containerized application distribution solutions for Linux.

Snap apps are slow to start because data is stored in squashfs images.

Installation

dnf install -y snapd
ln -s /var/lib/snapd/snap /snap