Packages
On Linux distributions, packages are archives used to share:
- π Libraries (.a and .so files)
- βοΈ Documentation (packagename-doc)
- π Headers (packagename-dev)
- πΉοΈ Applications (binaries)
- ...
Each operating system has a package management system to install and remove packages. We usually don't directly interact with it, and we use a package management tool instead. They allow us to download packages from package repositories and update them too.
In a nutshell, we often see these combinations:
Package System π₯οΈ | Package Tool π οΈ | Package format ποΈ |
---|---|---|
dpkg |
apt or aptitude |
.deb |
rpm |
dnf or yum β οΈ |
.rpm |
pacman |
pacman |
-
dpkg
is mainly used by Debian-like distributions. -
rpm
is mainly used by Fedora and Red Hat. -
pacman
is mainly used by Arch Linux.
Package Systems And Tools
Usage π: apt
is the default package manager on well-known Linux distros such as Debian/Ubuntu.
Example π₯:
Install, Update, Remove a package
$ sudo apt install aptitude
$ sudo apt update aptitude
$ sudo apt upgrade aptitude
$ sudo apt remove aptitude
Download updates for/upgrade all packages
$ sudo apt update
$ sudo apt upgrade
Update the OS π§ͺ
$ sudo apt dist-upgrade
Remove unused dependencies
$ sudo apt autoremove
$ sudo apt auto-remove
When installing packages, you are prompted Do you want to continue? [Y/n]
(you need to enter Y
). You can skip this, using -y
.
$ sudo apt install -y aptitude
Configuration files are stored in /etc/apt/
:
$ cat /etc/apt/sources.list # repositories
$ ls /etc/apt/apt.conf.d/ # proxy conf etc.
List installed packages:
$ apt list --installed
Usage π: aptitude
(which has to be installed) is the same as apt
, but there is a graphical interface.
Example π₯:
$ sudo aptitude # press 'q' to quit
Or, you can use it like apt
:
$ sudo aptitude install nano
Usage π: apt
uses the lower-level package manager dpkg
to install packages. Some developers may directly interact with it.
Example π₯:
$ sudo dpkg -i xxx.deb
Usage π: snap packages are a modern way to share applications. They contain all dependencies, and support automatic updates. Some cons are their larger size and sometimes there are performance issues.
π Find Snap packages here.
Example π₯:
$ sudo apt update
$ sudo apt install snapd
$ sudo snap install core
$ sudo snap refresh core
$ sudo snap install --classic xxx
Usage π: available on Debian-based distributions. Allow us to switch between multiple versions of the same program.
π» c++, cc, nc, php, java...
Example π₯:
$ sudo update-alternatives --config php
Mirrors
To reduce the time it takes to download packages, multiple mirrors of package repositories are set up, and users should use the nearest ones. A mirror is basically a copy of a package repository.
It could be hosted locally.
apt-mirror
Apt-mirror is a tool used on Linux to create a mirror.
$ sudo apt-get install apt-mirror
$ sudo cat /etc/apt/mirror.list
set base_path /path/to/mirror
set run_postmirror 0
deb http://deb.nodesource.com/node_10.x/ buster main
clean http://deb.nodesource.com/node_10.x
$ sudo apt-mirror /etc/apt/mirror.list
It will create a folder mirror
inside /path/to/mirror
with:
-
dists/<codename>/<repository>
: contains the metadata -
pool/<repository>
: contains the downloaded packages
Aptly
Aptly is a powerful tool created to simplify the process of creating and maintaining package repositories. It can be used to create mirrors.
$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A0546A43624A8331
$ sudo apt-get install aptly
$ sudo cat ~/.aptly.conf # aptly config show
{
"rootDir": "/path/to/mirror",
"downloadConcurrency": 20,
"architectures": ["amd64"]
}
$ [handle gpg problems]
$ aptly mirror create node20 https://apt.nodesource.com/node_20.x nodistro main
$ aptly mirror update node20
π» To-do π»
Stuff that I found, but never read/used yet.
$ apt-file
$ apt-file update
$ apt autoclean
$ wget -qO - xxx.gpg | apt-key add -
- APT store information about packages in a local database for offline use.
$ apt-cache search <name>
$ apt-cache show <package_name>