package manager for Linux

Overview

apt/apt-get debian based distro

yum : redhat/centos/fedora distro

apk : alpine (light Docker images)

snap : universal linux package manager and so with low coupling with distros, so updated more frequently

Snap

How to install Snap ?
Debian based :
apt install snapd

Applications location :
/snap/

List installed applications :
snap list

Search applications (it searches both on application names and summaries):
snap find keyword

Install an application :
snap install application-name

Delete an application :
snap remove application-name

Delete a specific version (ex: 123 revision) of an application :
snap remove --revision 123 application-name

Debian-based OS (Ubuntu, Debian…)

apt-get and apt-cache : low level command (machine use)
apt : higher level command (human use)

Configuration/repository files

These are located inside /etc/apt/.
The sources.list file contains the list of repo provided by the OS.
The sources.list.d/ folder contains third party repo added. Each one is defined in its own file

Add third party repository

Add the repo :
sudo add-apt-repository foo-repo
Update the repo managed to be aware of it :
sudo apt-get update

apt-mark

show, set and unset various settings for a package.

AUTOMATICALLY AND MANUALLY INSTALLED PACKAGES commands

auto
Mark a package as being automatically installed, which will cause the package to be removed when no more manually installed packages depend on this package.

manual
Mark a package as being manually installed, which will prevent the package from being automatically removed if no other packages depend on it.

showauto
Print a list of automatically installed packages with each package on a new line.
All automatically installed packages will be listed if no package is given.
If packages are given only those which are automatically installed will be shown.

showmanual
As showauto except that it will print a list of manually installed packages instead.

PREVENT CHANGES FOR A PACKAGE commands

hold
Mark a package as held back, which will prevent the package from being automatically installed, upgraded or removed.

unhold
Cancel a previously set hold on a package to allow all actions again.

showhold
print a list of packages on hold in the same way as for the other show commands.

apt-get and apt-cache

COMMANDS

* update available packages
sudo apt update

* search (in the repos) all packages which the package name or the description matches to a regex:
sudo apt search fooRegex

* search (in the repos) all packages which the package name matches to a regex:
sudo apt search –names-only fooRegex

* search (in the repos) all versions and all their dependencies packages for a specific package (not a regex):
apt-cache showpkg python3

* Show whether the package is installed and if that is its version, the default install/upgrade version  and all available versions:
sudo apt policy fooPackage

* display all packages :
sudo apt list

useful flag for list :
--installed
--upgradable
-a (for all)


* list all files installed for a package :
dpkg -L packageName

* download and install a package with all its dependencies
sudo apt install packageName

* download and install a specific version of a package with all its dependencies
sudo apt install packageName=fooVersion

* update a package to the default next version (if the package is not installed, do nothing)
sudo apt-get install --only-upgrade packageName

* update a package into a specific version (if the package is not installed, do nothing)
sudo apt-get install --only-upgrade PACKAGE_NAME=VERSION

* remove a package :
sudo apt remove packageName

useful flag for install or remove : -y (assume yes for any question)

* Fix all broken packages and remove them:

apt-get check
apt-get --fix-broken install
dpkg --configure -a
#removes orphaned packages which are not longer needed from the system
apt-get autoremove -y
#cleans the packages and install script in /var/cache/apt/archives/
apt-get clean

* install a debian package
sudo dpkg -i file.deb

Alternative

* list all targets of the link group:
update-alternatives --list name
Ex: update-alternatives --list javac

* Display detailed information about the link group:
update-alternatives --display name
Ex: update-alternatives --display javac

* set to another alternative
update-alternatives --config myapp

* list package names of master alternatives : (NOT OFTEN USEFUL)
update-alternatives --get-selections

* Adding a group of alternatives to the system
sudo update-alternatives --install link name path priority
link : the generic name for the master link
name :the name of its symlink in the alternatives directory
path : the alternative being introduced for the master link.

For example with python3, assuming that both /usr/bin/python3.6 and /usr/bin/python3.9 are installed in the system.
Here we define python3 as the symlink name, /usr/bin/python3 as the generic name for the master link and we add these two python installations as two alternatives with the 3.9 version as higher priority: 
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
In terms of symoblic links it creates that :

ll /usr/bin/python3
lrwxrwxrwx 1 root root  /usr/bin/python3 -> /etc/alternatives/python3*
ll /etc/alternatives/python3 
lrwxrwxrwx 1 root root  /etc/alternatives/python3 -> /usr/bin/python3.9*

* directory where are stored the metada of all alternatives :
/var/lib/dpkg/alternatives (ubuntu)
/var/lib/alternatives (others)

* directory with symbolic links to all alternatives
/etc/alternatives

APT-KEY

apt-key tool : used to manage the list of keys used by apt to authenticate packages.

* list trusted keys with fingerprints :
apt-key list

* add a new key represented by the file parameter to the list of trusted keys :
apt-key add fooFile

Specify – to take as source the standard input

Redhat/Centos OS : yum command

login user : system<unset> means : not a user but the system itself (auto-update for example).

List the installed yum repositories:
yum repolist all

To add a yum repository to /etc/yum.repos.d :
If yum-utils is not installed:
sudo yum install -y yum-utils
Then install the repository (for example for the docker repository):

sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/rhel/docker-ce.repo


To list all packages and their install dates, latest first:
rpm -qa --last

To list aliases for a package name for yum (each provide is an alias):
rpm -q --provides package

To install manually a package:
rpm -i foo.rpm

List all packages :
yum list

List all packages and all their versions:
yum --showduplicates list

List a specific packages and all its versions:
yum --showduplicates list foo-package

List installed packages :
yum list installed

Search a package :
yum search foopackage

Get detailed infos on a package :
yum info -v foopackage

Get packages that uses a specific package :
rpm -q --whatrequires specificPackage

Install a package :
yum install FOO-PACKAGE
To install a specific version of the package :
yum install FOO-PACKAGE-FOOVERSION
-y flag to skip confirmation message.

Remove a package :
yum remove FOO-PACKAGE

History of packages install/update/removal:
yum history

By default, it is limited to a recent history.
To list all:
yum history list all

History for a specific packages of install/update/removal:
yum history list foopackage

History for a specific package of install-files used in install/update/removal:
yum history package-list foopackage

The yum conf file : /etc/yum.conf.
We can find inside config for proxy

install a package from a new repository
you need to add the repository information to the /etc/yum.conf file or to its own repository.repo file in the /etc/yum.repos.d directory.

Third-party repository problems

Issue during apt or yum update :

The following signatures couldn't be verified because the public key is not available

Fix for Gitlab package :
curl https://gitlab-org.gitlab.io/omnibus-gitlab/gitlab_new_gpg.key -o /tmp/omnibus_gitlab_gpg.key
sudo apt-key add /tmp/omnibus_gitlab_gpg.key

Fix for google packages :
wget https://packages.cloud.google.com/apt/doc/apt-key.gpg && apt-key add apt-key.gpg

Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *