「pkg」の版間の差分

提供: FreeBSD入門
移動: 案内検索
(すでのサードパーティ製ソフトウェアがインストールされている場合)
(ダウンロードが Operation timed out になってしまう)
 
(同じ利用者による、間の14版が非表示)
行1: 行1:
<!-- vim: fileencoding=utf-8 filetype=mediawiki
+
[[FreeBSD]]の[[pkg]](/usr/sbin/pkg)は、次世代パッケージ管理システムとそのコマンドです。[[FreeBSD]] 10-CURRENT から採用されました。RELEASE版では、[[FreeBSD 10.0-RELEASE]]から利用できます。バイナリパッケージであるため、コンパイルが必要ありません。バイナリパッケージのメリットは、コンパイルがすでに終わってることでしょう。また、[[ports]]と併用できます。独自のビルドオプションなどを使いたいパッケージは、[[ports]]からビルドし、それ以外を[[pkg]]でインストールできます。
-->
+
[[pkg]]は、次世代パッケージ管理システムとそのコマンドです。
+
[[FreeBSD]] 10-CURRENT から採用されました。
+
  
 
'''読み方'''
 
'''読み方'''
行9: 行6:
  
 
== 概要 ==
 
== 概要 ==
 
 
[[pkg]]は、次世代パッケージ管理システムとそのコマンドです。
 
[[pkg]]は、次世代パッケージ管理システムとそのコマンドです。
[[FreeBSD]] 10-CURRENT から採用されました。
+
[[FreeBSD]] 10-CURRENT から採用されました。[[FreeBSD]] 9.1-RELEASE で利用できます。[[FreeBSD 10.0-RELEASE]]では、デフォルトで使用できます。
[[FreeBSD]] 9.1-RELEASE で利用できます。
+
/usr/sbin/pkg
 +
 
 +
[[FreeBSD]]の[[pkg]](8)とは、Ubuntuのapt-get、CentOSのyumをイメージのようなものと言えます。
  
 
[[ports|Ports Collection]]をベースに1-2週間ごとにパッケージが更新されます。
 
[[ports|Ports Collection]]をベースに1-2週間ごとにパッケージが更新されます。
 
最新のコレクションをバイナリでインストール・アップグレードできます。
 
最新のコレクションをバイナリでインストール・アップグレードできます。
  
== 設定 ==
+
以下の[[htop]]の動画の前半に[[pkg]]を利用している例があります。
 +
<html>
 +
<iframe width="560" height="315" src="//www.youtube.com/embed/YTH-CT4spAU" frameborder="0" allowfullscreen></iframe>
 +
</html>
 +
== はじめてのpkg入門 ==
 +
ここでは、簡単に[[pkg]]コマンドの使い方を紹介します。詳しくは、このあとのセクションをお読みください。
 +
ここでは、インストール、削除、アップデート、パッケージ情報の検索や表示を紹介します。
  
=== 設定ファイル ===
+
パッケージのインストールは、以下の通りです。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg install zsh
 +
</syntaxhighlight>
  
 +
パッケージの削除は、pkg deleteです。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg delete zsh
 +
</syntaxhighlight>
 +
 +
パッケージのアップデート手順は、以下の通りです。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg update
 +
$ sudo pkg upgrade
 +
</syntaxhighlight>
 +
 +
パッケージを探したい場合は、search を使用します。
 +
<syntaxhighlight lang="bash">
 +
$ pkg search vim
 +
</syntaxhighlight>
 +
 +
インストールされているパッケージを調べるには、infoを使用します。
 +
<syntaxhighlight lang="bash">
 +
# すべてのパッケージを表示
 +
$ pkg info '*'
 +
# 指定パッケージだけ表示
 +
$ pkg info zsh
 +
</syntaxhighlight>
 +
== 設定 ==
 +
=== 設定ファイル ===
 
* /usr/local/etc/pkg.conf
 
* /usr/local/etc/pkg.conf
  
=== make.conf ===
+
[[FreeBSD 10.0-RELEASE]] /etc/pkg/FreeBSD.conf
 +
<syntaxhighlight lang="bash">
 +
# $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
 +
}
 +
</syntaxhighlight>
  
 +
=== make.conf ===
 
[[FreeBSD]] 10.x 未満の場合は、下記設定を /etc/make.conf にします。
 
[[FreeBSD]] 10.x 未満の場合は、下記設定を /etc/make.conf にします。
  
行37: 行80:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% pkg help
 
% pkg help
usage: pkg [-v] [-d] [-j <jail name or id>|-c <chroot path>] <command> [<args>]
+
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:
 
Global options supported:
 
         -d            Increment debug level
 
         -d            Increment debug level
         -j            Execute pkg(1) inside a jail(8)
+
         -j            Execute pkg(8) inside a jail(8)
         -c            Execute pkg(1) inside a chroot(8)
+
         -c            Execute pkg(8) inside a chroot(8)
         -v            Display pkg(1) version
+
        -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:
 
Commands supported:
 
         add            Registers a package and installs it on the system
 
         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
 
         audit          Reports vulnerable packages
 
         autoremove    Removes orphan packages
 
         autoremove    Removes orphan packages
行52: 行101:
 
         check          Checks for missing dependencies and database consistency
 
         check          Checks for missing dependencies and database consistency
 
         clean          Cleans old packages from the cache
 
         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
 
         create        Creates software package distributions
 
         delete        Deletes packages from the database and the system
 
         delete        Deletes packages from the database and the system
行58: 行109:
 
         info          Displays information about installed packages
 
         info          Displays information about installed packages
 
         install        Installs packages from remote package repositories
 
         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
 
         query          Queries information about installed packages
 
         register      Registers a package into the local database
 
         register      Registers a package into the local database
行65: 行118:
 
         search        Performs a search of package repository catalogues
 
         search        Performs a search of package repository catalogues
 
         set            Modifies information about packages in the local database
 
         set            Modifies information about packages in the local database
 +
        ssh            ssh packages to be used via ssh
 
         shell          Opens a debug shell
 
         shell          Opens a debug shell
 
         shlib          Displays which packages link against a specific shared library
 
         shlib          Displays which packages link against a specific shared library
 
         stats          Displays package database statistics
 
         stats          Displays package database statistics
 +
        unlock        Unlocks a package, allowing modification or deletion
 
         update        Updates package repository catalogues
 
         update        Updates package repository catalogues
 
         updating      Displays UPDATING information for a package
 
         updating      Displays UPDATING information for a package
行73: 行128:
 
         version        Displays the versions of installed packages
 
         version        Displays the versions of installed packages
 
         which          Displays which package installed a specific file
 
         which          Displays which package installed a specific file
 +
 +
Commands provided by plugins:
  
 
For more information on the different commands see 'pkg help <command>'.
 
For more information on the different commands see 'pkg help <command>'.
行149: 行206:
  
 
=== パッケージをインストールする ===
 
=== パッケージをインストールする ===
 
+
パッケージのインストールの例です。
パッケージのインストールの例。
+
 
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
pkg install tmux
+
$ pkg install tmux
 +
</syntaxhighlight>
 +
=== パッケージをアンインストールする ===
 +
パッケージの削除には、以下のコマンドを実行します。
 +
<syntaxhighlight lang="bash">
 +
$ pkg delete tmux
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
=== バージョンチェック ===
 
=== バージョンチェック ===
 
+
アップデートできるパッケージがないか調べられます。
アップデートできるパッケージがないか調べます。
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
pkg version
+
$ pkg version
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
アップデート可能なパッケージには、'&lt;' が表示されます。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% pkg version
 
% pkg version
行170: 行229:
 
adns-1.4_1                        =
 
adns-1.4_1                        =
 
amap-5.2                          =
 
amap-5.2                          =
 +
</syntaxhighlight>
 +
==== 時代遅れなパッケージを調べる ====
 +
アップデート可能なパッケージだけを表示するには、以下のオプションを追加します。
 +
<syntaxhighlight lang="bash">
 +
$ pkg version -l '<'
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== データベースのダウンロード ===
+
以下は実行例です。
 +
<syntaxhighlight lang="bash">
 +
$ pkg version -l '<'
 +
git-1.9.2                          <
 +
hydra-7.6                          <
 +
libxml2-2.9.1                      <
 +
mariadb55-client-5.5.35            <
 +
mariadb55-server-5.5.35            <
 +
openjdk6-b31_2,1                  <
 +
p5-IO-Socket-SSL-1.984            <
 +
py27-pip-1.5.4                    <
 +
sqlite3-3.8.4.2                    <
 +
subversion-1.8.8_2                <
 +
vim-7.4.281                        <
 +
</syntaxhighlight>
  
 +
どのバージョンに上がるのかは、 -v をつけることで確認できます。
 +
<syntaxhighlight lang="bash">
 +
$ pkg version -l '<' -v
 +
git-1.9.2                          <  needs updating (port has 1.9.3)
 +
hydra-7.6                          <  needs updating (port has 8.0)
 +
libxml2-2.9.1                      <  needs updating (port has 2.9.1_1)
 +
mariadb55-client-5.5.35            <  needs updating (port has 5.5.35_1)
 +
mariadb55-server-5.5.35            <  needs updating (port has 5.5.35_1)
 +
openjdk6-b31_2,1                  <  needs updating (port has b31_3,1)
 +
p5-IO-Socket-SSL-1.984            <  needs updating (port has 1.988)
 +
py27-pip-1.5.4                    <  needs updating (port has 1.5.6)
 +
sqlite3-3.8.4.2                    <  needs updating (port has 3.8.4.3)
 +
subversion-1.8.8_2                <  needs updating (port has 1.8.9)
 +
vim-7.4.281                        <  needs updating (port has 7.4.295)
 +
</syntaxhighlight>
 +
 +
=== データベースのダウンロード ===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% sudo pkg update -f
 
% sudo pkg update -f
行180: 行275:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== バージョンアップ ===
 
=== バージョンアップ ===
 
 
新しいバージョンのパッケージにアップグレードします。
 
新しいバージョンのパッケージにアップグレードします。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
sudo pkg upgrade
+
$ sudo pkg upgrade
 
</syntaxhighlight>
 
</syntaxhighlight>
  
ドライラン(Dry run)します。
+
ドライラン(Dry run)します。ドライランは、実際には、インストールしません。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
sudo pkg upgrade -n
+
$ sudo pkg upgrade -n
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== パッケージの検証 ===
+
以下は、ドライランの実行例です。
 +
<syntaxhighlight lang="bash">
 +
$ pkg upgrade -n
 +
Updating repository catalogue
 +
Upgrades have been requested for the following 13 packages:
  
脆弱性のあるソフトウェアがインストールされていないか、検証できます。
+
        Upgrading git: 1.9.2 -> 1.9.3
 +
        Upgrading hydra: 7.6 -> 8.0
 +
        Upgrading libxml2: 2.9.1 -> 2.9.1_1
 +
        Reinstalling libxslt-1.1.28_3 (direct dependency changed)
 +
        Installing apache22: 2.2.27_2
 +
        Upgrading p5-IO-Socket-SSL: 1.984 -> 1.988
 +
        Reinstalling php55-5.5.12 (options changed)
 +
        Reinstalling php55-extensions-1.8 (options changed)
 +
        Upgrading py27-pip: 1.5.4 -> 1.5.6
 +
        Upgrading sqlite3: 3.8.4.2 -> 3.8.4.3
 +
        Upgrading subversion: 1.8.8_2 -> 1.8.9
 +
        Upgrading vim: 7.4.281 -> 7.4.295
 +
        Reinstalling mod_php55-5.5.12 (direct dependency changed)
  
 +
The upgrade will require 10 MB more space
 +
 +
20 MB to be downloaded
 +
</syntaxhighlight>
 +
=== インストールされているファイルからパッケージを調べる ===
 +
任意のファイルがどのパッケージによってインストールされたのか調べるには、以下のコマンドを実行します。
 +
<syntaxhighlight lang="bash">
 +
$ pkg which /usr/local/libexec/apache24/mod_remoteip.so
 +
/usr/local/libexec/apache24/mod_remoteip.so was installed by package apache24-2.4.9
 +
</syntaxhighlight>
 +
上記の結果から mod_remoteip.so は、 apache24 のパッケージに含まれていることがわかりました。
 +
=== 使われていないインストールされているパッケージの依存を削除する ===
 +
autoremove は、孤児のパッケージを削除するために使われます。
 +
依存関係でインストールされたか、すでに使われないパッケージを削除します。
 +
<syntaxhighlight lang="bash">
 +
pkg autoremove
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg autoremove
 +
Deinstallation has been requested for the following 14 packages:
 +
 +
        bison-2.7.1,1
 +
        curl-hiphop-7.36.0
 +
        db42-4.2.52_5
 +
        glog-0.3.3
 +
        libdwarf-20130207
 +
        libevent-hiphop-1.4.14b_3
 +
        libmemcached-1.0.7_2
 +
        libtool-2.4.2_3
 +
        libunwind-20121006
 +
        libxslt-1.1.28_3
 +
        re2c-0.13.6
 +
        t1lib-5.1.2_2,1
 +
        tbb-4.2.2
 +
        zip-3.0
 +
 +
The deinstallation will free 35 MB
 +
 +
Proceed with deinstalling packages [y/N]:
 +
</syntaxhighlight>
 +
=== 古くなったパッケージを削除する ===
 +
[[pkg]]のパッケージは、キャッシュディレクトリ(/var/cache/pkg/All)のパッケージのアーカイブ(txz)が保存されています。pkg upgradeでアップデートするときに、古いパッケージは自動的に削除されません。キャッシュディレクトリは、pkg.confのPKG_CACHEDIR変数で定義します。
 +
 +
古いパッケージを削除するには、以下のコマンドを実行します。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg clean
 +
</syntaxhighlight>
 +
 +
以下に実行例を示します。パッケージ数が多いため、途中省略しています。
 +
<syntaxhighlight lang="bash">
 +
$ du -hs /var/cache/pkg/All
 +
1.2G    /var/cache/pkg/All
 +
$ ls /var/cache/pkg/All|wc
 +
    516    516  10836
 +
$ sudo pkg clean
 +
The following package files will be deleted from the cache directory
 +
/var/cache/pkg:
 +
 +
Package:                      Origin:              Reason:
 +
All/gettext-0.18.3.1.txz      devel/gettext        Superseded by gettext-0.18.3.1_1
 +
All/sudo-1.8.9.p5.txz          security/sudo        Superseded by sudo-1.8.10.p3
 +
... 省略 ...
 +
All/php5-xml-5.4.28.txz        textproc/php5-xml    Size mismatch
 +
All/php55-gd-5.5.12.txz        graphics/php55-gd    Size mismatch
 +
 +
Proceed with cleaning the cache [y/N]:
 +
Deleting:
 +
        /var/cache/pkg/All/gettext-0.18.3.1.txz
 +
        /var/cache/pkg/All/sudo-1.8.9.p5.txz
 +
... 省略
 +
        /var/cache/pkg/All/php5-xml-5.4.28.txz
 +
        /var/cache/pkg/All/php55-gd-5.5.12.txz
 +
All done
 +
$ du -hs /var/cache/pkg/All
 +
217M    /var/cache/pkg/All
 +
$ ls /var/cache/pkg/All|wc
 +
      98      98    2021
 +
</syntaxhighlight>
 +
 +
=== パッケージの検証 ===
 +
脆弱性のあるソフトウェアがインストールされていないか、検証できます。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
pkg audit -F
 
pkg audit -F
行212: 行404:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== パッケージの情報をする ===
+
=== リモートパッケージリポジトリのパッケージの情報を取得する ===
 +
リモートパッケじリポジトリから指定したパターンを検索して、表示します。
 +
query は、任意の文字列が入ります。パターン(query)には、正規表現が指定できます。
 +
<syntaxhighlight lang="bash">
 +
pkg search 'query'
 +
</syntaxhighlight>
  
 +
ここでは、簡単に検索の例を取り上げます。
 +
 +
[[vim]]の検索例です。
 +
<syntaxhighlight lang="bash">
 +
$ pkg search vim
 +
vim-7.4.295
 +
vim-lite-7.4.295
 +
vimpager-1.8.8
 +
xpi-vimperator-3.5
 +
</syntaxhighlight>
 +
 +
少しだけ正規表現を使用した[[gcc]]の検索例です。
 +
<syntaxhighlight lang="bash">
 +
$ pkg search '^gcc'
 +
gcc-4.7.3_1
 +
gcc-arm-embedded-4.8.20140314
 +
gcc-aux-20140422_2
 +
gcc-ecj-4.5
 +
gcc410-4.10.0.s20140518
 +
gcc46-4.6.4_1,1
 +
gcc47-4.7.4.20140419
 +
gcc47-aux-20130411_4
 +
gcc48-4.8.3.s20140508
 +
gcc49-4.9.1.s20140507
 +
gccmakedep-1.0.2_1
 +
</syntaxhighlight>
 +
 +
検索のより詳しいことについては、続きをお読みください。
 +
==== リモートパッケージリポジトリの一覧を取得する ====
 +
リモートパッケージリポジトリのすべてのパッケージを表示します。
 +
<syntaxhighlight lang="bash">
 +
pkg search '.'
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="bash">
 +
user@b0:/ % pkg search '.'|wc
 +
  22691  22691  457583
 +
</syntaxhighlight>
 +
==== リモートのパッケージを検索する ====
 +
[[pkg]]のsearchコマンドは、以下の引数をとります。
 +
<syntaxhighlight lang="bash">
 +
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'.
 +
</syntaxhighlight>
 +
 +
[[vim]]を検索してみましょう。
 +
<syntaxhighlight lang="bash">
 +
user@b0:/ % pkg search vim
 +
vim-7.4.110_3
 +
vim-lite-7.4.110
 +
vimpager-1.8.3
 +
xpi-vimperator-3.5
 +
</syntaxhighlight>
 +
 +
クエリーには、正規表現を利用できます。[[gcc]]ではじまるパッケージだけ調べるには、^gcc を検索します。
 +
<syntaxhighlight lang="bash">
 +
$ pkg search '^gcc'
 +
gcc-4.7.3_1
 +
gcc-arm-embedded-4.8.20140314
 +
gcc-aux-20140422_2
 +
gcc-ecj-4.5
 +
gcc410-4.10.0.s20140518
 +
gcc46-4.6.4_1,1
 +
gcc47-4.7.4.20140419
 +
gcc47-aux-20130411_4
 +
gcc48-4.8.3.s20140508
 +
gcc49-4.9.1.s20140507
 +
gccmakedep-1.0.2_1
 +
</syntaxhighlight>
 +
==== リモートのパッケージの情報の詳細を取得する ====
 +
<syntaxhighlight lang="bash">
 +
user@b0:/ % pkg search sshsudo
 +
sshsudo-1.0
 +
</syntaxhighlight>
 +
-f オプションで詳細情報が取得できます。
 +
<syntaxhighlight lang="bash">
 +
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/
 +
</syntaxhighlight>
 +
 +
以下は、[[tmux]]の例です。Optionsのセクションで、[[pkg]]のパッケージが[[ports]]パッケージのmake configで指定できるオプションのいずれを有効にしてビルドされているか確認できます。 Shared Libs required で依存するシェアードオブジェクトの確認もできます。
 +
<syntaxhighlight lang="bash">
 +
$ pkg search -f tmux
 +
tmux-1.9.a_1
 +
Name          : tmux
 +
Version        : 1.9.a_1
 +
Installed on  : Thu Jan  1 09:00:00 JST 1970
 +
Origin        : sysutils/tmux
 +
Architecture  : freebsd:10:x86:64
 +
Prefix        : /usr/local
 +
Categories    : sysutils
 +
Licenses      : BSD2CLAUSE
 +
Maintainer    : gahr@FreeBSD.org
 +
WWW            : http://www.sourceforge.net/projects/tmux/
 +
Comment        : Terminal Multiplexer
 +
Options        :
 +
        BACKSPACE      : off
 +
        DOCS          : on
 +
        EXAMPLES      : on
 +
        LIBEVENT2      : off
 +
        LIBEVENT_STATIC: off
 +
Shared Libs required:
 +
        libevent-1.4.so.4
 +
Flat size      : 556KiB
 +
Pkg size      : 210 KB
 +
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/
 +
</syntaxhighlight>
 +
=== インストールされているパッケージの情報を取得する ===
 +
==== インストールされているパッケージの一覧を取得する ====
 +
インストールされているすべてのパッケージが確認できます。
 +
<syntaxhighlight lang="bash">
 +
$ pkg info
 +
</syntaxhighlight>
 +
==== パッケージの情報を取得する ====
 +
インストールされているパッケージの情報を確認します。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% pkg info tmux
 
% pkg info tmux
 
tmux-1.8                      A Terminal Multiplexer
 
tmux-1.8                      A Terminal Multiplexer
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
==== パッケージのメッセージ(pkg-message)を取得する ====
 +
-D で pkg-message を表示できます。以下の例では、[[ports]]でいえば、/usr/ports/www/apache24/pkg-message を表示しています。
 +
<syntaxhighlight lang="bash">
 +
$ pkg info -D apache24
 +
apache24-2.4.9_2:
 +
To run apache www server from startup, add apache24_enable="yes"
 +
in your /etc/rc.conf. Extra options can be found in startup script.
  
インストールされているファイルの一覧を表示する。
+
Your hostname must be resolvable using at least 1 mechanism in
 +
/etc/nsswitch.conf typically DNS or /etc/hosts or apache might
 +
have issues starting depending on the modules you are using.
 +
</syntaxhighlight>
 +
==== パッケージの情報を詳細な取得する ====
 +
ビルドオプション(portsのmake config)や共有ライブラリ(シェアードライブラリ)の依存なども確認できます。
 +
<syntaxhighlight lang="bash">
 +
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/
 +
</syntaxhighlight>
 +
==== インストールされているファイルの一覧を取得する ====
 +
インストールされているファイルの一覧を表示できます。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% pkg info -l tmux
 
% pkg info -l tmux
行242: 行624:
 
/usr/local/share/licenses/tmux-1.8/catalog.mk
 
/usr/local/share/licenses/tmux-1.8/catalog.mk
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
=== インストールされているパッケージの統計を表示する ===
 +
<syntaxhighlight lang="bash">
 +
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
 +
</syntaxhighlight>
 +
=== パッケージをロックとアンロック ===
 +
==== パッケージのロック ====
 +
パッケージの更新をロックできます。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg lock tmux
 +
tmux-1.9.a: lock this package? [y/N]: y
 +
Locking tmux-1.9.a
 +
</syntaxhighlight>
 +
==== パッケージのロック状態の確認 ====
 +
パッケージがロックされているかは、infoで確認します。
 +
;yes:ロックされている
 +
;no:ロックされていない
 +
<syntaxhighlight lang="bash">
 +
$ pkg info -k tmux vim
 +
tmux-1.9.a                    yes
 +
vim-7.4.192_1                  no
 +
</syntaxhighlight>
  
 +
すべてのパッケージのロックの状態を確認する場合は、-aを指定します。
 +
<syntaxhighlight lang="bash">
 +
$ pkg info -k -a
 +
</syntaxhighlight>
 +
==== パッケージのアンロック ====
 +
パッケージのロックは、アンロックオプションで解除できます。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg unlock tmux
 +
tmux-1.9.a: unlock this package? [y/N]: y
 +
Unlocking tmux-1.9.a
 +
</syntaxhighlight>
 +
==== ロック状態のパッケージはアップデートできない ====
 +
ロック状態のパッケージは、アップデートがあっても、インストールされません。
 +
<syntaxhighlight lang="bash">
 +
$ 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]:
 +
</syntaxhighlight>
 +
 +
=== パッケージデータベースのバックアップ ===
 +
明示的にパッケージのデータベースをバックアップするには、以下のコマンドを実行します。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg backup -d pkg.db
 +
</syntaxhighlight>
 +
 +
毎日バックアップが取りたい場合には、 perodic のスクリプトを使用します。
 +
/etc/default/perodic.conf では、デフォルトで、毎日バックアップすることになっています。
 +
<syntaxhighlight lang="bash">
 +
# 220.backup-pkgdb
 +
daily_backup_pkgdb_enable="YES"                        # Backup /var/db/pkg
 +
daily_backup_pkgdb_dir="/var/backups"
 +
</syntaxhighlight>
 +
 +
== pkgコマンドが動かない! ==
 +
=== Repo FreeBSD needs schema upgrade from 2006 to 2010 but it is opened readonly ===
 +
pkgコマンドをアップグレードしたら、動かなくなってしまいました。
 +
-fオプションをつけて、アップデートしてあげるとなおります。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg search libressl
 +
pkg: Repo FreeBSD needs schema upgrade from 2006 to 2010 but it is opened readonly
 +
pkg: need to re-create repo FreeBSD to upgrade schema version
 +
[1]    27342 exit 70    sudo pkg search libressl
 +
 +
$ sudo pkg update -f
 +
Updating repository catalogue
 +
Fetching meta.txz: 100% of 944 B
 +
Fetching digests.txz: 100% of 1 MB
 +
Fetching packagesite.txz: 100% of 5 MB
 +
 +
Adding new entries: 100%
 +
Incremental update completed, 23313 packages processed:
 +
0 packages updated, 0 removed and 23313 added.
 +
</syntaxhighlight>
 +
=== ダウンロードが Operation timed out になってしまう ===
 +
インターネットが混雑している場合に、ダウンロードが失敗してしまうことがあります。これを回避する方法として、タイムアウトを長くする方法があります。
 +
/usr/local/etc/pkg.conf の設定ファイルに以下のタイムアウトの設定を追加します。時間は適当に設定してください。
 +
<syntaxhighlight lang="bash">
 +
FETCH_TIMEOUT=300
 +
</syntaxhighlight>
 +
 +
== 関連項目 ==
 
* [[ports]]
 
* [[ports]]
 
* [[ソフトウェアの管理]]
 
* [[ソフトウェアの管理]]
 +
* [[FreeBSD 10.0 環境構築]]
 +
* [[FreeBSDの環境構築]]
 +
* [[pkg 1.5.0]]
 +
* [[Chef]]
 +
* [[libc.so.7 version FBSD_1.4 required by sudo]]
 +
<!-- vim: fileencoding=utf-8 filetype=mediawiki
 +
-->

2020年6月6日 (土) 23:53時点における最新版

FreeBSDpkg(/usr/sbin/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では、デフォルトで使用できます。

/usr/sbin/pkg

FreeBSDpkg(8)とは、Ubuntuのapt-get、CentOSのyumをイメージのようなものと言えます。

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

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

はじめてのpkg入門

ここでは、簡単にpkgコマンドの使い方を紹介します。詳しくは、このあとのセクションをお読みください。 ここでは、インストール、削除、アップデート、パッケージ情報の検索や表示を紹介します。

パッケージのインストールは、以下の通りです。

$ sudo pkg install zsh

パッケージの削除は、pkg deleteです。

$ sudo pkg delete zsh

パッケージのアップデート手順は、以下の通りです。

$ sudo pkg update
$ sudo pkg upgrade

パッケージを探したい場合は、search を使用します。

$ pkg search vim

インストールされているパッケージを調べるには、infoを使用します。

# すべてのパッケージを表示
$ pkg info '*'
# 指定パッケージだけ表示
$ pkg info zsh

設定

設定ファイル

  • /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 '<'

以下は実行例です。

$ pkg version -l '<'
git-1.9.2                          <
hydra-7.6                          <
libxml2-2.9.1                      <
mariadb55-client-5.5.35            <
mariadb55-server-5.5.35            <
openjdk6-b31_2,1                   <
p5-IO-Socket-SSL-1.984             <
py27-pip-1.5.4                     <
sqlite3-3.8.4.2                    <
subversion-1.8.8_2                 <
vim-7.4.281                        <

どのバージョンに上がるのかは、 -v をつけることで確認できます。

$ pkg version -l '<' -v
git-1.9.2                          <   needs updating (port has 1.9.3)
hydra-7.6                          <   needs updating (port has 8.0)
libxml2-2.9.1                      <   needs updating (port has 2.9.1_1)
mariadb55-client-5.5.35            <   needs updating (port has 5.5.35_1)
mariadb55-server-5.5.35            <   needs updating (port has 5.5.35_1)
openjdk6-b31_2,1                   <   needs updating (port has b31_3,1)
p5-IO-Socket-SSL-1.984             <   needs updating (port has 1.988)
py27-pip-1.5.4                     <   needs updating (port has 1.5.6)
sqlite3-3.8.4.2                    <   needs updating (port has 3.8.4.3)
subversion-1.8.8_2                 <   needs updating (port has 1.8.9)
vim-7.4.281                        <   needs updating (port has 7.4.295)

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

% 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 upgrade -n
Updating repository catalogue
Upgrades have been requested for the following 13 packages:
 
        Upgrading git: 1.9.2 -> 1.9.3
        Upgrading hydra: 7.6 -> 8.0
        Upgrading libxml2: 2.9.1 -> 2.9.1_1
        Reinstalling libxslt-1.1.28_3 (direct dependency changed)
        Installing apache22: 2.2.27_2
        Upgrading p5-IO-Socket-SSL: 1.984 -> 1.988
        Reinstalling php55-5.5.12 (options changed)
        Reinstalling php55-extensions-1.8 (options changed)
        Upgrading py27-pip: 1.5.4 -> 1.5.6
        Upgrading sqlite3: 3.8.4.2 -> 3.8.4.3
        Upgrading subversion: 1.8.8_2 -> 1.8.9
        Upgrading vim: 7.4.281 -> 7.4.295
        Reinstalling mod_php55-5.5.12 (direct dependency changed)
 
The upgrade will require 10 MB more space
 
20 MB to be downloaded

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

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

$ 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 のパッケージに含まれていることがわかりました。

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

autoremove は、孤児のパッケージを削除するために使われます。 依存関係でインストールされたか、すでに使われないパッケージを削除します。

pkg autoremove
$ sudo pkg autoremove
Deinstallation has been requested for the following 14 packages:
 
        bison-2.7.1,1
        curl-hiphop-7.36.0
        db42-4.2.52_5
        glog-0.3.3
        libdwarf-20130207
        libevent-hiphop-1.4.14b_3
        libmemcached-1.0.7_2
        libtool-2.4.2_3
        libunwind-20121006
        libxslt-1.1.28_3
        re2c-0.13.6
        t1lib-5.1.2_2,1
        tbb-4.2.2
        zip-3.0
 
The deinstallation will free 35 MB
 
Proceed with deinstalling packages [y/N]:

古くなったパッケージを削除する

pkgのパッケージは、キャッシュディレクトリ(/var/cache/pkg/All)のパッケージのアーカイブ(txz)が保存されています。pkg upgradeでアップデートするときに、古いパッケージは自動的に削除されません。キャッシュディレクトリは、pkg.confのPKG_CACHEDIR変数で定義します。

古いパッケージを削除するには、以下のコマンドを実行します。

$ sudo pkg clean

以下に実行例を示します。パッケージ数が多いため、途中省略しています。

$ du -hs /var/cache/pkg/All
1.2G    /var/cache/pkg/All
$ ls /var/cache/pkg/All|wc
     516     516   10836
$ sudo pkg clean
The following package files will be deleted from the cache directory
/var/cache/pkg:
 
Package:                       Origin:              Reason:
All/gettext-0.18.3.1.txz       devel/gettext        Superseded by gettext-0.18.3.1_1
All/sudo-1.8.9.p5.txz          security/sudo        Superseded by sudo-1.8.10.p3
... 省略 ...
All/php5-xml-5.4.28.txz        textproc/php5-xml    Size mismatch
All/php55-gd-5.5.12.txz        graphics/php55-gd    Size mismatch
 
Proceed with cleaning the cache [y/N]:
Deleting:
        /var/cache/pkg/All/gettext-0.18.3.1.txz
        /var/cache/pkg/All/sudo-1.8.9.p5.txz
... 省略
        /var/cache/pkg/All/php5-xml-5.4.28.txz
        /var/cache/pkg/All/php55-gd-5.5.12.txz
All done
$ du -hs /var/cache/pkg/All
217M    /var/cache/pkg/All
$ ls /var/cache/pkg/All|wc
      98      98    2021

パッケージの検証

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

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 は、任意の文字列が入ります。パターン(query)には、正規表現が指定できます。

pkg search 'query'

ここでは、簡単に検索の例を取り上げます。

vimの検索例です。

$ pkg search vim
vim-7.4.295
vim-lite-7.4.295
vimpager-1.8.8
xpi-vimperator-3.5

少しだけ正規表現を使用したgccの検索例です。

$ pkg search '^gcc'
gcc-4.7.3_1
gcc-arm-embedded-4.8.20140314
gcc-aux-20140422_2
gcc-ecj-4.5
gcc410-4.10.0.s20140518
gcc46-4.6.4_1,1
gcc47-4.7.4.20140419
gcc47-aux-20130411_4
gcc48-4.8.3.s20140508
gcc49-4.9.1.s20140507
gccmakedep-1.0.2_1

検索のより詳しいことについては、続きをお読みください。

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

リモートパッケージリポジトリのすべてのパッケージを表示します。

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'.

vimを検索してみましょう。

user@b0:/ % pkg search vim
vim-7.4.110_3
vim-lite-7.4.110
vimpager-1.8.3
xpi-vimperator-3.5

クエリーには、正規表現を利用できます。gccではじまるパッケージだけ調べるには、^gcc を検索します。

$ pkg search '^gcc'
gcc-4.7.3_1
gcc-arm-embedded-4.8.20140314
gcc-aux-20140422_2
gcc-ecj-4.5
gcc410-4.10.0.s20140518
gcc46-4.6.4_1,1
gcc47-4.7.4.20140419
gcc47-aux-20130411_4
gcc48-4.8.3.s20140508
gcc49-4.9.1.s20140507
gccmakedep-1.0.2_1

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

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/

以下は、tmuxの例です。Optionsのセクションで、pkgのパッケージがportsパッケージのmake configで指定できるオプションのいずれを有効にしてビルドされているか確認できます。 Shared Libs required で依存するシェアードオブジェクトの確認もできます。

$ pkg search -f tmux
tmux-1.9.a_1
Name           : tmux
Version        : 1.9.a_1
Installed on   : Thu Jan  1 09:00:00 JST 1970
Origin         : sysutils/tmux
Architecture   : freebsd:10:x86:64
Prefix         : /usr/local
Categories     : sysutils
Licenses       : BSD2CLAUSE
Maintainer     : gahr@FreeBSD.org
WWW            : http://www.sourceforge.net/projects/tmux/
Comment        : Terminal Multiplexer
Options        :
        BACKSPACE      : off
        DOCS           : on
        EXAMPLES       : on
        LIBEVENT2      : off
        LIBEVENT_STATIC: off
Shared Libs required:
        libevent-1.4.so.4
Flat size      : 556KiB
Pkg size       : 210 KB
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

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

インストールされているパッケージの情報を確認します。

% pkg info tmux
tmux-1.8                       A Terminal Multiplexer

パッケージのメッセージ(pkg-message)を取得する

-D で pkg-message を表示できます。以下の例では、portsでいえば、/usr/ports/www/apache24/pkg-message を表示しています。

$ pkg info -D apache24
apache24-2.4.9_2:
To run apache www server from startup, add apache24_enable="yes"
in your /etc/rc.conf. Extra options can be found in startup script.
 
Your hostname must be resolvable using at least 1 mechanism in
/etc/nsswitch.conf typically DNS or /etc/hosts or apache might
have issues starting depending on the modules you are using.

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

ビルドオプション(portsのmake config)や共有ライブラリ(シェアードライブラリ)の依存なども確認できます。

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

すべてのパッケージのロックの状態を確認する場合は、-aを指定します。

$ pkg info -k -a

パッケージのアンロック

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

$ 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]:

パッケージデータベースのバックアップ

明示的にパッケージのデータベースをバックアップするには、以下のコマンドを実行します。

$ sudo pkg backup -d pkg.db

毎日バックアップが取りたい場合には、 perodic のスクリプトを使用します。 /etc/default/perodic.conf では、デフォルトで、毎日バックアップすることになっています。

# 220.backup-pkgdb
daily_backup_pkgdb_enable="YES"                         # Backup /var/db/pkg
daily_backup_pkgdb_dir="/var/backups"

pkgコマンドが動かない!

Repo FreeBSD needs schema upgrade from 2006 to 2010 but it is opened readonly

pkgコマンドをアップグレードしたら、動かなくなってしまいました。 -fオプションをつけて、アップデートしてあげるとなおります。

$ sudo pkg search libressl
pkg: Repo FreeBSD needs schema upgrade from 2006 to 2010 but it is opened readonly
pkg: need to re-create repo FreeBSD to upgrade schema version
[1]    27342 exit 70    sudo pkg search libressl
 
$ sudo pkg update -f
Updating repository catalogue
Fetching meta.txz: 100% of 944 B
Fetching digests.txz: 100% of 1 MB
Fetching packagesite.txz: 100% of 5 MB
 
Adding new entries: 100%
Incremental update completed, 23313 packages processed:
0 packages updated, 0 removed and 23313 added.

ダウンロードが Operation timed out になってしまう

インターネットが混雑している場合に、ダウンロードが失敗してしまうことがあります。これを回避する方法として、タイムアウトを長くする方法があります。 /usr/local/etc/pkg.conf の設定ファイルに以下のタイムアウトの設定を追加します。時間は適当に設定してください。

FETCH_TIMEOUT=300

関連項目