次世代パッケージ管理システム、pkg(8)FreeBSDのコレ知ってる?(3)(2/3 ページ)

» 2012年08月24日 00時00分 公開
[後藤大地,BSDコンサルティング株式会社]

pkg(8)のセットアップ

 pkg(8)を使い始めるには、まずpkg(8)の最新版をインストールしてから、リモートリポジトリをダウンロードする必要がある。奇妙に思うかもしれないが、システムには/usr/sbin/pkgがインストールされているが、最新版は/usr/local/sbin/pkgとしてインストールされる仕組みになっている。

 最新のpkg(8)を取得する操作は、次のように/usr/sbin/pkgを実行するだけでよい。

# pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg please wait
Installing pkg-1.0.r5_1... done
If you are upgrading from the old package format, first run:
  $ pkg2ng
usage: pkg [-v] [-d] [-j |-c ]  []
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 library
        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 '.
# 

  最新のpkg(8)をダウンロード

 次にリモートリポジトリを取得する。

# pkg update
Updating repository catalogue
repo.txz               100% 9682KB 345.8KB/s   1.1MB/s   00:28    
# 

  リモートリポジトリを取得

 これで準備完了だ。リモートリポジトリはrepo.sqliteとして/var/db/pkg/以下に配置される。

# ll -h /var/db/pkg/
total 58572
drwxr-xr-x  2 root  wheel  -  512B Aug 14 04:13 ./
drwxr-xr-x  8 root  wheel  -  512B Aug 14 04:10 ../
-rw-r--r--  1 root  wheel  -   97k Aug 14 04:12 local.sqlite
-rw-r--r--  1 root  wheel  -   57M Aug 14 04:13 repo.sqlite
# 

  /var/db/pkg/に展開されるリモートリポジトリデータとローカルのSQLiteデータベース

ソフトの検索とインストール、インストール済みソフトの確認

 pkg(8)の基本的な使い方は、関連するコマンド名やソフトウェア名で検索をかけ、インストールしたい対象を選択してインストール、というものになる。ソフトウェアの検索にはsearchサブコマンドを使う。例えばsudoをキーワードにして検索すると、次のような結果を得ることができる。

# pkg search sudo
sudo-1.8.5.p2                  Allow others to run commands as root
fxsudoku-0.5.1_22              An implementation of the Sudoku game
sudosh-1.8.2_5                 A sudo shell
sudoku_solver-1.20             A Sudoku Solver in C
sudoscript-2.1.2               Audited shells in Perl with sudo(8) and script(1)
ksudoku-0.4_6                  A Sudoku generator and solver for KDE
gnustep-sudoku-0.7             Sudoku solver and generator
sudoku-1.0.2                   Console based Sudoku games
sudosh2-1.0.4                  Second version of the sudo shell
sshsudo-1.0                    A bash script to run sudo command on multiple remote computers
# 

 ここではsudo-1.8.5.p2がインストールしたいソフトウェアなので、これをinstallサブコマンドの引数に指定してインストールを実施する。関連してインストールされるソフトウェア一覧が表示され、インストールしてもよいか確認を求められるので、「y」と入力してインストールを開始する。

# pkg install sudo-1.8.5.p2
Updating repository catalogue
Repository catalogue is up-to-date, no need to fetch fresh copy
The following packages will be installed:
        Installing libiconv: 1.14
        Installing gettext: 0.18.1.1
        Installing sudo: 1.8.5.p2
The installation will require 17 MB more space
6 MB to be downloaded
Proceed with installing packages [y/N]: y
libiconv-1.14.txz       100%  591KB 147.6KB/s 180.6KB/s   00:04    
gettext-0.18.1.1.txz    100% 4999KB 277.7KB/s 419.0KB/s   00:18    
sudo-1.8.5.p2.txz       100%  566KB 141.5KB/s 215.9KB/s   00:04    
Checking integrity... done
Installing libiconv-1.14... done
Installing gettext-0.18.1.1... done
Installing sudo-1.8.5.p2... done
# 

 システムにインストールされたソフトウェアの一覧はinfoサブコマンドで表示できる。

# pkg info
gettext-0.18.1.1               GNU gettext package
libiconv-1.14                  A character set conversion library
pkg-1.0.r5_1                   New generation package manager
sudo-1.8.5.p2                  Allow others to run commands as root
# 

 個別のソフトウェアに関する情報はinfoサブコマンドに-fを指定することで取得可能だ。

# pkg info -f sudo-1.8.5.p2
Name           : sudo
Version        : 1.8.5.p2
Origin         : security/sudo
Prefix         : /usr/local
Categories     : security
Licenses       : sudo 
Maintainer     : wxs@FreeBSD.org
WWW            : http://www.courtesan.com/sudo/
Comment        : Allow others to run commands as root
Options        : 
        AUDIT: on
        DISABLE_AUTH: off
        DISABLE_ROOT_SUDO: off
        INSULTS: off
        LDAP: off
        NLS: on
        NOARGS_SHELL: off
        OPIE: off
Flat size      : 2 MB
Description    : 
This is the CU version of sudo.
Sudo is a program designed to allow a sysadmin to give limited root
privileges to users and log root activity.  The basic philosophy is to
give as few privileges as possible but still allow people to get their
work done.
MAILING LISTS:
Please send bugs, problems, comments, etc to sudo-bugs@courtesan.com
There is a mailing list that receives announcements whenever a new
version of sudo is released.  You can subscribe to it by sending a
message to "majordomo@courtesan.com" that includes the line
"subscribe sudo-announce".  There is also a list for people working
on sudo.  The command to add yourself is "subscribe sudo-workers".
WWW: http://www.courtesan.com/sudo/
# 

 yを入力せずにインストールさせるには、installサブコマンドに-yを指定するか、またはyes | pkgのようにyes(1)コマンドをパイプで接続すればよい。

 一度インストールしたソフトウェアのパッケージは/var/cache/pkg/All/にキャッシュされる。

# ll -h /var/cache/pkg/All/
total 6312
drwxr-xr-x  2 root  wheel  -  512B Aug 14 04:53 ./
drwxr-xr-x  3 root  wheel  -  512B Aug  4 03:29 ../
-rw-------  1 root  wheel  -  4.9M Aug 14 04:53 gettext-0.18.1.1.txz
-rw-------  1 root  wheel  -  590k Aug 14 04:53 libiconv-1.14.txz
-rw-------  1 root  wheel  -  565k Aug 14 04:53 sudo-1.8.5.p2.txz
# 

 このため、二度目以降のインストール操作ではダウンロードの操作が発生せず、素早くインストールできる。

Copyright © ITmedia, Inc. All Rights Reserved.

RSSについて

アイティメディアIDについて

メールマガジン登録

@ITのメールマガジンは、 もちろん、すべて無料です。ぜひメールマガジンをご購読ください。