Package Management: Difference between revisions

From miki
Jump to navigation Jump to search
(→‎Ubuntu / Debian: Querying packages that are not yet installed)
Line 22: Line 22:
apt-cache search <regex> # Search package cache (package name and description) for given <regex>
apt-cache search <regex> # Search package cache (package name and description) for given <regex>
apt-cache showpkg <package(s)> # Show information about given package(s)
apt-cache showpkg <package(s)> # Show information about given package(s)
</source>

Querying packages that are '''not installed yet''' (requires package '''apt-file'''):<br>
''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>
<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
</source>
</source>


Line 32: Line 82:


To add a repository:
To add a repository:
<source lang="bash">
* edit file <tt>/etc/apt/sources.list</tt> ou <tt>sources.list.d/</tt>, then <code>apt-get update</code>.
vi /etc/apt/sources.list # or edit files in /etc/apt/sources.list.d/
apt-get update
</source>


To add a package authentication key:
To add a package authentication key:
Line 39: Line 92:
gpg --export --armor 247D1CFF | sudo apt-key add - # Add the key
gpg --export --armor 247D1CFF | sudo apt-key add - # Add the key
</source>
</source>

<div style="display:none">You should not see this</div>


== RPM's ==
== RPM's ==

Revision as of 14:18, 16 October 2009

Ubuntu / Debian

Installing a package from repository:

apt-get update                      # (OPTIONAL) update the local repository cache
apt-get install <package(s)>        # Install given package
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 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

Querying packages that are installed / from cache repository:

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 <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)
apt-cache search <regex>            # Search package cache (package name and description) for given <regex>
apt-cache showpkg <package(s)>      # Show information about given package(s)

Querying packages that are not installed yet (requires package apt-file):
Note: An alternative is to use the script [{{#file: dweblocate}} dweblocate], but apt-file is more powerful actually

#!/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
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

Querying / Installing 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
dpkg --install <debfile>            # (or -i) Install a package from given .deb file

To add a repository:

vi /etc/apt/sources.list            # or edit files in /etc/apt/sources.list.d/
apt-get update

To add a package authentication key:

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
You should not see this

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