「pkg」の版間の差分

提供: FreeBSD入門
移動: 案内検索
行14: 行14:
 
最新のコレクションをバイナリでインストール・アップグレードできます。
 
最新のコレクションをバイナリでインストール・アップグレードできます。
  
以下の動画の前半に[[pkg]]を利用している例があります。
+
以下の[[htop]]の動画の前半に[[pkg]]を利用している例があります。
 
<html>
 
<html>
 
<iframe width="560" height="315" src="//www.youtube.com/embed/YTH-CT4spAU" frameborder="0" allowfullscreen></iframe>
 
<iframe width="560" height="315" src="//www.youtube.com/embed/YTH-CT4spAU" frameborder="0" allowfullscreen></iframe>

2014年5月25日 (日) 09:55時点における版

pkgは、次世代パッケージ管理システムとそのコマンドです。FreeBSD 10-CURRENT から採用されました。RELEASE版では、FreeBSD 10.0-RELEASEから利用できます。バイナリパッケージであるため、コンパイルが必要ありません。バイナリパッケージのメリットは、コンパイルがすでに終わってることでしょう。また、portsと併用できます。独自のビルドオプションなどを使いたいパッケージは、portsからビルドし、それ以外をpkgでインストールできます。

読み方

pkg
ぴーけーじー

目次

概要

pkgは、次世代パッケージ管理システムとそのコマンドです。 FreeBSD 10-CURRENT から採用されました。 FreeBSD 9.1-RELEASE で利用できます。 FreeBSD 10.0-RELEASEでは、デフォルトで使用できます。

Ports Collectionをベースに1-2週間ごとにパッケージが更新されます。 最新のコレクションをバイナリでインストール・アップグレードできます。

以下のhtopの動画の前半にpkgを利用している例があります。

設定

設定ファイル

  • /usr/local/etc/pkg.conf

FreeBSD 10.0-RELEASE /etc/pkg/FreeBSD.conf

# $FreeBSD: release/10.0.0/etc/pkg/FreeBSD.conf 258710 2013-11-28 14:24:26Z gjb $
FreeBSD: {
  url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
  mirror_type: "srv",
  signature_type: "fingerprints",
  fingerprints: "/usr/share/keys/pkg",
  enabled: yes
}

make.conf

FreeBSD 10.x 未満の場合は、下記設定を /etc/make.conf にします。

WITH_PKGNG=	yes

使い方

pkg コマンドのオプション

% pkg help
Usage: pkg [-v] [-d] [-l] [-N] [-j <jail name or id>|-c <chroot path>] 
[-C <configuration file>] [-R <repo config dir>] <command> [<args>]
 
Global options supported:
        -d             Increment debug level
        -j             Execute pkg(8) inside a jail(8)
        -c             Execute pkg(8) inside a chroot(8)
        -C             Use the specified configuration file
        -R             Directory to search for individual repository configurations
        -l             List available commands and exit
        -v             Display pkg(8) version
        -N             Test if pkg(8) is activated and avoid auto-activation
 
Commands supported:
        add            Registers a package and installs it on the system
        annotate       Add, modify or delete tag-value style annotations on packages
        audit          Reports vulnerable packages
        autoremove     Removes orphan packages
        backup         Backs-up and restores the local package database
        check          Checks for missing dependencies and database consistency
        clean          Cleans old packages from the cache
        config         Display the value of the configuration options
        convert        Convert database from/to pkgng
        create         Creates software package distributions
        delete         Deletes packages from the database and the system
        fetch          Fetches packages from a remote repository
        help           Displays help information
        info           Displays information about installed packages
        install        Installs packages from remote package repositories
        lock           Locks package against modifications or deletion
        plugins        Manages plugins and displays information about plugins
        query          Queries information about installed packages
        register       Registers a package into the local database
        remove         Deletes packages from the database and the system
        repo           Creates a package repository catalogue
        rquery         Queries information in repository catalogues
        search         Performs a search of package repository catalogues
        set            Modifies information about packages in the local database
        ssh            ssh packages to be used via ssh
        shell          Opens a debug shell
        shlib          Displays which packages link against a specific shared library
        stats          Displays package database statistics
        unlock         Unlocks a package, allowing modification or deletion
        update         Updates package repository catalogues
        updating       Displays UPDATING information for a package
        upgrade        Performs upgrades of packaged software distributions
        version        Displays the versions of installed packages
        which          Displays which package installed a specific file
 
Commands provided by plugins:
 
For more information on the different commands see 'pkg help <command>'.

はじめて起動するとき

% sudo /usr/sbin/pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
Bootstrapping pkg please wait
Installing pkg-1.0.11... done
If you are upgrading from the old package format, first run:
 
  # pkg2ng
usage: pkg [-v] [-d] [-j <jail name or id>|-c <chroot path>] <command> [<args>]
 
Global options supported:
        -d             Increment debug level
        -j             Execute pkg(1) inside a jail(8)
        -c             Execute pkg(1) inside a chroot(8)
        -v             Display pkg(1) version
 
Commands supported:
        add            Registers a package and installs it on the system
        audit          Reports vulnerable packages
        autoremove     Removes orphan packages
        backup         Backs-up and restores the local package database
        check          Checks for missing dependencies and database consistency
        clean          Cleans old packages from the cache
        create         Creates software package distributions
        delete         Deletes packages from the database and the system
        fetch          Fetches packages from a remote repository
        help           Displays help information
        info           Displays information about installed packages
        install        Installs packages from remote package repositories
        query          Queries information about installed packages
        register       Registers a package into the local database
        remove         Deletes packages from the database and the system
        repo           Creates a package repository catalogue
        rquery         Queries information in repository catalogues
        search         Performs a search of package repository catalogues
        set            Modifies information about packages in the local database
        shell          Opens a debug shell
        shlib          Displays which packages link against a specific shared li                                                                                                                                                                brary
        stats          Displays package database statistics
        update         Updates package repository catalogues
        updating       Displays UPDATING information for a package
        upgrade        Performs upgrades of packaged software distributions
        version        Displays the versions of installed packages
        which          Displays which package installed a specific file
 
For more information on the different commands see 'pkg help <command>'.

すでにサードパーティ製ソフトウェアがインストールされている場合

FreeBSDports などでソフトウェアがインストールされている場合は、データベースを新しいフォーマットへ変換する必要があります。

sudo /usr/local/sbin/pkg2ng
% sudo /usr/local/sbin/pkg2ng
 
省略
 
Moved old package database to /var/db/pkg.bak.
Conversion has been successfully finished
Your old packages database has been moved to: /var/db/pkg.bak.
% ls /var/db/pkg
local.sqlite  repo.sqlite

パッケージをインストールする

パッケージのインストールの例。

pkg install tmux

パッケージをアンインストールする

pkg delete tmux

バージョンチェック

アップデートできるパッケージがないか調べます。

pkg version
% pkg version
ImageMagick-6.8.0.7                <
ORBit2-2.14.19                     =
R-2.15.3                           =
adns-1.4_1                         =
amap-5.2                           =

時代遅れなパッケージを調べる

pkg version -l '<'

データベースのダウンロード

% sudo pkg update -f
Updating repository catalogue
repo.txz                        100% 1832     1.8KB/s   1.8KB/s   00:00

バージョンアップ

新しいバージョンのパッケージにアップグレードします。

sudo pkg upgrade

ドライラン(Dry run)します。

sudo pkg upgrade -n

インストールされているファイルからパッケージを調べる

任意のファイルがどのパッケージによってインストールされたのか調べるには、以下のコマンドを実行します。

$ pkg which /usr/local/libexec/apache24/mod_remoteip.so
/usr/local/libexec/apache24/mod_remoteip.so was installed by package apache24-2.4.9

上記の結果から mod_remoteip.so は、 apache24 のパッケージに含まれていることがわかりました。

使われていないインストールされているパッケージの依存を削除する

pkg autoremove

パッケージの検証

脆弱性のあるソフトウェアがインストールされていないか、検証できます。

pkg audit -F
% sudo pkg audit -F
auditfile.tbz                         100%   87KB  86.8KB/s  86.8KB/s   00:01
ca_root_nss-3.14 is vulnerable:
mozilla -- multiple vulnerabilities
 
WWW: http://portaudit.FreeBSD.org/a4ed6632-5aa9-11e2-8fcb-c8600054b392.html
 
省略
 
10 problem(s) in your installed packages found.

リモートのパッケージの情報を取得する

query は、任意の文字列が入ります。

pkg search 'query'

リモートのパッケージの一覧を取得する

pkg search '.'
user@b0:/ % pkg search '.'|wc
   22691   22691  457583

リモートのパッケージを検索する

pkgのsearchコマンドは、以下の引数をとります。

Usage: pkg search [-egix] [-r repo] [-S search] [-L label] [-Q mod]... 
	<pkg-name>
       pkg search [-cDdefgiopqRx] [-r repo] <pattern>
 
       Search and Label options: comment description name origin pkg-name
       Output Modifiers: annotations arch categories comment depends-on
             description full licenses maintainer name options pkg-size
             prefix repository required-by shared-libs-required shared-libs-provided
             size url version www
For more information see 'pkg help search'.
user@b0:/ % pkg search vim
vim-7.4.110_3
vim-lite-7.4.110
vimpager-1.8.3
xpi-vimperator-3.5

リモートのパッケージの情報の詳細を取得する

user@b0:/ % pkg search sshsudo
sshsudo-1.0

-f オプションで詳細情報が取得できます。

user@b0:/ % pkg search -f sshsudo
sshsudo-1.0
Name           : sshsudo
Version        : 1.0
Origin         : sysutils/sshsudo
Architecture   : freebsd:10:x86:32
Prefix         : /usr/local
Categories     : sysutils
Licenses       : GPLv3
Maintainer     : gaod@hychen.org
WWW            : http://code.google.com/p/sshsudo/
Comment        : A bash script to run sudo command on multiple remote computers
Flat size      : 40.5KiB
Pkg size       : 15 KB
Description    :
A bash script to run sudo command on multiple remote computers with least effort
 
WWW:    http://code.google.com/p/sshsudo/

インストールされているパッケージの情報を取得する

インストールされているパッケージの一覧を取得する

pkg info

パッケージの情報を取得する

% pkg info tmux
tmux-1.8                       A Terminal Multiplexer

パッケージの情報を詳細な取得する

user@b0:/ % pkg info -f tmux
tmux-1.8_1
Name           : tmux
Version        : 1.8_1
Origin         : sysutils/tmux
Architecture   : freebsd:10:x86:32
Prefix         : /usr/local
Categories     : sysutils
Licenses       : BSD
Maintainer     : gahr@FreeBSD.org
WWW            : http://www.sourceforge.net/projects/tmux/
Comment        : A Terminal Multiplexer
Options        :
        BACKSPACE      : off
        LIBEVENT2      : off
        LIBEVENT_STATIC: off
Shared Libs required:
        libevent-1.4.so.4
Flat size      : 476KiB
Description    :
Tmux is a terminal multiplexer, it enables a number of terminals to be accessed
and controlled from a single terminal. tmux is intended to be a simple, modern,
BSD-licensed alternative to programs such as GNU screen.
 
WWW:    http://www.sourceforge.net/projects/tmux/

インストールされているファイルの一覧を取得する

インストールされているファイルの一覧を表示する。

% pkg info -l tmux
tmux-1.8 owns the following files:
/usr/local/bin/tmux
/usr/local/etc/bash_completion.d/tmux
/usr/local/man/man1/tmux.1.gz
/usr/local/share/doc/tmux/CHANGES
/usr/local/share/doc/tmux/FAQ
/usr/local/share/doc/tmux/README
/usr/local/share/doc/tmux/TODO
/usr/local/share/examples/tmux/bash_completion_tmux.sh
/usr/local/share/examples/tmux/h-boetes.conf
/usr/local/share/examples/tmux/n-marriott.conf
/usr/local/share/examples/tmux/screen-keys.conf
/usr/local/share/examples/tmux/t-williams.conf
/usr/local/share/examples/tmux/tmux.vim
/usr/local/share/examples/tmux/tmux_backup.sh
/usr/local/share/examples/tmux/vim-keys.conf
/usr/local/share/licenses/tmux-1.8/BSD
/usr/local/share/licenses/tmux-1.8/LICENSE
/usr/local/share/licenses/tmux-1.8/catalog.mk

インストールされているパッケージの統計を表示する

user@b0:/ % pkg stat
Local package database:
        Installed packages: 116
        Disk space occupied: 583 MB
 
Remote package database(s):
        Number of repositories: 1
        Packages available: 22691
        Unique packages: 22691
        Total size of packages: 94 GB

パッケージをロックとアンロック

パッケージのロック

パッケージの更新をロックできます。

$ sudo pkg lock tmux
tmux-1.9.a: lock this package? [y/N]: y
Locking tmux-1.9.a

パッケージのロック状態の確認

パッケージがロックされているかは、infoで確認します。

yes
ロックされている
no
ロックされていない
$ pkg info -k tmux vim
tmux-1.9.a                     yes
vim-7.4.192_1                  no

パッケージのアンロック

パッケージのロックは、アンロックオプションで解除できます。

$ sudo pkg unlock tmux
tmux-1.9.a: unlock this package? [y/N]: y
Unlocking tmux-1.9.a

ロック状態のパッケージはアップデートできない

ロック状態のパッケージは、アップデートがあっても、インストールされません。

$ sudo pkg install tmux
Updating repository catalogue
tmux-1.9.a_1 already installed
$ sudo pkg unlock tmux
tmux-1.9.a: unlock this package? [y/N]: y
Unlocking tmux-1.9.a
$ sudo pkg install tmux
Updating repository catalogue
The following 1 packages will be installed:
 
        Upgrading tmux: 1.9.a -> 1.9.a_1
 
210 KB to be downloaded
 
Proceed with installing packages [y/N]:

関連項目