Package Management
What is a Package Manager
From wikipedia:
A package manager or package management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer's operating system in a consistent manner.
dpkg (Debian Package Manager)
Install a local .deb
package in Ubuntu:
$ dpkg -i filename.deb
List pakcages:
$ dpkg -l
Check all installed packages
$ dpkg --get-selections
$ dpkg --get-selections | grep mongo
dpkg
is a backend-ish tool, usually we do not need to use it directly. Check other options in $ man dpkg
.
check where the command is coming from
$ dpkg -S /bin/ls
$ dpkg -S $(which ls)
$ dpkg -S /usr/bin/ssh
openssh-client: /usr/bin/ssh
$ dpkg -S /bin/grep
grep: /bin/grep
Note that
-S
for search-s
for status
Get details about the package:
$ dpkg -s coreutils
coreutils: /bin/ls
error: parsing file ... near line 0
Error:
dpkg: error: parsing file '/var/lib/dpkg/updates/0004' near line 0:
Verify:
$ head /var/lib/dpkg/updates/0004
#padding
#padding
#padding
#padding
Fix:
$ cd /var/lib/dpkg/updates && rm -rf 0004
$ sudo dpkg --configure -a
Apt
apt
can be considered a front-end to dpkg
.
apt
is a simplified command that combines the most commonly used command options from apt-get
and apt-cache
.
apt Commands
$ sudo apt install <package>
$ sudo apt install <package>=<version> # Install a specific version
$ sudo apt search <package>
$ sudo apt show <package>
$ sudo apt update
$ sudo apt list --upgradable
$ sudo apt list --installed
$ sudo apt upgrade
$ apt-cache stats: get stats of the packages
$ apt-cache pkgnames | grep docker
How to list available packages
# list available packages
$ apt-cache search KEYWORD
# e.g. search for Chrome
$ apt-cache search google-chrome
google-chrome-stable - The web browser from Google
$ apt install google-chrome-stable
apt update vs apt upgrade vs apt dist-upgrade
apt update
will only check the latest versions of the packages, without actually downloading package updates;apt upgrade
will do the actual upgrading;apt dist-upgrade
is for upgrading the OS itself.
Where do the packages come from?
They come from "repositories" listed in
/etc/apt/sources.list
/etc/apt/sources.list.d/
Personal Package Archives (PPAs) are software repositories designed for Ubuntu users and are easier to install than other third-party repositories. PPAs are often used to distribute pre-release software so that it can be tested.
Snap
Snaps now work natively on Arch, Debian, Fedora, and different flavors of Ubuntu.
Unlike Flatpak, Ubuntu's Snappy tools are equally suitable for packaging command-line programs and operating system components.
Why Snap
"With snap packages, applications are installed in their own container, and all the third-party applications are installed with them so there are no version conflicts." This allows users to update and roll back applications without causing problems to the rest of their operating system. It also comes with security benefits because applications are more isolated from each other and from core parts of the OS than they normally would be.
How to Create Snap Package
Flatpak
"The Future of Apps on Linux".
Flatpak is strongly aimed at graphical desktop applications.