Package Management: Difference between revisions

From miki
Jump to navigation Jump to search
 
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Ubuntu / Debian ==
== Ubuntu / Debian ==
See [[apt]].

'''{{red|NEW}}''' &mdash; Do not use <code>apt-get</code> anymore, use <code>apt</code> instead. Mostly the same, but with progress bar!

=== Basic ===
{{blue|'''Installing'''}} a package '''from REPOSITORIES''', using '''aptitude''':
<source lang="bash">
# ----- Installing from the REPOSITORIES - APTITUDE
aptitude update # (OPTIONAL) update the local repository cache
aptitude install <package(s)> # Install given package
aptitude remove <package(s)> # Remove package (or install it if package name prefixed with - )
</source>
''Note: Advantage of <code>aptitude</code> over <code>apt-get</code> is that it maintains <tt>/var/log/aptitude</tt>, and remove dependencies by default.''

{{blue|'''Installing'''}} a package '''from REPOSITORIES''', using '''apt-get''':
<source lang="bash">
# ----- Installing from the REPOSITORIES - APT-GET
apt-get update # (OPTIONAL) update the local repository cache
apt-get install <package(s)> # Install given package
apt-get install <package(s)>=<version> # Use = to install a specific version (usually to force downgrade) !!! no space !!!
apt-get install <package(s)>/<release> # Or use / to install from a specific distribution version !!! no space !!!
apt-get upgrade # Install new version of all installed package (without installing new package)
apt-get remove <package(s)> # Remove package (or install it if package name prefixed with - )
apt-get autoremove <package(s)> # Remove package and all its unused dependencies
apt-get purge <package(s)> # Remove package and related configuration files
apt-get autoremove # Remove package installed to satisfy dependencies for some package and that are no more needed
</source>

{{blue|'''Installing'''}} a package '''from a .deb PACKAGE file''':
<source lang="bash">
# ----- Installing from a .deb PACKAGE file
dpkg --install <debfile> # (or -i) Install a package from given .deb file
</source>

{{blue|'''Querying'''}} the '''cache''' or '''installed''' packages:
<source lang=bash>
# ----- Querying INSTALLED PACKAGE
dpkg --get-selections # Show the list of packages installed through apt-get
dpkg --get-selections | grep php # ... filtering for some specific package keyword
dpkg -l <pattern> # (dpkg-query) List packages matching pattern, incl. version + description
dpkg -s <package> # (dpkg-query) Report status of specified package
dpkg -L <package> # List files delivered by a given <package>
dlocate -L <package> # ... same as above but much faster (require package dlocate)
dpkg -S <file> # List packages providing given file
dlocate -S <file> # ... same as above but much faster (require package dlocate)
dlocate <file> # ... same as dpkg -L -S combined but much faster (require package dlocate)
debsums -s <pacakge> # List MODIFIED files in given package
debsums -s # List MODIFIED files in all installed packages
# ----- Querying the CACHE
apt-cache search <regex> # Search package cache (package name and description) for given <regex>
apt-cache search --name-only <regex> # ... same but only search in package name
apt-cache showpkg <package(s)> # Show version and dependencies information about given package(s)
apt-cache show <package(s)> # Show information (description...) about given package(s)
apt-cache dotty <package(s)>|dot -Tpng|display
# Generate & display dependency graph (require graphviz & imagemagick)
apt-rdepends -d <package(s)>|dot -Tpng|display
# Idem (but usually much lighter)
apt-cache dotty -o APT::Cache::GivenOnly=true $(dpkg --get-selections linux*|awk '{print $1}')|dot -Tpng|display
# Dependency graph restricted to package(s) given on command line
aptitude why|why-not <package> # Explain why a package should or cannot be installed on the system
# ----- Querying a .deb PACKAGE file
dpkg --info <debfile> # (or -I) Show information of given .deb file
dpkg --content <debfile> # (or -c) Show content of given .deb file
# ----- Querying LIST of packages
deborphan -a | sort # List of all packages that have no dependencies
apt-show-versions # List all installed packages, and whether there are up-to-date, obsolete, not coming from repo
apt-show-versions -a # ... idem, but show all available versions
apt-show-versions | grep -v uptodate # ... only show packages that are no up-to-date (No available version, upgradeable)
aptitude search '~o' # Similar to 'apt-show-versions' | grep 'No available version'
</source>

{{blue|'''Querying'''}} packages that are '''not installed yet''' (may require package '''apt-file'''):<br>
<source lang=bash>
apt-file update # (optional - needed 1st time use)
apt-file list <package> # Search package in repositories, and show the content
apt-file search <file> # Display the name of all packages within repository that contain this file
apt-file search -l <file> # ... only print package name
apt-file search -x "/<file>$" # ... more accurate query using regex
#View package CHANGELOG
aptitude changelog <package> # changelog of version that was/will be installed
aptitude changelog <package>=version # ... specific version
</source>
:''Note: An alternative is to use the script '''[{{#file: dweblocate}} dweblocate]''', but '''apt-file''' is more powerful actually''
<div style="display:none"><source lang="bash">
#!/bin/bash

# Very handy script to query online debian/ubuntu package database.
# It more or less imitates the behaviour of dlocate, but is not limited to package installed on the current system.
#
# Usage:
#
# dweblocate -L <package> List all files in package <package>
# dweblocate -S <filename> List all packages that contains <filename>
#
# Based on script at http://mydebian.blogdns.org/?p=742
# Modified by Fuujuhi, 2009.

DIST=ubuntu # debian | ubuntu
SUITENAME=jaunty # Not necessary for debian

if [ "$DIST" = "ubuntu" ] ; then
LISTURL="http://packages.ubuntu.com/$DISTNAME/all/$2/filelist"
SEARCHURL="http://packages.ubuntu.com/search?suite=${SUITENAME}&searchon=contents&keywords=$2"
elif [ "$DIST" = "debian" ] ; then
LISTURL="http://packages.ubuntu.com/$DISTNAME/all/$2/filelist"
SEARCHURL="http://packages.debian.org/search?suite=stable&searchon=contents&keywords=$2"
else
echo -e "Unknown distribution $DIST... Aborting!"
exit 1
fi

if [ $# -lt 2 ]; then
echo -e "Usage:\t$0 -S file \n\t$0 -L package"
exit 1
fi

if [ "$1" = "-L" ]; then
wget -q "$LISTURL" -O- | sed -n '/<pre>/,/<\/pre>/ {s/^[^/]*//;/\/pre>/!p}'
elif [ "$1" = "-S" ]; then
wget -q "$SEARCHURL" -O- | sed -n '/<table>/,/<\/table>/ { s/[[:space:]]*<a href="[^>]*>\([^<]*\)<\/a>/\1/p}'
else
echo "Error: invalid argument \"$1\"";
exit 2
fi
</source></div>

{{blue|'''View'''}} package source repository:
<source lang="bash">
apt-cache madison <package> # Display available version of a package in each repository
</source>

{{blue|'''View'''}} package installation history:
<source lang="bash">
grep install /var/log/dpkg.log # Also check dpkg.log.1, etc.
sudo cat /var/log/apt/terl.log # Also check
sudo cat /var/log/apt/history.log
</source>

{{blue|'''Add'''}} a repository:
<source lang="bash">
vi /etc/apt/sources.list # or edit files in /etc/apt/sources.list.d/
apt-get update
</source>

{{blue|'''Add'''}} a package authentication key:
<source lang="bash">
gpg --keyserver keyserver.ubuntu.com --recv 247D1CFF # (optional) Get the key from some keyserver
gpg --export --armor 247D1CFF | sudo apt-key add - # Add the key
</source>

Miscellaneous:
<source lang="bash">
dpkg-reconfigure popularity-contest # subscribe / unsubscribe to the package usage survey
apt-get moo # Get super cow powers
aptitude moo # Get super cow powers? try with -v, -vv
</source>

=== Advanced stuff ===

Reference:
* [http://wiki.yobi.be/wiki/Debian_Commands Debian commands on Yobi.be]
* Mail from Phil (2011/03/01)

==== APT policy ====
Use <code>apt-cache policy</code> to view curret package policy:
<source lang="bash">
apt-cache policy # Policy summary
apt-cache policy <pkg> # Policy for a given <pkg>
</source>

Content of file <tt>/etc/apt/apt.conf.d/00default</tt> (or <tt>/etc/apt/apt.conf</tt> if that file doesn't exist):
<source lang="bash">
APT::Default-Release "testing";
</source>

This changes the order of preference for packages. Here it says <tt>default=testing=wheezy</tt>, so:

<source lang="bash">
apt-cache policy virtualbox-osevirtualbox-ose:
# Installed: (none)
# Candidate: 4.0.2-dfsg-1
# Version table:
# 4.0.4-dfsg-1+b1 0
# 500 http://ftp.be.debian.org/debian/ sid/main amd64 Packages
# 4.0.2-dfsg-1 0
# 990 http://ftp.be.debian.org/debian/ wheezy/main amd64 Packages
# 3.2.10-dfsg-1 0
# 500 http://ftp.be.debian.org/debian/ squeeze/main amd64 Packages
</source>
The number (500 vs 990) is giving the priority.


==== APT Pinning ====
Reference:
* <code>man apt_preferences</code>
* http://www.debianiste.org/?post/2009/06/23/Apt-pinning-ou-comment-avoir-une-Debian-Stable-et-a-jour-%3A
* http://jaqque.sbih.org/kplug/apt-pinning.html
* http://www.argon.org/~roderick/apt-pinning.html

==== Rebuild / Recompile a package ====

References: [http://www.cyberciti.biz/faq/rebuilding-ubuntu-debian-linux-binary-package/], [http://ubuntuforums.org/showthread.php?t=101097]

<source lang=bash>
# Install required packages
sudo apt-get install build-essential fakeroot dpkg-dev

# Create build directory
mkdir build
cd build

# Get package source (e.g. udisks)
# - See further down to solve gpg signature verification warning
apt-get source udisks

# Install all packages needed to build 'udisks' (aka. build deps)
sudo apt-get build-dep udisks

# (optional) Unpack Debian / Ubuntu source package (.dsc) - this is done automatically by apt-get
# First get gpg key, and export it as trusted keys (see http://askubuntu.com/questions/56841/gpg-cant-check-signature)
gpg --keyserver keyserver.ubuntu.com --recv-keys 7ADF9466
gpg --no-default-keyring -a --export 136B762D | gpg --no-default-keyring --keyring ~/.gnupg/trustedkeys.gpg --import -
# Second unpack the source package
dpkg-source -x udisks_1.0.4-5ubuntu2.1.dsc

# Go into package dir
cd udisks-1.0.4/

# (optional) Edit the files
vi src/device.c
# (optional) Change compilation settings
DEB_BUILD_OPTIONS="--enable-gui --enable-radio" fakeroot debian/rules binary
CC=gcc-3.4 DEB_BUILD_OPTIONS="--enable-gui --enable-radio" fakeroot debian/rules binary
# (optional, strongly suggested) Change package version
debchange --local foo --preserve --distribution precise-proposed "Force mount flag 'dmode=0500' for UDF filesystem."

# Rebuild the package
dpkg-buildpackage -rfakeroot -b

# Install the package
cd ..
dpkg -i udisks_1.0.4-5ubuntu2.1foo1_amd64.deb
</source>

=== Ignore dependencies, force package install ===

<source lang=bash>
apt-get download overlay-scrollbar-gtk2:i386
sudo dpkg --ignore-depends overlay-scrollbar -i overlay-scrollbar-gtk2*.deb
sudo vi /var/lib/dpkg/status
# On line Depends: remove 'overlay-scrollbar' for package 'overlay-scrollbar-gtk2', architecture 'i386'
sudo apt-get install -f
</source>

=== Clone or repackage ===
'''dpkg-repack''' creates a {{file|.deb}} file out of a package that has already
been installed. If any changes have been made to the package while it was
unpacked (ie, files in {{file|/etc}} were modified), the new package will inherit
the changes.

This utility can make it easy to copy packages from one computer to another,
or to recreate packages that are installed on your system, but no longer
available elsewhere, or to store the current state of a package before you
upgrade it.

<source lang=bash>
apt-get install dpkg-repack
dpkg-repack package
</source>

'''apt-clone''' can be used to clone/restore the packages on a apt based system.
<source lang=bash>
apt-get install apt-clone
</source>

=== Update a computer not connected to internet ===

Here we describe how to update a debian/ubuntu distribution on a computer not connected to internet (called the ''offline'' system), using another computer connected to internet (called the ''proxy'' system).

==== Via apt cache ====
This method assumes that both ''offline'' and ''proxy'' systems are identical. Here we will simply first install the packages on the ''proxy'' system, then upgrade the ''offline'' system.

# First sync ''offline'' and ''proxy''
: Copy the folders {{file|/etc/apt}}, {{file|/var/lib/apt}} from ''proxy'' to ''offline'' system. Make sure that these folders are identical. Delete the folder {{file|/var/cache/apt}} on the ''offline'' system, it will be generated at next invocation of apt.
# Install the packages on ''proxy'' system.
# Copy the content of {{file|/var/cache/apt/archives}} to ''offline'' system.
# Install the packages on ''offline'' system.
:Make sure to use the exact same <code>apt-get install</code> command. If some packages are missing, you may force reinstall these packages on the ''proxy'' system to get back the corresponding packages.

==== Using <code>apt-offline</code> ====
Reference: [https://www.maketecheasier.com/update-upgrade-ubuntu-without-internet-connection/]

First you need to install {{deb|apt-offline}} on the ''offline'' and ''proxy'' systems.
sudo apt-get install apt-offline

This usually requires an internet connection, but another solution is to first install the package on the ''proxy'' system, then copy the package {{file|.deb}} file from {{file|/var/cache/apt/archives}} into same directory on the ''offline'' system. Now install the package on the ''offline'' system using <code>apt-get</code> as usual.

;Upprade offline system
* On ''offline'' system, generate the reference signature file:
<source lang=bash>
sudo apt-offline set --update --upgrade /path/to/apt.sig # ... OR ...
sudo apt-offline set --update --upgrade --upgrade-type dist-upgrade /path/to/apt.sig
</source>
* On ''proxy'' system, download the necessary packages:
<source lang=bash>
apt-offline get -d /path/to/download/directory /path/to/apt.sig # ... OR ...
apt-offline get --bundle /download/path/bundle.zip /path/to/apt.sig
</source>
* Back on ''offline'' system, install all the packages:
<source lang=bash>
sudo apt-offline install /path/to/bundle.zip
sudo apt-get upgrade # ... OR ...
sudo apt-get dist-upgrade
</source>

;Install a package on offline system
* On ''offline'' system, generate the reference signature file and request installation of package (here {{deb|vlc}}):
<source lang=bash>
sudo apt-offline set --install-package vlc -- /path/to/apt.sig
</source>
* On ''proxy'' system, download the necessary packages:
<source lang=bash>
apt-offline get --bundle /download/path/bundle.zip /path/to/apt.sig
</source>
* Back on ''offline'' system, install all the packages:
<source lang=bash>
sudo apt-offline install /path/to/bundle.zip
sudo apt-get install vlc
</source>

=== Internals ===
; {{file|/var/cache/apt/archives}}
:Contains the latest packages installed via <code>apt-get</code>. Before downloading a package, ''apt'' checks whether the package is already available (and not corrupted) in that folder.
; {{file|/var/cache/apt/srcpkgcache.bin}}
:(From [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=566275] and <code>man apt.conf</code>) {{file|srcpkgcache.bin}} includes the information containing in the files in {{file|/var/lib/apt/lists}} &mdash; aka all informations you get from the internet by <code>deb</code> and <code>deb-src</code> lines &mdash; these information are changed only on <code>apt-get update</code>.
; {{file|/var/cache/apt/pkgcache.bin}}
:{{file|pkgcache.bin}} on the other hand caches the information in {{file|srcpkgcache.bin}} + the informations extracted from the apt and dpkg status files. These change on every install/remove done by apt or directly by <code>dpkg</code>. So if only the status files are changed apt doesn't need to reparse the other informations again - and if no file was changed in between yet and the last call apt can directly load the {{file|pkgcache.bin}} file into memory.

; {{file|/var/lib/apt}}
:Contains the list of repository content (as selected in {{file|/etc/apt/sources.list}} and {{file|/etc/apt/sources.list.d}}, the trusted keyrings, etc.


== RPM's ==
== RPM's ==
Line 384: Line 46:
:Note that <tt>checkinstall</tt> can actually run any arbitrary command and monitor change on the file system.
:Note that <tt>checkinstall</tt> can actually run any arbitrary command and monitor change on the file system.


== Managing alternatives ==
== Backports ==
=== Debian ===
See [https://www.ocf.berkeley.edu/docs/staff/procedures/backporting-packages/ Backporting Debian packages].

== Managing alternatives with <code>update-alternatives</code> ==
Display current set of alternatives (e.g. here for ''gcc'' on ''Cygwin''):
Display current set of alternatives (e.g. here for ''gcc'' on ''Cygwin''):
<source lang=bash>
<source lang=bash>
Line 444: Line 110:
/usr/sbin/update-alternatives --set gcc /usr/bin/gcc-3.exe # Set gcc-3 as alternative for gcc (also set slaves, etc)
/usr/sbin/update-alternatives --set gcc /usr/bin/gcc-3.exe # Set gcc-3 as alternative for gcc (also set slaves, etc)
/usr/sbin/update-alternatives --config gcc # Select alternative via menu
/usr/sbin/update-alternatives --config gcc # Select alternative via menu
</source>

=== Alternatives for clang ===
<source lang="bash">
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 1000
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 1000
sudo update-alternatives --config clang
sudo update-alternatives --config clang++
</source>
</source>

Latest revision as of 09:24, 26 November 2019

Ubuntu / Debian

See apt.

RPM's

rpm -ivh package                    # Installing a package - verbose and progress bars
rpm -iv -nodeps package             # Installing a package (verbose), ignore dependencies
  • Query commands
rpm -ql package                     # List files provided by a package
  • To query a package that has not been installed, add -p option to the command:
rpm -qpl package                    # List files provided by a package

Source package

Installing from source package is usually done with

./configure
make
sudo make install

Usually ./configure --help gives additional package configuration options (like installing documentation, etc).

Installing build dependencies
Building from sources usually requires more dependencies than using the package. If the package is available on the distribution, the easiest way to install these dependencies is usually via apt-get build-dep:
sudo apt-get build-dep udisks
Installing as a package
Instead of installing with make install, use checkinstall to create a temporary package that can later be uninstalled with the package manager.
./configure
make
sudo checkinstall                  # Creates a package and install it as if 'sudo make install' was run

#... to uninstall:
sudo dpkg -r <packagename>
Note that checkinstall can actually run any arbitrary command and monitor change on the file system.

Backports

Debian

See Backporting Debian packages.

Managing alternatives with update-alternatives

Display current set of alternatives (e.g. here for gcc on Cygwin):

$ /usr/sbin/update-alternatives --display gcc
# gcc - status is manual.
#  link currently points to /usr/bin/gcc-3.exe
# /usr/bin/gcc-3.exe - priority 30
#  slave lib-cpp: <NONE>
#  slave cc: /usr/bin/cc-3.exe
#  slave cpp: /usr/bin/cpp-3.exe
#  slave gcov: /usr/bin/gcov-3.exe
#  slave i686-pc-cygwin-gcc-4.3.4: <NONE>
#  slave i686-pc-cygwin-gcc: /usr/bin/i686-pc-cygwin-gcc-3.exe
#  slave protoize: /usr/bin/protoize-3.exe
#  slave unprotoize: /usr/bin/unprotoize-3.exe
#  slave cpp.1.gz: /usr/share/man/man1/cpp-3.1.gz
#  slave gcc.1.gz: /usr/share/man/man1/gcc-3.1.gz
#  slave gcov.1.gz: /usr/share/man/man1/gcov-3.1.gz
#  slave ffi.3.gz: <NONE>
#  slave ffi_call.3.gz: <NONE>
#  slave ffi_prep_cif.3.gz: <NONE>
# /usr/bin/gcc-4.exe - priority 40
#  slave lib-cpp: /usr/bin/cpp-4.exe
#  slave cc: /usr/bin/gcc-4.exe
#  slave cpp: /usr/bin/cpp-4.exe
#  slave gcov: /usr/bin/gcov-4.exe
#  slave i686-pc-cygwin-gcc-4.3.4: <NONE>
#  slave i686-pc-cygwin-gcc: /usr/bin/i686-pc-cygwin-gcc-4.exe
#  slave protoize: <NONE>
#  slave unprotoize: <NONE>
#  slave cpp.1.gz: /usr/share/man/man1/cpp-4.1.gz
#  slave gcc.1.gz: /usr/share/man/man1/gcc-4.1.gz
#  slave gcov.1.gz: /usr/share/man/man1/gcov-4.1.gz
#  slave ffi.3.gz: /usr/share/man/man3/ffi-4.3.gz
#  slave ffi_call.3.gz: /usr/share/man/man3/ffi_call-4.3.gz
#  slave ffi_prep_cif.3.gz: /usr/share/man/man3/ffi_prep_cif-4.3.gz
# Current `best' version is /usr/bin/gcc-4.exe.

Create a new entry with

/usr/sbin/update-alternatives --install /usr/bin/gcc.exe gcc /usr/bin/gcc-3.exe  30 \
 --slave /usr/bin/cc.exe cc /usr/bin/cc-3.exe \
 --slave /usr/bin/cpp.exe cpp /usr/bin/cpp-3.exe \
 --slave /usr/bin/gcov.exe gcov /usr/bin/gcov-3.exe \
 --slave /usr/bin/i686-pc-cygwin-gcc.exe i686-pc-cygwin-gcc /usr/bin/i686-pc-cygwin-gcc-3.exe \
 --slave /usr/bin/protoize.exe protoize /usr/bin/protoize-3.exe \
 --slave /usr/bin/unprotoize.exe unprotoize /usr/bin/unprotoize-3.exe \
 --slave /usr/share/man/man1/cpp.1.gz cpp.1.gz /usr/share/man/man1/cpp-3.1.gz \
 --slave /usr/share/man/man1/gcc.1.gz gcc.1.gz /usr/share/man/man1/gcc-3.1.gz \
 --slave /usr/share/man/man1/gcov.1.gz gcov.1.gz /usr/share/man/man1/gcov-3.1.gz

Select an entry with

/usr/sbin/update-alternatives --auto gcc                        # Select alternative for gcc based on priority
/usr/sbin/update-alternatives --set gcc /usr/bin/gcc-3.exe      # Set gcc-3 as alternative for gcc (also set slaves, etc)
/usr/sbin/update-alternatives --config gcc                      # Select alternative via menu

Alternatives for clang

sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 1000
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 1000
sudo update-alternatives --config clang
sudo update-alternatives --config clang++