これは、なにをしたくて書いたもの?
たまに、Ubuntu Linux/Debianを使っている時のソフトウェアのインストール前提条件としてこういう記述を見ることがあり
$ sudo apt install build-essential
「開発パッケージ一式」みたいなざっくりしたイメージでずっと捉えていたのですが、1度ちゃんと見てみようかなと
思いまして。
build-essentialとはなんなのか?という話です。
環境
今回の確認環境は、こちらです。
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.1 LTS Release: 20.04 Codename: focal $ uname -srvmpio Linux 5.4.0-54-generic #60-Ubuntu SMP Fri Nov 6 10:37:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
build-essentialとは?
パッケージのページはこちら。
Ubuntu – Details of package build-essential in focal
とはいえ、これを見てもよくわかりませんね。
試しに、インストールを試みてみます。
$ sudo apt install build-essential パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下の追加パッケージがインストールされます: binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev 提案パッケージ: binutils-doc cpp-doc gcc-9-locales debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-9-multilib glibc-doc bzr libstdc++-9-doc make-doc 以下のパッケージが新たにインストールされます: binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev アップグレード: 0 個、新規インストール: 41 個、削除: 0 個、保留: 0 個。 39.9 MB のアーカイブを取得する必要があります。 この操作後に追加で 175 MB のディスク容量が消費されます。
すごく大量のパッケージのインストールが示唆されます。
apt showで見てみましょう。
$ apt show build-essential Package: build-essential Version: 12.8ubuntu1.1 Priority: optional Build-Essential: yes Section: devel Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Matthias Klose <doko@debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 21.5 kB Depends: libc6-dev | libc-dev, gcc (>= 4:9.2), g++ (>= 4:9.2), make, dpkg-dev (>= 1.17.11) Task: ubuntu-mate-core, ubuntu-mate-desktop Download-Size: 4,664 B APT-Sources: http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages Description: build-essential なパッケージの一覧情報 Debian パッケージを構築するつもりがないのであれば、本パッケージは不要です。 1.14.18 以降の dpkg では、Debian パッケージの構築に本パッケージは必須です。 . 本パッケージには、Debian パッケージの構築に必須であるとされるパッケージ の一覧情報が含まれています。本パッケージはこの一覧にある各種パッケージに 依存もしているので、build-essential な各種パッケージを簡単にインストール できます。 . 本パッケージがインストールされていれば、特定のパッケージを構築する際に は、そのパッケージが構築にあたって依存しているという指定のあるパッケー ジをインストールするだけで構いません。逆に、作成しているパッケージの構 築に依存しているパッケージを判断する際に、本パッケージが依存する各種パッ ケージは常に除外して構いません。 . 本パッケージは、どのパッケージが build-essential であるかの定義は_行い ません_。実際の定義は Debian ポリシーマニュアルにあります。本パッケー ジは一覧情報を提供するだけですが、ほとんどの人にはこれで充分です。 本パッケージとマニュアルが一致しない場合に正しいのは、マニュアルになり ます。 N: 追加レコードが 1 件あります。表示するには '-a' スイッチを付けてください。
ストレートに言うと、こうですね。
本パッケージには、Debian パッケージの構築に必須であるとされるパッケージの一覧情報が含まれています。
本パッケージはこの一覧にある各種パッケージに 依存もしているので、build-essentialな各種パッケージを簡単にインストール できます。
つまり、Debianパッケージを作るために必要なパッケージ一式がインストールするためのものです、と。
Debian パッケージを構築するつもりがないのであれば、本パッケージは不要です。
build-essentialでインストールされるパッケージのひとつを見てみます。
$ apt show gcc Package: gcc Version: 4:9.3.0-1ubuntu2 Priority: optional Build-Essential: yes Section: devel Source: gcc-defaults (1.185.1ubuntu2) Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 51.2 kB Provides: c-compiler, gcc-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2) Depends: cpp (= 4:9.3.0-1ubuntu2), gcc-9 (>= 9.3.0-3~) Recommends: libc6-dev | libc-dev Suggests: gcc-multilib, make, manpages-dev, autoconf, automake, libtool, flex, bison, gdb, gcc-doc Conflicts: gcc-doc (<< 1:2.95.3) Task: ubuntustudio-video, ubuntu-mate-core, ubuntu-mate-desktop Download-Size: 5,208 B APT-Manual-Installed: no APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: GNU C コンパイラ これは GNU C コンパイラです。移植性に優れ、最適化を行う C 言語用コンパイラ です。 . 本パッケージは、デフォルトの GNU C コンパイラを提供する依存パッケージです。
よくよく見ると、こんな記述があります。build-essentialでインストールされる対象であることを示しているようです。
Build-Essential: yes
全然関係なさそうなパッケージを見ると、Build-Essential項目自体がそもそもありません。
$ apt show grep Package: grep Version: 3.4-1 Priority: required Essential: yes Section: utils Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Anibal Monsalve Salazar <anibal@debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 508 kB Provides: rgrep Pre-Depends: libc6 (>= 2.14), libpcre3 Depends: dpkg (>= 1.15.4) | install-info Suggests: libpcre3 (>= 7.7) Conflicts: rgrep Homepage: http://www.gnu.org/software/grep/ Task: minimal Download-Size: 151 kB APT-Manual-Installed: yes APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: GNU grep, egrep, fgrep 'grep' はファイル内の文字列を検索するユーティリティです。コマンドラインか ら、またスクリプトから使用できます。あなたが使用しないとしても、おそらくあ なたのシステムにある他のパッケージが使用するでしょう。 . grep ユーティリティの GNU ファミリは "西洋最速の grep" かもしれません。GNU grep は、高速な遅延状態決定性照合器 (元祖 Unix の egrep より約 2 倍速い) を 元に固定長文字列に対して Boyer-Moore-Gosper 検索を併用し、一致するはずのな い文字列を完全正規表現照合器で除いており、不必要なすべての文字の探索はしな いようになっています。このため、一般には Unix の grep や egrep より数倍高速 です (しかし後方参照を含む正規表現では他より遅くなるでしょう)。
中身を見てみる
build-essentialでインストールされるファイルのリストを見てみます。
Ubuntu – File list of package build-essential/focal/amd64
どうやら、対象となるパッケージのリストがありそうです。
とりあえず、build-essentialをインストールしてみましょう。
$ sudo apt install build-essential
インストールされました。
$ dpkg -l | grep build-essential ii build-essential 12.8ubuntu1.1 amd64 Informational list of build-essential packages
リストを確認してみます。
/usr/share/doc/build-essential/list
List of Build-Essential packages
as of 2017-09-17, Debian sid
This file lists the non-essential packages that are build-essential.
The list is not closed under the "depends on" relation, so one will
usually need to install more packages than given here.
This list attempts to document the set of build-essential packages as
well as possible. However, it is not authoritative (actually, there
is no authoritative list at all); the definition of the
"build-essential" class of packages given in Debian Policy Manual
(version >= 3.6.1.1), section 4 "Source packages" (more precisely
subsection 4.2 "Package relationships") is the definitive answer.
Here's the definition (as of Policy 3.6.1.1):
It is not necessary to explicitly specify build-time relationships
on a minimal set of packages that are always needed to compile,
link and put in a Debian package a standard "Hello World!" program
written in C or C++. The required packages are called
_build-essential_, and an informational list can be found in
`/usr/share/doc/build-essential/list' (which is contained in the
`build-essential' package).
The list is given below in a format which is readable by both humans and
programs. The format is described at the end of this file.
BEGIN LIST OF PACKAGES
libc6-dev [!alpha !ia64 !hurd-i386] | libc0.3-dev [hurd-i386] | libc6.1-dev [alpha ia64] | libc-dev
Provides the ISO C standard library
Indirectly depended on by g++, but we'll ignore
it since libc6-dev is used for non-C++ programs too.
libc6-dev-sparc64 [sparc]
Used only on the sparc architecture.
gcc (>= 4:9.2)
g++ (>= 4:9.2)
NOTE:
The libstdc++ -dev library is not needed, as g++ depends on it
make
Also depended on by dpkg-dev, but make does warrant its own
dependency since debian/rules will need it even if dpkg-dev
stopped depending on it
dpkg-dev (>= 1.17.11)
Provides dpkg-genchanges and other scripts. Versioned, because
of support for the build-time dependency fields in /debian/control
and dpkg-architecture support for OS and CPU information.
NOTE:
Although this list does not contain them, all `Essential: yes'
packages are build-essential as well. A list of such packages
can be found by executing the following command
`grep-status -FEssential -sPackage -ni yes'
when the `grep-dctrl' package is installed and in its default
configuration. Such list is installed with this package as
the file
`/usr/share/doc/build-essential/essential-packages-list'
hurd-dev [hurd-i386]
Provides libpthread.so (and other such essential components).
END LIST OF PACKAGES
Here's the format definition:
- First line is the following, without any leading or trailing
whitespace:
BEGIN LIST OF PACKAGES
- Last line is the following, without any leading or trailing
whitespace:
END LIST OF PACKAGES
- A line with leading whitespace is a comment.
- Other lines are joined with end-of-line replaced by comma, and
the result is parsed like the body of the Build-Depends field.
The list of build-essential packages for a particular
architecture is constructed from the result list by ignoring all
the package name - package version pairs which would be ignored
if we were building for that architecture and then removing the
architecture specifications.
The Python program list2depends parses stdin as if it were this
file and outputs one line that is suitable for use in a dependency
field body of a Debian binary package.
Local Variables:
mode: text
End:
パッケージの部分を抜粋すると、こんな感じですね。
※hurd-devはlibpthread.soによる提供
libc6-dev [!alpha !ia64 !hurd-i386] | libc0.3-dev [hurd-i386] | libc6.1-dev [alpha ia64] | libc-dev libc6-dev-sparc64 [sparc] gcc (>= 4:9.2) g++ (>= 4:9.2) make dpkg-dev (>= 1.17.11) hurd-dev [hurd-i386]
apt show build-essentialで表示されるDependsの内容とも、ほぼ一致します。
Depends: libc6-dev | libc-dev, gcc (>= 4:9.2), g++ (>= 4:9.2), make, dpkg-dev (>= 1.17.11)
構成される個別パッケージの依存関係を見る
ところで、build-essentialをインストールしようとすると、対象としてえらく大量のパッケージが表示されていたと思います。
なにがそんなに多いんでしょうね。apt showで各パッケージのDependsを確認してみましょう。
libc6-dev。また、libc-devはこちらの仮想パッケージですね。
## Depends: libc6 (= 2.31-0ubuntu9.1), libc-dev-bin (= 2.31-0ubuntu9.1), linux-libc-dev, libcrypt-dev $ apt show libc6-dev Package: libc6-dev Version: 2.31-0ubuntu9.1 Priority: optional Build-Essential: yes Section: libdevel Source: glibc Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 19.5 MB Provides: libc-dev Depends: libc6 (= 2.31-0ubuntu9.1), libc-dev-bin (= 2.31-0ubuntu9.1), linux-libc-dev, libcrypt-dev Suggests: glibc-doc, manpages-dev Conflicts: libc0.1-dev, libc0.3-dev, libc6.1-dev Breaks: binutils (<< 2.26), binutils-gold (<< 2.20.1-11), cmake (<< 2.8.4+dfsg.1-5), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2), gcc-4.6 (<< 4.6.0-12), libhwloc-dev (<< 1.2-3), libjna-java (<< 3.2.7-4), liblouis-dev (<< 2.3.0-2), liblouisxml-dev (<< 2.4.0-2), libperl5.26 (<< 5.26.1-3), make (<< 3.81-8.1), pkg-config (<< 0.26-1) Homepage: https://www.gnu.org/software/libc/libc.html Task: ubuntustudio-video, ubuntu-mate-core, ubuntu-mate-desktop Original-Vcs-Browser: https://salsa.debian.org/glibc-team/glibc Original-Vcs-Git: https://salsa.debian.org/glibc-team/glibc.git Download-Size: 2,519 kB APT-Manual-Installed: no APT-Sources: http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages Description: GNU C ライブラリ: 開発用ライブラリとヘッダファイル 標準的な C ライブラリを用いるプログラムのコンパイルやリンクに必要とされる シンボリックリンク、ヘッダおよびオブジェクトファイルが含まれます。 N: 追加レコードが 1 件あります。表示するには '-a' スイッチを付けてください。
gcc。
## Depends: cpp (= 4:9.3.0-1ubuntu2), gcc-9 (>= 9.3.0-3~) $ apt show gcc Package: gcc Version: 4:9.3.0-1ubuntu2 Priority: optional Build-Essential: yes Section: devel Source: gcc-defaults (1.185.1ubuntu2) Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 51.2 kB Provides: c-compiler, gcc-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2) Depends: cpp (= 4:9.3.0-1ubuntu2), gcc-9 (>= 9.3.0-3~) Recommends: libc6-dev | libc-dev Suggests: gcc-multilib, make, manpages-dev, autoconf, automake, libtool, flex, bison, gdb, gcc-doc Conflicts: gcc-doc (<< 1:2.95.3) Task: ubuntustudio-video, ubuntu-mate-core, ubuntu-mate-desktop Download-Size: 5,208 B APT-Manual-Installed: no APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: GNU C コンパイラ これは GNU C コンパイラです。移植性に優れ、最適化を行う C 言語用コンパイラ です。 . 本パッケージは、デフォルトの GNU C コンパイラを提供する依存パッケージです。
g++。
## Depends: cpp (= 4:9.3.0-1ubuntu2), gcc (= 4:9.3.0-1ubuntu2), g++-9 (>= 9.3.0-3~), gcc-9 (>= 9.3.0-3~) $ apt show g++ Package: g++ Version: 4:9.3.0-1ubuntu2 Priority: optional Build-Essential: yes Section: devel Source: gcc-defaults (1.185.1ubuntu2) Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 16.4 kB Provides: c++-compiler, g++-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2) Depends: cpp (= 4:9.3.0-1ubuntu2), gcc (= 4:9.3.0-1ubuntu2), g++-9 (>= 9.3.0-3~), gcc-9 (>= 9.3.0-3~) Suggests: g++-multilib Task: ubuntu-mate-core, ubuntu-mate-desktop Download-Size: 1,604 B APT-Manual-Installed: no APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: GNU C++ コンパイラ これは GNU C++ コンパイラです。移植性に優れ、最適化を行う C++ 用コンパイラ です。 . 本パッケージは、デフォルトの GNU C++ コンパイラを提供する依存パッケージ です。
make。
## Depends: libc6 (>= 2.27) $ apt show make Package: make Version: 4.2.1-1.2 Priority: optional Build-Essential: yes Section: devel Source: make-dfsg Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Manoj Srivastava <srivasta@debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 393 kB Depends: libc6 (>= 2.27) Suggests: make-doc Conflicts: make-guile Replaces: make-guile Homepage: https://www.gnu.org/software/make/ Task: ubuntu-mate-core, ubuntu-mate-desktop Download-Size: 162 kB APT-Manual-Installed: no APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: コンパイルを制御するユーティリティ GNU Make は、プログラムのソースファイルからプログラムの実行ファイルやその他の 対象ファイルを生成する作業を制御するユーティリティです。大きなプログラムの どの部分を (再) 生成すべきかを自動判定し、その (再) 生成に必要なコマンドを 発行します。Make は入力ファイルに基づいて、対応する入力の更新に応じて対象 (ファイル) を更新する必要があるどんなタスクに対しても利用できます --- コンピュータプログラムのビルドに限りません。まさに、Make は汎用目的の 依存関係解決ユーティリティなのです。
dpkg-dev。
## Depends: perl:any, libdpkg-perl (= 1.19.7ubuntu3), tar (>= 1.28-1), bzip2, xz-utils, patch (>= 2.7), make, binutils $ apt show dpkg-dev Package: dpkg-dev Version: 1.19.7ubuntu3 Priority: optional Build-Essential: yes Section: utils Source: dpkg Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 2,124 kB Depends: perl:any, libdpkg-perl (= 1.19.7ubuntu3), tar (>= 1.28-1), bzip2, xz-utils, patch (>= 2.7), make, binutils Recommends: build-essential, gcc | c-compiler, fakeroot, gnupg | gnupg2, gpgv | gpgv2, libalgorithm-merge-perl Suggests: debian-keyring Breaks: debhelper (<< 10.10.1~) Homepage: https://wiki.debian.org/Teams/Dpkg Task: ubuntu-mate-core, ubuntu-mate-desktop Download-Size: 679 kB APT-Manual-Installed: no APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: Debian パッケージ開発ツール 本パッケージは、Debian ソースパッケージの展開、構築、そしてアップロードに 要求される開発ツール (dpkg-source を含む) を提供します。 . Debian ソースパッケージのほとんどは、構築するにはさらに別のツールを必要と します。例えば、ほとんどのパッケージは、make や、C コンパイラ gcc を必要と します。
dpkg-devは、だいぶいろいろ入りますね。Recommendsでも多く引っ張ってきます。
Dockerfileなどでapt-get installを書く時は、こういうのは個々のパッケージを書いた方が良さそうですね。