lisz-works

技術と興味の集合体

Windows Subsystem for Linux(WSL)でGCCをインストールしてみた!

【スポンサーリンク】

Windows Subsystem for Linux

Windows Subsystem for Linux(WSL)で、「GCCでC言語コンパイルしよ!」……と思って実行したら

The program 'gcc' is currently not installed.

Windows Subsystem for Linuxには、デフォルトでGCCが入っていない!?

ということで、インストールをしてみました。

インストールでまずコケる

gccを実行したとき、このように表示されました。

user:~$ gcc
The program 'gcc' is currently not installed. You can install it by typing:
sudo apt install gcc

親切にも「これでインストールしなさい!」といってきてくれた。なんていい人!

ということで言われたコマンド「sudo apt install gcc」を実行。

コンソールの表示

user:~$ sudo apt install gcc
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 cpp cpp-5 gcc-5 libasan2 libatomic1 libc-dev-bin libc6-dev
libcc1-0 libcilkrts5
  libgcc-5-dev libgomp1 libisl15 libitm1 liblsan0 libmpc3 libmpx0
libquadmath0 libtsan0 libubsan0
  linux-libc-dev manpages-dev
Suggested packages:
  binutils-doc cpp-doc gcc-5-locales gcc-multilib make autoconf automake
libtool flex bison gdb
  gcc-doc gcc-5-multilib gcc-5-doc libgcc1-dbg libgomp1-dbg libitm1-dbg
libatomic1-dbg
  libasan2-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg
libmpx0-dbg
  libquadmath0-dbg glibc-doc
The following NEW packages will be installed:
  binutils cpp cpp-5 gcc gcc-5 libasan2 libatomic1 libc-dev-bin libc6-dev
libcc1-0 libcilkrts5
  libgcc-5-dev libgomp1 libisl15 libitm1 liblsan0 libmpc3 libmpx0
libquadmath0 libtsan0 libubsan0
  linux-libc-dev manpages-dev
0 upgraded, 23 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.8 MB/27.4 MB of archives.
After this operation, 99.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 binutils
amd64 2.26.1-1ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Err:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 cpp-5
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libcc1-0
amd64 5.4.0-6ubuntu1~16.04.4
Ign:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libgomp1
amd64 5.4.0-6ubuntu1~16.04.4
Err:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 cpp-5
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libitm1
amd64 5.4.0-6ubuntu1~16.04.4
Err:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libcc1-0
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libatomic1 amd64 5.4.0-6ubuntu1~16.04.4
Err:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libgomp1
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libasan2
amd64 5.4.0-6ubuntu1~16.04.4
Err:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libitm1
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:8 http://security.ubuntu.com/ubuntu xenial-security/main amd64 liblsan0
amd64 5.4.0-6ubuntu1~16.04.4
Err:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libatomic1 amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:9 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libtsan0
amd64 5.4.0-6ubuntu1~16.04.4
Err:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libasan2
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Err:8 http://security.ubuntu.com/ubuntu xenial-security/main amd64 liblsan0
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Err:9 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libtsan0
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Err:10 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libubsan0 amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:11 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libcilkrts5 amd64 5.4.0-6ubuntu1~16.04.4
Err:10 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libubsan0 amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:12 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libmpx0
amd64 5.4.0-6ubuntu1~16.04.4
Err:11 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libcilkrts5 amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:13 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libquadmath0 amd64 5.4.0-6ubuntu1~16.04.4
Err:12 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libmpx0
amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:14 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libgcc-5-dev amd64 5.4.0-6ubuntu1~16.04.4
Err:13 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libquadmath0 amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:15 http://security.ubuntu.com/ubuntu xenial-security/main amd64 gcc-5
amd64 5.4.0-6ubuntu1~16.04.4
Err:14 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libgcc-5-dev amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:16 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libc-dev-bin amd64 2.23-0ubuntu9Err:15 http://security.ubuntu.com/ubuntu
xenial-security/main amd64 gcc-5 amd64 5.4.0-6ubuntu1~16.04.4
  404  Not Found [IP: 91.189.88.149 80]
Ign:17 http://security.ubuntu.com/ubuntu xenial-security/main amd64
linux-libc-dev amd64 4.4.0-96.119
Err:16 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libc-dev-bin amd64 2.23-0ubuntu9  404  Not Found [IP: 91.189.88.149 80]
Ign:18 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libc6-dev amd64 2.23-0ubuntu9
Err:17 http://security.ubuntu.com/ubuntu xenial-security/main amd64
linux-libc-dev amd64 4.4.0-96.119
  404  Not Found [IP: 91.189.88.149 80]
Err:18 http://security.ubuntu.com/ubuntu xenial-security/main amd64
libc6-dev amd64 2.23-0ubuntu9
  404  Not Found [IP: 91.189.88.149 80]
E: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/b/binutils/binutils_2.26.1-1ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/cpp-5_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libcc1-0_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libgomp1_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libitm1_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libatomic1_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libasan2_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/liblsan0_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libtsan0_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libubsan0_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libcilkrts5_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libmpx0_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libquadmath0_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libgcc-5-dev_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.0-6ubuntu1~16.04.4_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc-dev-bin_2.23-0ubuntu9_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.4.0-96.119_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Failed to fetch
http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6-dev_2.23-0ubuntu9_amd64.deb
404  Not Found [IP: 91.189.88.149 80]

E: Unable to fetch some archives, maybe run apt-get update or try with
--fix-missing?

くそほどエラーしてる……

apt-getのアップデート

ということでググった。

するとコチラに行き着いた。

https://qiita.com/aegis_m/items/1bf07d4e84f5d6af3c8c#%E5%88%9D%E6%9C%9F%E8%A8%AD%E5%AE%9A

曰く、なにやらインストール時に使っているコマンド「apt」のアップデートが必要そう。
というかよく見たら「maybe run apt-get update」って言ってる……

ともあれ、言われている通り、「apt-get update」を行います。

管理者権限が必要な為、「sudo」と先頭につけて実行しています。
管理者権限のないユーザ(一般ユーザ)の場合、パスワードの入力が必要になります。

user:~$ sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
[7,532 kB]
Get:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
[491 kB]
Get:7 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en
[212 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64
Packages [7,224 B]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/restricted
Translation-en [2,152 B]
Get:10 http://security.ubuntu.com/ubuntu xenial-security/universe amd64
Packages [347 kB]
Get:11 http://security.ubuntu.com/ubuntu xenial-security/universe
Translation-en [130 kB]
Get:12 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64
Packages [3,464 B]
Get:13 http://security.ubuntu.com/ubuntu xenial-security/multiverse
Translation-en [1,744 B]
Get:14 http://archive.ubuntu.com/ubuntu xenial/universe Translation-en
[4,354 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages
[144 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial/multiverse Translation-en
[106 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
[775 kB]
Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/main Translation-en
[321 kB]
Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64
Packages [7,560 B]
Get:20 http://archive.ubuntu.com/ubuntu xenial-updates/restricted
Translation-en [2,272 B]
Get:21 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64
Packages [627 kB]
Get:22 http://archive.ubuntu.com/ubuntu xenial-updates/universe
Translation-en [252 kB]
Get:23 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64
Packages [16.4 kB]
Get:24 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse
Translation-en [8,344 B]
Get:25 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64
Packages [4,844 B]
Get:26 http://archive.ubuntu.com/ubuntu xenial-backports/main
Translation-en [3,220 B]
Get:27 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64
Packages [7,400 B]
Get:28 http://archive.ubuntu.com/ubuntu xenial-backports/universe
Translation-en [3,996 B]
Fetched 15.7 MB in 1min 16s (204 kB/s)
Reading package lists... Done

GCCのインストール

apt-get updateも行ったので……

改めてインストールを実行!

user:~$ sudo apt install gcc

コンソールの表示

user:~$ sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
[7,532 kB]
Get:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
[491 kB]
Get:7 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en
[212 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64
Packages [7,224 B]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/restricted
Translation-en [2,152 B]
Get:10 http://security.ubuntu.com/ubuntu xenial-security/universe amd64
Packages [347 kB]
Get:11 http://security.ubuntu.com/ubuntu xenial-security/universe
Translation-en [130 kB]
Get:12 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64
Packages [3,464 B]
Get:13 http://security.ubuntu.com/ubuntu xenial-security/multiverse
Translation-en [1,744 B]
Unpacking libatomic1:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package libasan2:amd64.
Preparing to unpack .../libasan2_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking libasan2:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package liblsan0:amd64.
Preparing to unpack .../liblsan0_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking liblsan0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package libtsan0:amd64.
Preparing to unpack .../libtsan0_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking libtsan0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package libubsan0:amd64.
Preparing to unpack .../libubsan0_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking libubsan0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package libcilkrts5:amd64.
Preparing to unpack .../libcilkrts5_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking libcilkrts5:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package libmpx0:amd64.
Preparing to unpack .../libmpx0_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking libmpx0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package libquadmath0:amd64.
Preparing to unpack .../libquadmath0_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking libquadmath0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package libgcc-5-dev:amd64.
Preparing to unpack .../libgcc-5-dev_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking libgcc-5-dev:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package gcc-5.
Preparing to unpack .../gcc-5_5.4.0-6ubuntu1~16.04.9_amd64.deb ...
Unpacking gcc-5 (5.4.0-6ubuntu1~16.04.9) ...
Selecting previously unselected package gcc.
Preparing to unpack .../gcc_4%3a5.3.1-1ubuntu1_amd64.deb ...
Unpacking gcc (4:5.3.1-1ubuntu1) ...
Selecting previously unselected package libc-dev-bin.
Preparing to unpack .../libc-dev-bin_2.23-0ubuntu10_amd64.deb ...
Unpacking libc-dev-bin (2.23-0ubuntu10) ...
Selecting previously unselected package linux-libc-dev:amd64.
Preparing to unpack .../linux-libc-dev_4.4.0-124.148_amd64.deb ...
Unpacking linux-libc-dev:amd64 (4.4.0-124.148) ...
Selecting previously unselected package libc6-dev:amd64.
Preparing to unpack .../libc6-dev_2.23-0ubuntu10_amd64.deb ...
Unpacking libc6-dev:amd64 (2.23-0ubuntu10) ...
Selecting previously unselected package manpages-dev.
Preparing to unpack .../manpages-dev_4.04-2_all.deb ...
Unpacking manpages-dev (4.04-2) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libmpc3:amd64 (1.0.3-1) ...
Setting up binutils (2.26.1-1ubuntu1~16.04.6) ...
Setting up libisl15:amd64 (0.16.1-1) ...
Setting up cpp-5 (5.4.0-6ubuntu1~16.04.9) ...
Setting up cpp (4:5.3.1-1ubuntu1) ...
Setting up libcc1-0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libgomp1:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libitm1:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libatomic1:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libasan2:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up liblsan0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libtsan0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libubsan0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libcilkrts5:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libmpx0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libquadmath0:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up libgcc-5-dev:amd64 (5.4.0-6ubuntu1~16.04.9) ...
Setting up gcc-5 (5.4.0-6ubuntu1~16.04.9) ...
Setting up gcc (4:5.3.1-1ubuntu1) ...
Setting up libc-dev-bin (2.23-0ubuntu10) ...
Setting up linux-libc-dev:amd64 (4.4.0-124.148) ...
Setting up libc6-dev:amd64 (2.23-0ubuntu10) ...
Setting up manpages-dev (4.04-2) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...

GCCのインストール確認

GCCの動作確認を……!

user:~$ gcc
gcc: fatal error: no input files
compilation terminated.

GCCさんが怒ってくれた!!インストール成功です!!

怒られて喜ぶという不思議な状況ですね(笑)

あとがき

Windows Subsystem for LinuxにGCCを入れて実行したい!

という方は、まずはGCCさんに怒られに行きましょう!(謎)

www.lisz-works.com