【Windows】【10】【WSL】開発ツールのインストール【SW】

WSL (Windows Subsystem for Linux) に gcc, g++, make 等々の開発ツールをインストールする。
なお、WSL を使うための設定手順はこちらを参照。

gcc, g++, make, autoconf, などなどソフトは多数のため、build-essential を指定してインストールすること。
(gcc 単独で入れようとして依存パッケージが多すぎてエラーになるはず)
 

 

結論

以下の順にコマンドを実行すれば良い。

% sudo apt-get -y update
% sudo apt-get -y install build-essential

 

手順詳細

1. PowerShell から bash を起動させて以下を実行する。

以下ようにエラーになるが、エラーメッセージに従い「apt-get update」を実行する。

% sudo apt install build-essential

[sudo] password for neko:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-7 dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base
  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1 libbinutils libc-dev-bin
  libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0
  libmpc3 libmpx2 libquadmath0 libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev manpages-dev
Suggested packages:
  binutils-doc cpp-doc gcc-7-locales debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib libtool
  flex bison gdb gcc-doc gcc-7-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg
  libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg glibc-doc bzr libstdc++-7-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base
  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1 libbinutils libc-dev-bin
  libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0
  libmpc3 libmpx2 libquadmath0 libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev manpages-dev
0 upgraded, 39 newly installed, 0 to remove and 0 not upgraded.
Need to get 2002 kB/36.9 MB of archives.
After this operation, 160 MB of additional disk space will be used.
Ign:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-libc-dev amd64 4.15.0-29.31
Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libdpkg-perl all 1.19.0.5ubuntu2 [211 kB]
Err:1 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 linux-libc-dev amd64 4.15.0-29.31
  404  Not Found [IP: 123.123.12.123 80]
Get:3 http://archive.ubuntu.com/ubuntu bionic/main amd64 dpkg-dev all 1.19.0.5ubuntu2 [607 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic/main amd64 build-essential amd64 12.4ubuntu1 [4758 B]
Get:5 http://archive.ubuntu.com/ubuntu bionic/main amd64 libfakeroot amd64 1.22-2ubuntu1 [25.9 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic/main amd64 fakeroot amd64 1.22-2ubuntu1 [62.3 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic/main amd64 libalgorithm-diff-perl all 1.19.03-1 [47.6 kB]
Get:8 http://archive.ubuntu.com/ubuntu bionic/main amd64 libalgorithm-diff-xs-perl amd64 0.04-5 [11.1 kB]
Get:9 http://archive.ubuntu.com/ubuntu bionic/main amd64 libalgorithm-merge-perl all 0.08-3 [12.0 kB]
Get:10 http://archive.ubuntu.com/ubuntu bionic/main amd64 libfile-fcntllock-perl amd64 0.22-3build2 [33.2 kB]
Fetched 1016 kB in 8s (125 kB/s)
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.15.0-29.31_amd64.deb  404  Not Found [IP: 123.123.12.123 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

 

2. apt-get update を行いパッケージリストを更新する

% sudo apt-get -y update 

sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [167 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [8570 kB]
Get:7 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [62.9 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [66.6 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [39.2 kB]
Get:10 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [1444 B]
Get:11 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [996 B]
Get:12 http://archive.ubuntu.com/ubuntu bionic/universe Translation-en [4941 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [151 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic/multiverse Translation-en [108 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [322 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [122 kB]
Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [192 kB]
Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [90.1 kB]
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [4180 B]
Get:20 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [2740 B]
Get:21 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [2704 B]
Get:22 http://archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1136 B]
Fetched 15.1 MB in 1min 20s (188 kB/s)
Reading package lists... Done

  

3. 再度「sudo apt install build-essential」を実行する

% sudo apt install build-essential

Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Selecting previously unselected package manpages-dev.
Preparing to unpack .../38-manpages-dev_4.15-1_all.deb ...
Unpacking manpages-dev (4.15-1) ...
Setting up libquadmath0:amd64 (8-20180414-1ubuntu2) ...
Setting up libgomp1:amd64 (8-20180414-1ubuntu2) ...
Setting up libatomic1:amd64 (8-20180414-1ubuntu2) ...
Setting up libcc1-0:amd64 (8-20180414-1ubuntu2) ...
Setting up libtsan0:amd64 (8-20180414-1ubuntu2) ...
Setting up linux-libc-dev:amd64 (4.15.0-34.37) ...
Setting up libdpkg-perl (1.19.0.5ubuntu2) ...
Setting up liblsan0:amd64 (8-20180414-1ubuntu2) ...
Setting up gcc-7-base:amd64 (7.3.0-16ubuntu3) ...
Setting up binutils-common:amd64 (2.30-20ubuntu2~18.04) ...
Setting up libfile-fcntllock-perl (0.22-3build2) ...
Setting up libmpx2:amd64 (8-20180414-1ubuntu2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up libfakeroot:amd64 (1.22-2ubuntu1) ...
Setting up libalgorithm-diff-perl (1.19.03-1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up libmpc3:amd64 (1.1.0-1) ...
Setting up libc-dev-bin (2.27-3ubuntu1) ...
Setting up manpages-dev (4.15-1) ...
Setting up libc6-dev:amd64 (2.27-3ubuntu1) ...
Setting up libitm1:amd64 (8-20180414-1ubuntu2) ...
Setting up libisl19:amd64 (0.19-1) ...
Setting up libasan4:amd64 (7.3.0-16ubuntu3) ...
Setting up libbinutils:amd64 (2.30-20ubuntu2~18.04) ...
Setting up libcilkrts5:amd64 (7.3.0-16ubuntu3) ...
Setting up libubsan0:amd64 (7.3.0-16ubuntu3) ...
Setting up fakeroot (1.22-2ubuntu1) ...
update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode
Setting up libgcc-7-dev:amd64 (7.3.0-16ubuntu3) ...
Setting up cpp-7 (7.3.0-16ubuntu3) ...
Setting up libstdc++-7-dev:amd64 (7.3.0-16ubuntu3) ...
Setting up libalgorithm-merge-perl (0.08-3) ...
Setting up libalgorithm-diff-xs-perl (0.04-5) ...
Setting up binutils-x86-64-linux-gnu (2.30-20ubuntu2~18.04) ...
Setting up cpp (4:7.3.0-3ubuntu2) ...
Setting up binutils (2.30-20ubuntu2~18.04) ...
Setting up gcc-7 (7.3.0-16ubuntu3) ...
Setting up g++-7 (7.3.0-16ubuntu3) ...
Setting up gcc (4:7.3.0-3ubuntu2) ...
Setting up dpkg-dev (1.19.0.5ubuntu2) ...
Setting up g++ (4:7.3.0-3ubuntu2) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up build-essential (12.4ubuntu1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...