FreeBSD 12のPortsの管理

FreeBSDでアプリをインストールする場合

  • pkgコマンドでインストール
  • Portsでインストール

の2通りあります。
両者の違いは、

  • pkgコマンド
    あらかじめコンパイルされたバイナリファイルをインストールする。速くインストールすることができる。
  • Ports
    ソースプログラムをダウンロードし、コンパイル、インストールを行う。コンパイルに時間がかかるけど、細かい設定が可能になる。

こんなところでしょうか。

今回は、こだわった設定を行いたいので、アプリをインストールするときには、すべてPortsを使うことにします。

Portsによるインストール方法

ちょっと細かくPortsによるインストール方法を解説します。

root@cafe:~ # cd /usr/ports/
root@cafe:/usr/ports # ls
.arcconfig      UIDs            distfiles       mail            shells
.gitattributes  UPDATING        dns             math            sysutils
.gitauthors     accessibility   editors         misc            textproc
.gitignore      arabic          emulators       multimedia      ukrainian
.gitmessage     archivers       finance         net             vietnamese
CHANGES         astro           french          net-im          www
CONTRIBUTING.md audio           ftp             net-mgmt        x11
COPYRIGHT       base            games           net-p2p         x11-clocks
GIDs            benchmarks      german          news            x11-drivers
Keywords        biology         graphics        palm            x11-fm
LEGAL           cad             hebrew          polish          x11-fonts
MOVED           chinese         hungarian       ports-mgmt      x11-servers
Makefile        comms           irc             portuguese      x11-themes
Mk              converters      japanese        print           x11-toolkits
README          databases       java            russian         x11-wm
Templates       deskutils       korean          science
Tools           devel           lang            security
root@cafe:/usr/ports # echo */wget
ftp/wget
root@cafe:/usr/ports # cd ftp/wget/
root@cafe:/usr/ports/ftp/wget #

OSインストール時に、Portsもインストールするように指定したため、最初から/usr/portsにPorts Collectionが入っています。
まず最初に、インストールしたいportsのディレクトリに移動します。
ここでは、wgetをインストールしたいために、/usr/ports/ftp/wgetへ移動しています。

root@cafe:/usr/ports/ftp/wget # make fetch
===>  License GPLv3+ accepted by the user
===>   wget-1.20.3 depends on file: /usr/local/sbin/pkg - found
=> wget-1.20.3.tar.lz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch https://ftpmirror.gnu.org/wget/wget-1.20.3.tar.lz
wget-1.20.3.tar.lz                                    2085 kB  322 kBps    06s
===> Fetching all distfiles required by wget-1.20.3 for building
root@cafe:/usr/ports/ftp/wget #

make fetchコマンドで、ソースプログラムを/usr/ports/distfiles/.にダウンロードします。

root@cafe:/usr/ports/ftp/wget # make config


make configコマンドであらかじめ準備されていればportsの設定画面が出てきます。これで細かい設定ができます。今回はデフォルトのままで「OK」を選択します。
ここで設定した内容は、/var/db/ports/の下に書き込まれて、再実行するときには、それが参照されます。
設定をやり直したい場合は、make rmconfigコマンドで設定内容を削除しておきます。

root@cafe:/usr/ports/ftp/wget # make extract
===>  License GPLv3+ accepted by the user
===>   wget-1.20.3 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by wget-1.20.3 for building
===>  Extracting for wget-1.20.3
=> SHA256 Checksum OK for wget-1.20.3.tar.lz.
root@cafe:/usr/ports/ftp/wget # ls -l work
total 4
-rw-r--r--   1 root  wheel     0 Sep 27 00:40 .extract_done.wget._usr_local
drwxr-xr-x  13 root  wheel  1024 Apr  5  2019 wget-1.20.3
root@cafe:/usr/ports/ftp/wget #

make extractコマンドでカレントディレクトリにworkディレクトリを作成し、その中にソースプログラムを展開します。

root@cafe:/usr/ports/ftp/wget # make patch
===>  Patching for wget-1.20.3
/usr/bin/sed -i.bak -e 's,WGETRC = $(sysconfdir)/wgetrc,&.sample,'  /usr/ports/ftp/wget/work/wget-1.20.3/doc/Makefile.in
/usr/bin/sed -i.bak -e 's,/usr/local/etc/wgetrc,/usr/local/etc/wgetrc,'  /usr/ports/ftp/wget/work/wget-1.20.3/doc/sample.wgetrc*  /usr/ports/ftp/wget/work/wget-1.20.3/doc/wget.texi
root@cafe:/usr/ports/ftp/wget #

make patchコマンドでportsで用意されたパッチを適用します。

root@cafe:/usr/ports/ftp/wget # make build
===>   wget-1.20.3 depends on package: libiconv>=1.14_11 - found
===>   wget-1.20.3 depends on executable: makeinfo - found
===>   wget-1.20.3 depends on executable: msgfmt - found
===>   wget-1.20.3 depends on package: perl5>=5.30.r1<5.31 - found
===>   wget-1.20.3 depends on shared library: libidn2.so - not found
===>  License GPLv3 accepted by the user
===>   libidn2-2.2.0 depends on file: /usr/local/sbin/pkg - found
=> libidn2-2.2.0.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
:
省略
:
/usr/local/bin/pod2man --center="GNU Wget" --release="GNU Wget 1.20.3" --utf8 wget.pod > wget.1 ||  /usr/local/bin/pod2man --center="GNU Wget" --release="GNU Wget 1.20.3" wget.pod > wget.1
Making all in po
Making all in util
Making all in fuzz
Making all in tests
Making all in testenv
root@cafe:/usr/ports/ftp/wget #

make buildコマンド(makeコマンド単体で打つのと同等)でコンパイルを実施します。バイナリファイルはworkディレクトリの下に作られます。このとき、必要なライブラリなどがあれば、それも事前にインストールを行います。

root@cafe:/usr/ports/ftp/wget # make install
===>  Staging for wget-1.20.3
===>   wget-1.20.3 depends on executable: indexinfo - found
===>   Generating temporary packing list
:
省略
:
Installing wget-1.20.3...
===> SECURITY REPORT:
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
/usr/local/bin/wget

      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type 'make deinstall'
      to deinstall the port if this is a concern.

      For more information, and contact details about the security
      status of this software, see the following webpage:
http://www.gnu.org/s/wget/
root@cafe:/usr/ports/ftp/wget #

make installコマンドでインストールを実施します。wokディレクトリにあるバイナリファイル、マニュアルなどを/usr/localの下の適切な場所にコピーします。
これまでのmake 何とかコマンドは後段のコマンドを入れたら前段の処理を自動で行ってくれるので、実際には

root@cafe:~ # cd /usr/ports/ftp/wget
root@cafe:/usr/ports/ftp/wget # make install

だけでOKです!

その他のコマンドです。

root@cafe:/usr/ports/ftp/wget # make deinstall
===>  Deinstalling for wget
===>   Deinstalling wget-1.20.3
Updating database digests format: 100%
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
        wget-1.20.3

Number of packages to be removed: 1

The operation will free 3 MiB.
[1/1] Deinstalling wget-1.20.3...
[1/1] Deleting files for wget-1.20.3: 100%
root@cafe:/usr/ports/ftp/wget #

make deinstallでインストールしたアプリ(パッケージ)を削除します。

root@cafe:/usr/ports/ftp/wget # make reinstall
===>  Deinstalling for wget
===>   wget not installed, skipping
===>  Installing for wget-1.20.3
===>  Checking if wget is already installed
===>   Registering installation for wget-1.20.3
Installing wget-1.20.3...
===> SECURITY REPORT:
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
/usr/local/bin/wget

      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type 'make deinstall'
      to deinstall the port if this is a concern.

      For more information, and contact details about the security
      status of this software, see the following webpage:
http://www.gnu.org/s/wget/
root@cafe:/usr/ports/ftp/wget #

make reinstallコマンドでパッケージを再インストールします。portsは一度インストールするとworkフォルダの下にフラグを立ててインストールしたことを覚えているので、make installコマンドで再インストールできなくなります。そのときに使います。

root@cafe:/usr/ports/ftp/wget # make clean
===>  Cleaning for libidn2-2.2.0
===>  Cleaning for libunistring-0.9.10_1
===>  Cleaning for wget-1.20.3
root@cafe:/usr/ports/ftp/wget # ls -l work
ls: work: No such file or directory
root@cafe:/usr/ports/ftp/wget #

make cleanコマンドでソースプログラムやコンパイルしたバイナリファイルなどを削除します。実施にはworkフォルダごと削除を行います。

Portsのアップデート

アプリのバージョンが上がったりすると、それに合わせてPortsもアップデートされます。

root@cafe:~ # portsnap fetch
Looking up portsnap.FreeBSD.org mirrors... 4 mirrors found.
Fetching public key from ipv4.aws.portsnap.freebsd.org... done.
Fetching snapshot tag from ipv4.aws.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Fetching snapshot generated at Sat Sep 26 09:20:12 JST 2020:
2a111d9d1bae024ca3f6dc87a28f38a467bb44b8b9e25f          85 MB 8067 kBps    11s
Extracting snapshot... done.
Verifying snapshot integrity... done.
Fetching snapshot tag from ipv4.aws.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Updating from Sat Sep 26 09:20:12 JST 2020 to Sun Sep 27 00:31:06 JST 2020.
Fetching 4 metadata patches... done.
Applying metadata patches... done.
Fetching 0 metadata files... done.
Fetching 92 patches.
(92/92) 100.00%  done.
done.
Applying patches...
done.
Fetching 10 new ports or files... done.
root@cafe:~ # portsnap extract
/usr/ports/.arcconfig
/usr/ports/.gitattributes
/usr/ports/.gitauthors
/usr/ports/.gitignore
/usr/ports/.gitmessage
/usr/ports/CHANGES
/usr/ports/CONTRIBUTING.md
/usr/ports/COPYRIGHT
:
省略
:
/usr/ports/x11/yeahconsole/
/usr/ports/x11/yelp/
/usr/ports/x11/zenity/
Building new INDEX files... done.
root@cafe:~ #

初めてportsnapコマンドを使うときには、portsnap fetchportsnap extractを実行します。これで、最新のportsがインストールされました。

root@cafe:~ # portsnap fetch update
Looking up portsnap.FreeBSD.org mirrors... 4 mirrors found.
Fetching snapshot tag from ipv4.aws.portsnap.freebsd.org... done.
Latest snapshot on server matches what we already have.
No updates needed.
Ports tree is already up to date.
root@cafe:~ #

次回からはportsnap fetch updateコマンドでOKです。

portsでインストールしたパッケージのアップデート

Portsをアップデートすると古くなったパッケージが出てきます。それをアップデートする方法です。

root@cafe:~ # pkg version -l "<"
automake-1.16.1_2                  <
gettext-runtime-0.20.1             <
gettext-tools-0.20.1_1             <
gmake-4.2.1_3                      <
help2man-1.47.11                   <
libiconv-1.14_11                   <
libidn2-2.2.0                      <
libtextstyle-0.20.1                <
libxml2-2.9.9                      <
nginx-1.16.1_4,2                   <
pcre-8.43_2                        <
pcre2-10.33                        <
perl5-5.30.0                       <
php74-7.4.0.r3                     <
pkgconf-1.6.3,1                    <
texinfo-6.6_4,1                    <
root@cafe:~ #

pkg version -lコマンドで古くなったパッケージの一覧を出すことができます。
それらを一つ一つmake reinstallしても良いのですが、まとめてアップデートするツールをインストールしておきます。

root@cafe:~ # cd /usr/ports/ports-mgmt/portmaster/
root@cafe:/usr/ports/ports-mgmt/portmaster # make install
:
省略
:
====> Compressing man pages (compress-man)
===>  Installing for portmaster-3.19_25
===>  Checking if portmaster is already installed
===>   Registering installation for portmaster-3.19_25
Installing portmaster-3.19_25...
root@cafe:/usr/ports/ports-mgmt/portmaster #

portmasterコマンドをインストールしておきます。

root@cafe:/usr/ports/ports-mgmt/portmaster # portmaster -a
===>>> Gathering distinfo list for installed ports

===>>> Starting check of installed ports for available updates
===>>> Launching child to update pkgconf-1.6.3,1 to pkgconf-1.7.3,1
:
省略
:
===>>> The following actions will be taken if you choose to proceed:
        Upgrade pkgconf-1.6.3,1 to pkgconf-1.7.3,1
        Upgrade libiconv-1.14_11 to libiconv-1.16
        Upgrade libxml2-2.9.9 to libxml2-2.9.10_1
        Upgrade pcre-8.43_2 to pcre-8.44
        Upgrade pcre2-10.33 to pcre2-10.35
        Upgrade automake-1.16.1_2 to automake-1.16.2
        Upgrade perl5-5.30.0 to perl5-5.30.3
        Upgrade texinfo-6.6_4,1 to texinfo-6.7_4,1
        Upgrade gettext-runtime-0.20.1 to gettext-runtime-0.21
        Upgrade gettext-tools-0.20.1_1 to gettext-tools-0.21
        Upgrade libtextstyle-0.20.1 to libtextstyle-0.21
        Upgrade gmake-4.2.1_3 to gmake-4.3_2
        Upgrade help2man-1.47.11 to help2man-1.47.16
        Upgrade libidn2-2.2.0 to libidn2-2.3.0_1
        Upgrade nginx-1.16.1_4,2 to nginx-1.18.0_25,2
        Upgrade php74-7.4.0.r3 to php74-7.4.10

===>>> Proceed? y/n [y]

依存関係を含めて、アップデートの確認画面が出るので、yを選択します。

===>>> Starting build for ports that need updating <<<===

===>>> Launching child to install devel/pkgconf

===>>> All >> devel/pkgconf (1/16)

===>>> Currently installed version: pkgconf-1.6.3,1
===>>> Port directory: /usr/ports/devel/pkgconf

===>>> Starting check for build dependencies
===>>> Gathering dependency list for devel/pkgconf from ports
===>>> Dependency check complete for devel/pkgconf

===>>> All >> pkgconf-1.6.3,1 (1/16)

===>  Cleaning for pkgconf-1.7.3,1
:
省略
:
===>  Installing for pkgconf-1.7.3,1
===>  Checking if pkgconf is already installed
===>   Registering installation for pkgconf-1.7.3,1 as automatic
Installing pkgconf-1.7.3,1...

===>>> Upgrade of pkgconf-1.6.3,1 to pkgconf-1.7.3,1 succeeded

===>>> Delete pkgconf-1.6.3.tar.xz? y/n [n]

古いダウンロードファイルを消してもいいかの確認画面が出るのでyで消しておきます。
これを続けてアップデート完了です!

===>>> The following actions were performed:
        Upgrade of pkgconf-1.6.3,1 to pkgconf-1.7.3,1
        Upgrade of libiconv-1.14_11 to libiconv-1.16
        Upgrade of libxml2-2.9.9 to libxml2-2.9.10_1
        Upgrade of pcre-8.43_2 to pcre-8.44
        Upgrade of perl5-5.30.0 to perl5-5.30.3
        Upgrade of gettext-runtime-0.20.1 to gettext-runtime-0.21
        Upgrade of libtextstyle-0.20.1 to libtextstyle-0.21
        Upgrade of gettext-tools-0.20.1_1 to gettext-tools-0.21
        Upgrade of gmake-4.2.1_3 to gmake-4.3_2
        Upgrade of help2man-1.47.11 to help2man-1.47.16
        Upgrade of texinfo-6.6_4,1 to texinfo-6.7_4,1
        Upgrade of automake-1.16.1_2 to automake-1.16.2
        Upgrade of pcre2-10.33 to pcre2-10.35
        Upgrade of libidn2-2.2.0 to libidn2-2.3.0_1
        Upgrade of nginx-1.16.1_4,2 to nginx-1.18.0_25,2
        Upgrade of php74-7.4.0.r3 to php74-7.4.10

root@cafe:/usr/ports/ports-mgmt/portmaster #

その他のパッケージやPorts管理コマンド

root@cafe:~ # pkg info
autoconf-2.69_3                Automatically configure source code on many Un*x platforms
autoconf-wrapper-20131203      Wrapper script for GNU autoconf
automake-1.16.2                GNU Standards-compliant Makefile generator
dialog4ports-0.1.6             Console Interface to configure ports
gettext-runtime-0.21           GNU gettext runtime libraries and programs
gettext-tools-0.21             GNU gettext development and translation tools
gmake-4.3_2                    GNU version of 'make' utility
help2man-1.47.16               Automatically generating simple manual pages from program output
indexinfo-0.3.1                Utility to regenerate the GNU info page index
libargon2-20190702             Memory hard password hashing program and library
libiconv-1.16                  Character set conversion library
libidn2-2.3.0_1                Implementation of IDNA2008 internationalized domain names
libtextstyle-0.21              Text styling library
libtool-2.4.6_1                Generic shared library support script
libunistring-0.9.10_1          Unicode string library
libxml2-2.9.10_1               XML parser library for GNOME
m4-1.4.18_1,1                  GNU M4
nginx-1.18.0_25,2              Robust and small WWW server
p5-Locale-gettext-1.07         Message handling functions
p5-Locale-libintl-1.31         Internationalization library for Perl
p5-Text-Unidecode-1.30         Text::Unidecode -- US-ASCII transliterations of Unicode text
p5-Unicode-EastAsianWidth-12.0 East Asian Width properties
pcre-8.44                      Perl Compatible Regular Expressions library
pcre2-10.35                    Perl Compatible Regular Expressions library, version 2
perl5-5.30.3                   Practical Extraction and Report Language
php74-7.4.10                   PHP Scripting Language
pkg-1.15.6                     Package manager
pkgconf-1.7.3,1                Utility to help to configure compiler and linker flags
portmaster-3.19_25             Manage your ports without external databases or languages
texinfo-6.7_4,1                Typeset documentation system with multiple format output
wget-1.20.3                    Retrieve files from the Net via HTTP(S) and FTP
root@cafe:~ #

pkg infoインストールされているパッケージの一覧を表示します。

root@cafe:~ # pkg info wget
wget-1.20.3
Name           : wget
Version        : 1.20.3
Installed on   : Sun Sep 27 01:03:31 2020 JST
Origin         : ftp/wget
Architecture   : FreeBSD:12:amd64
Prefix         : /usr/local
Categories     : ipv6 ftp www
Licenses       : GPLv3+
Maintainer     : vd@FreeBSD.org
WWW            : http://www.gnu.org/s/wget/
Comment        : Retrieve files from the Net via HTTP(S) and FTP
Options        :
        DOCS           : on
        GNUTLS         : off
        IDN            : on
        IPV6           : on
        MANPAGES       : on
        METALINK       : off
        NLS            : on
        OPENSSL        : on
        PCRE           : off
        PSL            : off
Shared Libs required:
        libidn2.so.0
        libintl.so.8
        libunistring.so.2
        libpcre2-8.so.0
Annotations    :
        FreeBSD_version: 1201000
        cpe            : cpe:2.3:a:gnu:wget:1.20.3:::::freebsd12:x64
Flat size      : 3.08MiB
Description    :
GNU wget is a free software package for retrieving files using HTTP,
HTTPS and FTP, the most widely-used Internet protocols. It is a
non-interactive command-line tool, so it may easily be called from
scripts, cron jobs, terminals without X-Windows support, etc.

GNU wget has many features to make retrieving large files or mirroring
entire web or FTP sites easy, including:

 o Can resume aborted downloads, using REST and RANGE
 o Can use filename wild cards and recursively mirror directories
 o NLS-based message files for many different languages
 o Optionally converts absolute links in downloaded documents to
   relative, so that downloaded documents may link to each other locally
 o Supports HTTP and SOCKS proxies
 o Supports HTTP cookies
 o Supports persistent HTTP connections
 o Unattended / background operation
 o Uses local file timestamps to determine whether documents need to
   be re-downloaded when mirroring
 o GNU wget is distributed under the GNU General Public License.

WWW: http://www.gnu.org/s/wget/

root@cafe:~ #

pkg info パッケージ名インストールされているパッケージの詳細を表示します。

root@cafe:~ # pkg prime-list
dialog4ports
nginx
php74
pkg
portmaster
wget
root@cafe:~ #

pkg prime-list明示的にインストールしたパッケージ名を表示します。

root@cafe:~ # pkg autoremove
Updating database digests format: 100%
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 17 packages:

Installed packages to be REMOVED:
        autoconf: 2.69_3
        autoconf-wrapper: 20131203
        automake: 1.16.2
        gettext-tools: 0.21
        gmake: 4.3_2
        help2man: 1.47.16
        libiconv: 1.16
        libtextstyle: 0.21
        libtool: 2.4.6_1
        m4: 1.4.18_1,1
        p5-Locale-gettext: 1.07
        p5-Locale-libintl: 1.31
        p5-Text-Unidecode: 1.30
        p5-Unicode-EastAsianWidth: 12.0
        perl5: 5.30.3
        pkgconf: 1.7.3,1
        texinfo: 6.7_4,1

Number of packages to be removed: 17

The operation will free 98 MiB.

Proceed with deinstalling packages? [y/N]: n
root@cafe:~ #

pkg autoremove使われていない(依存していない)パッケージを削除します。ただし、コンパイル時に必要なパッケージも、ここに含まれるので、portsからインストールを行うときにまた必要になります。

root@cafe:~ # portmaster -L
===>>> Root ports (No dependencies, not depended on)
===>>> dialog4ports-0.1.6
===>>> pkg-1.15.6
===>>> pkgconf-1.7.3,1
===>>> portmaster-3.19_25
===>>> 4 root ports

===>>> Trunk ports (No dependencies, are depended on)
===>>> autoconf-wrapper-20131203
===>>> indexinfo-0.3.1
===>>> libargon2-20190702
===>>> libiconv-1.16
===>>> libxml2-2.9.10_1
===>>> pcre-8.44
===>>> pcre2-10.35
===>>> perl5-5.30.3
===>>> 8 trunk ports

===>>> Branch ports (Have dependencies, are depended on)
===>>> autoconf-2.69_3
===>>> gettext-runtime-0.21
===>>> libidn2-2.3.0_1
===>>> libtextstyle-0.21
===>>> libunistring-0.9.10_1
===>>> m4-1.4.18_1,1
===>>> p5-Locale-gettext-1.07
===>>> p5-Locale-libintl-1.31
===>>> p5-Text-Unidecode-1.30
===>>> p5-Unicode-EastAsianWidth-12.0
===>>> 10 branch ports

===>>> Leaf ports (Have dependencies, not depended on)
===>>> automake-1.16.2
===>>> gettext-tools-0.21
===>>> gmake-4.3_2
===>>> help2man-1.47.16
===>>> libtool-2.4.6_1
===>>> nginx-1.18.0_25,2
===>>> php74-7.4.10
===>>> texinfo-6.7_4,1
===>>> wget-1.20.3
===>>> 9 leaf ports

===>>> 31 total installed ports
        ===>>> There are no new versions available
root@cafe:~ #

portmaster -L依存関係を含めたパッケージの一覧を表示します。