Linux package management

From Ever changing code
Jump to navigation Jump to search

Apt-get

List all configured software sources

grep -r --include '*.list' '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/

List all installed packages, search wit dash '/'. Remove grep to display headers

dpkg -l | grep ii | less

Search within the package descriptions you've already downloaded to find the package that's got the feature you're looking for. REGEX (regular expressions) is expected after 'search' and any keystrokes that mean something to your command shell (e.g. [|?*] ) you'll need to quote them so that apt-cache will be able to see them instead of having the shell expand the term to a list of file names that mean something else entirely.

apt-cache search tunnel
apt-cache search 'php.*sql'
apt-cache search apache.\*perl
apt-cache search elvis\|vim
Display info about a package
apt-cache show gns3
Check an available package verison in a repository
$ apt-cache policy gns3
gns3:
  Installed: (none)
  Candidate: 0.8.6-3ubuntu1
  Version table:
     0.8.6-3ubuntu1 0
        500 http://gb.archive.ubuntu.com/ubuntu/ trusty/multiverse amd64 Packages

Install a specific version

sudo apt-get install ansible=<version>
sudo apt-cache policy ansible      #show available packages and its primary install candidate 
sudo apt-cache showpkg ansible     #shows details about available packages including dependencies
sudo apt-cache showpkg ansible
Package: ansible
Versions: 
2.0.1.0-1ppa~trusty (/var/lib/apt/lists/ppa.launchpad.net_ansible_ansible_ubuntu_dists_trusty_main_binary-amd64_Packages)
Description Language: 
                File: /var/lib/apt/lists/ppa.launchpad.net_ansible_ansible_ubuntu_dists_trusty_main_binary-amd64_Packages
                 MD5: ddfdff3530378f98f78630ce2aed5fe8
Description Language: en
                File: /var/lib/apt/lists/ppa.launchpad.net_ansible_ansible_ubuntu_dists_trusty_main_i18n_Translation-en
                 MD5: ddfdff3530378f98f78630ce2aed5fe8

1.7.2+dfsg-1~ubuntu14.04.1 (/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_trusty-backports_universe_binary-amd64_Packages)
Description Language: 
                File: /var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_trusty_universe_binary-amd64_Packages
                 MD5: db2b21b0d2286fccc4401d5982361488

1.5.4+dfsg-1 (/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_trusty_universe_binary-amd64_Packages)
Description Language: 
                File: /var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_trusty_universe_binary-amd64_Packages
                 MD5: db2b21b0d2286fccc4401d5982361488

Reverse Depends: 
  ansible-fireball,ansible
  ansible-fireball,ansible
Dependencies: 
2.0.1.0-1ppa~trusty - python (0 (null)) python-support (2 0.90) python-jinja2 (0 (null)) python-yaml (0 (null)) python-paramiko (0 (null)) python-httplib2 (0 (null)) python-six (0  sshpass (0 (null)) 
Provides: 
2.0.1.0-1ppa~trusty - 
1.7.2+dfsg-1~ubuntu14.04.1 - 
1.5.4+dfsg-1 - 
Reverse Provides: 
sudo apt-cache policy ansible
ansible:
  Installed: (none)
  Candidate: 2.0.1.0-1ppa~trusty
  Version table:
     2.0.1.0-1ppa~trusty 0
        500 http://ppa.launchpad.net/ansible/ansible/ubuntu/ trusty/main amd64 Packages
     1.7.2+dfsg-1~ubuntu14.04.1 0
        100 http://gb.archive.ubuntu.com/ubuntu/ trusty-backports/universe amd64 Packages
     1.5.4+dfsg-1 0
        500 http://gb.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages

Package sources management

sudo add-apt-repository          http://apt.keepsolid.com/ubuntu
sudo add-apt-repository --remove http://apt.keepsolid.com/ubuntu

Signed packages

Fix missing package signing key

The apt packaging system has a set of trusted keys that determine whether a package can be authenticated and therefore trusted to be installed on the system. Sometimes the system does not have all the keys it needs and runs into this issue. Fortunately, there is a quick fix. Each key that is listed as missing needs to be added to the apt key manager so that it can authenticate the packages.

Error

Error: https://apt.releases.hashicorp.com focal InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AA16FCBCA621E701


Fix

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA16FCBCA621E701
Executing: /tmp/apt-key-gpghome.qhiPACEaom/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys AA16FCBCA621E701
gpg: key AA16FCBCA621E701: public key "HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Yum

It it a default package management in the following and many other RPM-based Linux distributions:

  • Amazon Linux AMI
  • Red Hat Enterprise Linux
  • Fedora
  • CentOS

Usage

System update

sudo yum update

Install package

sudo yum install nagios

Package description

$ yum info nagios
Loaded plugins: priorities, update-motd, upgrade-helper
Installed Packages
Name        : nagios
Arch        : x86_64
Version     : 3.5.1
Release     : 1.6.amzn1
Size        : 5.3 M
Repo        : installed
From repo   : amzn-main
Summary     : Nagios monitors hosts and services and yells if somethings breaks
URL         : http://www.nagios.org/
License     : GPLv2
Description : Nagios is a program that will monitor hosts and services on your
            : network.  It has the ability to send email or page alerts when a
            : problem arises and when a problem is resolved.  Nagios is written
            : in C and is designed to run under Linux (and some other *NIX
            : variants) as a background process, intermittently running checks
            : on various services that you specify.
            :
            : The actual service checks are performed by separate "plugin" programs
            : which return the status of the checks to Nagios. The plugins are
            : available at http://sourceforge.net/projects/nagiosplug.
            :
            : This package provides the core program, web interface, and documentation
            : files for Nagios. Development files are built as a separate package.

List available packages

yum list [available|installed|extras|updates|obsoletes|all|recent] [pkgspec] 
yum list available | less
yum list available | grep package

Nala

Nala is a front-end for libapt-pkg, the interface is using the python-apt api. It takes the most of the apt-get options and it aims to show specifically what will happen with a package during install, removal, or an upgrade.

# Install
## Option 1. Ubuntu 22.04 / Debian Testing/Sid
echo "deb-src https://deb.volian.org/volian/ scar main" | sudo tee -a /etc/apt/sources.list.d/volian-archive-scar-unstable.list
wget -qO - https://deb.volian.org/volian/scar.key | sudo tee /etc/apt/trusted.gpg.d/volian-archive-scar-unstable.gpg > /dev/null
sudo apt update && sudo apt install nala

## Option 2.
Navigate to releases page https://gitlab.com/volian/nala/-/releases
wget https://deb.volian.org/volian/pool/main/n/nala-legacy/nala-legacy_0.11.0_amd64.deb

# Usage
sudo nala update
nala list --upgradable
sudo nala upgrade

Commands:
  autopurge   Autopurge packages that are no longer needed.
  autoremove  Autoremove packages that are no longer needed.
  clean       Clear out the local archive of downloaded package files.
  fetch       Fetch fast mirrors to speed up downloads.
  history     Show transaction history.
  install     Install packages.
  list        List packages based on package names.
  purge       Purge packages.
  remove      Remove packages.
  search      Search package names and descriptions.
  show        Show package details.
  update      Update package list.
  upgrade     Update package list and upgrade the system.

# Auto completion
nala --install-completion bash
  bash completion installed in /home/vagrant/.local/share/bash-completion/completions/nala.bash
  Completion will take effect once you restart the terminal


Update

sudo nala update
[sudo] password for piotr: 
Error: https://packages.cloud.google.com/apt cloud-sdk InRelease
  The following signatures couldn t be verified because the public key is not available: NO_PUBKEY B53DC80D13EDEF05
╭─ Updating Package List ───────────────────────────────────────────────────────────────────────────────────────────╮
│No Change: https://apt.releases.hashicorp.com jammy InRelease                                                      │
│No Change: https://updates.signal.org/desktop/apt xenial InRelease                                                 │
│No Change: http://archive.ubuntu.com/ubuntu jammy InRelease                                                        │
│No Change: https://dl.google.com/linux/chrome/deb stable InRelease                                                 │
│Updated:   http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 KB]                                       │
│Updated:   http://archive.ubuntu.com/ubuntu jammy-security/universe amd64 DEP-11 Metadata [13 KB]                  │
│Fetched 3.6 MB in 1s (0 Bytes/s)                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

References