はじめまして。メディア開発本部エンジニアの久保です。

2016年8月に公開された、Windows 10 Anniversary Update では Bash on Ubuntu on Windows の提供が始まりました。
Windows でもネイティブな Bash 環境が整ったわけですが、まだまだ Windows 7 や 8.1 を使われている方もいるかと思います(私もその一人です!)。

そんな Windows 8.1 以前の環境でも GNU コマンドが使用したい!と思い、Windows に Unix ライクな環境を構築してみました。

MSYS2 とは

MSYS2(Minimal SYStem2) は Windows 上で Unix ライクなシェル環境を提供するもので、

  • ターミナルに mintty
  • シェルに Bash
  • パッケージマネージャに pacman

で構成されています。
Windows で Git を使っている方は、Git Bash でおなじみかと思います。

今回は MSYS2 をインストールして、Windows で GNU ツールを使えるようにしたいと思います。

MSYS2 のインストールと設定

検証環境

Windows 7 Professional SP1 64-bit

MSYS2 のインストール

MSYS2 installer より、インストーラをダウンロードします。
今回は 64-bit の Windows なので、msys2-x86_64-*.exe をダウンロードし、実行します。

インストールは特別な指定なく進められるかと思います。
インストール先は、標準の C:\msys64 としました。

MSYS2 の設定

インストールが完了したら、スタートメニューから MinGW-w64 Win64 Shell を起動します。

公式ドキュメントに沿って進めていきます。
まずは、アップデートをしましょう。パッケージマネージャの pacman のバージョンを確認します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ pacman --version
.--. Pacman v4.2.1-463-g28da-dirty - libalpm v10.0.0
/ _.-' .-. .-. .-. Copyright (C) 2006-2016 Pacman Development Team
\ '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet
'--'
This program may be freely redistributed under
the terms of the GNU General Public License.
$ pacman --version .--. Pacman v4.2.1-463-g28da-dirty - libalpm v10.0.0 / _.-' .-. .-. .-. Copyright (C) 2006-2016 Pacman Development Team \ '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet '--' This program may be freely redistributed under the terms of the GNU General Public License.
$ pacman --version

 .--.                  Pacman v4.2.1-463-g28da-dirty - libalpm v10.0.0
/ _.-' .-.  .-.  .-.   Copyright (C) 2006-2016 Pacman Development Team
\  '-. '-'  '-'  '-'   Copyright (C) 2002-2006 Judd Vinet
 '--'
                       This program may be freely redistributed under
                       the terms of the GNU General Public License.

バージョンは 4.2.1 でした。
pacman のバージョンによって、アップデートコマンドが異なるので注意が必要です。

次に、core の update をします。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ update-core
==> Update package databases...
:: パッケージデータベースの同期中...
mingw32 296.0 KiB 517K/s 00:01 [#####################] 100%
mingw32.sig 96.0 B 0.00B/s 00:00 [#####################] 100%
mingw64 295.7 KiB 2039K/s 00:00 [#####################] 100%
mingw64.sig 96.0 B 0.00B/s 00:00 [#####################] 100%
msys 135.8 KiB 924K/s 00:00 [#####################] 100%
msys.sig 96.0 B 0.00B/s 00:00 [#####################] 100%
==> Checking if there are critical packages to upgrade.
bash 4.3.042-4 -> 4.3.046-1
pacman 5.0.0.6348.cc5a8f1-1 -> 5.0.1-1
msys2-runtime 2.4.1.16860.40c26fc-1 -> 2.6.0-1
==> Core packages require updating.
==> Please close all other MSYS2 derived windows (e.g. terminal
==> windows, Bash sessions, etc) before proceeding.
==> 警告: When the update has completed, you MUST close this MSYS2 window
==> 警告: (use Alt-F4 or red [ X ], etc.), rather than 'exit'!!!
Press [Enter] key when ready to start update...
==> Updating core packages...
依存関係を解決しています...
衝突するパッケージがないか確認しています...
パッケージ (4) bash-4.3.046-1 msys2-runtime-2.6.0-1
msys2-runtime-devel-2.6.0-1 pacman-5.0.1-1
合計ダウンロード容量: 14.42 MiB
合計インストール容量: 72.88 MiB
最終的なアップグレード容量: 21.44 MiB
:: インストールを行いますか? [Y/n]
:: パッケージを取得します ...
msys2-runtime-2.6.0... 2.2 MiB 1273K/s 00:02 [#####################] 100%
bash-4.3.046-1-x86_64 1876.6 KiB 1414K/s 00:01 [#####################] 100%
pacman-5.0.1-1-x86_64 6.8 MiB 1354K/s 00:05 [#####################] 100%
msys2-runtime-devel... 3.6 MiB 1458K/s 00:03 [#####################] 100%
(4/4) キーリングのキーを確認 [#####################] 100%
(4/4) パッケージの整合性をチェック [#####################] 100%
(4/4) パッケージファイルのロード [#####################] 100%
(4/4) ファイルの衝突をチェック [#####################] 100%
(4/4) 空き容量を確認 [#####################] 100%
:: パッケージの変更を処理しています...
(1/4) 更新 msys2-runtime [#####################] 100%
(2/4) 更新 bash [#####################] 100%
(3/4) 更新 pacman [#####################] 100%
(4/4) インストール msys2-runtime-devel [#####################] 100%
Please close this window.
$ update-core ==> Update package databases... :: パッケージデータベースの同期中... mingw32 296.0 KiB 517K/s 00:01 [#####################] 100% mingw32.sig 96.0 B 0.00B/s 00:00 [#####################] 100% mingw64 295.7 KiB 2039K/s 00:00 [#####################] 100% mingw64.sig 96.0 B 0.00B/s 00:00 [#####################] 100% msys 135.8 KiB 924K/s 00:00 [#####################] 100% msys.sig 96.0 B 0.00B/s 00:00 [#####################] 100% ==> Checking if there are critical packages to upgrade. bash 4.3.042-4 -> 4.3.046-1 pacman 5.0.0.6348.cc5a8f1-1 -> 5.0.1-1 msys2-runtime 2.4.1.16860.40c26fc-1 -> 2.6.0-1 ==> Core packages require updating. ==> Please close all other MSYS2 derived windows (e.g. terminal ==> windows, Bash sessions, etc) before proceeding. ==> 警告: When the update has completed, you MUST close this MSYS2 window ==> 警告: (use Alt-F4 or red [ X ], etc.), rather than 'exit'!!! Press [Enter] key when ready to start update... ==> Updating core packages... 依存関係を解決しています... 衝突するパッケージがないか確認しています... パッケージ (4) bash-4.3.046-1 msys2-runtime-2.6.0-1 msys2-runtime-devel-2.6.0-1 pacman-5.0.1-1 合計ダウンロード容量: 14.42 MiB 合計インストール容量: 72.88 MiB 最終的なアップグレード容量: 21.44 MiB :: インストールを行いますか? [Y/n] :: パッケージを取得します ... msys2-runtime-2.6.0... 2.2 MiB 1273K/s 00:02 [#####################] 100% bash-4.3.046-1-x86_64 1876.6 KiB 1414K/s 00:01 [#####################] 100% pacman-5.0.1-1-x86_64 6.8 MiB 1354K/s 00:05 [#####################] 100% msys2-runtime-devel... 3.6 MiB 1458K/s 00:03 [#####################] 100% (4/4) キーリングのキーを確認 [#####################] 100% (4/4) パッケージの整合性をチェック [#####################] 100% (4/4) パッケージファイルのロード [#####################] 100% (4/4) ファイルの衝突をチェック [#####################] 100% (4/4) 空き容量を確認 [#####################] 100% :: パッケージの変更を処理しています... (1/4) 更新 msys2-runtime [#####################] 100% (2/4) 更新 bash [#####################] 100% (3/4) 更新 pacman [#####################] 100% (4/4) インストール msys2-runtime-devel [#####################] 100% Please close this window.
$ update-core
==> Update package databases...
:: パッケージデータベースの同期中...
 mingw32                  296.0 KiB   517K/s 00:01 [#####################] 100%
 mingw32.sig               96.0   B  0.00B/s 00:00 [#####################] 100%
 mingw64                  295.7 KiB  2039K/s 00:00 [#####################] 100%
 mingw64.sig               96.0   B  0.00B/s 00:00 [#####################] 100%
 msys                     135.8 KiB   924K/s 00:00 [#####################] 100%
 msys.sig                  96.0   B  0.00B/s 00:00 [#####################] 100%
==> Checking if there are critical packages to upgrade.
bash 4.3.042-4 -> 4.3.046-1
pacman 5.0.0.6348.cc5a8f1-1 -> 5.0.1-1
msys2-runtime 2.4.1.16860.40c26fc-1 -> 2.6.0-1
==> Core packages require updating.
==> Please close all other MSYS2 derived windows (e.g. terminal
==> windows, Bash sessions, etc) before proceeding.
==> 警告: When the update has completed, you MUST close this MSYS2 window
==> 警告: (use Alt-F4 or red [ X ], etc.), rather than 'exit'!!!
Press [Enter] key when ready to start update...
==> Updating core packages...
依存関係を解決しています...
衝突するパッケージがないか確認しています...

パッケージ (4) bash-4.3.046-1  msys2-runtime-2.6.0-1
               msys2-runtime-devel-2.6.0-1  pacman-5.0.1-1

合計ダウンロード容量:  14.42 MiB
合計インストール容量:  72.88 MiB
最終的なアップグレード容量:  21.44 MiB

:: インストールを行いますか? [Y/n]
:: パッケージを取得します ...
 msys2-runtime-2.6.0...     2.2 MiB  1273K/s 00:02 [#####################] 100%
 bash-4.3.046-1-x86_64   1876.6 KiB  1414K/s 00:01 [#####################] 100%
 pacman-5.0.1-1-x86_64      6.8 MiB  1354K/s 00:05 [#####################] 100%
 msys2-runtime-devel...     3.6 MiB  1458K/s 00:03 [#####################] 100%
(4/4) キーリングのキーを確認                       [#####################] 100%
(4/4) パッケージの整合性をチェック                 [#####################] 100%
(4/4) パッケージファイルのロード                   [#####################] 100%
(4/4) ファイルの衝突をチェック                     [#####################] 100%
(4/4) 空き容量を確認                               [#####################] 100%
:: パッケージの変更を処理しています...
(1/4) 更新 msys2-runtime                           [#####################] 100%
(2/4) 更新 bash                                    [#####################] 100%
(3/4) 更新 pacman                                  [#####################] 100%
(4/4) インストール msys2-runtime-devel             [#####################] 100%
Please close this window.

メッセージにもありますが、アップデートが完了したら、ターミナルウィンドウを閉じます。
今回は、closeコマンドではなく、[x]ボタンや Alt + F4 で閉じてください。

再度、スタートメニューから MinGW-w64 Win64 Shell を起動します。
続いて、パッケージのアップデートをしましょう。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ pacman -Syuu
:: Starting core system upgrade...
警告: terminate other MSYS2 programs before proceeding
依存関係を解決しています...
衝突するパッケージがないか確認しています...
パッケージ (2) filesystem-2016.07-2 mintty-1~2.5.0-1
合計ダウンロード容量: 0.18 MiB
合計インストール容量: 0.39 MiB
最終的なアップグレード容量: 0.02 MiB
:: インストールを行いますか? [Y/n] y
:: パッケージを取得します...
filesystem-2016.07-... 37.4 KiB 18.2M/s 00:00 [#####################] 100%
mintty-1~2.5.0-1-x86_64 151.2 KiB 445K/s 00:00 [#####################] 100%
(2/2) キーリングのキーを確認 [#####################] 100%
(2/2) パッケージの整合性をチェック [#####################] 100%
(2/2) パッケージファイルのロード [#####################] 100%
(2/2) ファイルの衝突をチェック [#####################] 100%
(2/2) 空き容量を確認 [#####################] 100%
:: パッケージの変更を処理しています...
(1/2) 更新 filesystem [#####################] 100%
WARNING: the shell starting scripts have been unified. Please update your
shortcuts to the following targets, otherwise they will STOP WORKING:
* MSYS2_ROOT\msys2_shell.cmd -mingw32
* MSYS2_ROOT\msys2_shell.cmd -mingw64
* MSYS2_ROOT\msys2_shell.cmd -msys
(2/2) 更新 mintty [#####################] 100%
警告: terminate MSYS2 without returning to shell and check for updates again
警告: for example close your terminal window instead of calling exit
$ pacman -Syuu :: Starting core system upgrade... 警告: terminate other MSYS2 programs before proceeding 依存関係を解決しています... 衝突するパッケージがないか確認しています... パッケージ (2) filesystem-2016.07-2 mintty-1~2.5.0-1 合計ダウンロード容量: 0.18 MiB 合計インストール容量: 0.39 MiB 最終的なアップグレード容量: 0.02 MiB :: インストールを行いますか? [Y/n] y :: パッケージを取得します... filesystem-2016.07-... 37.4 KiB 18.2M/s 00:00 [#####################] 100% mintty-1~2.5.0-1-x86_64 151.2 KiB 445K/s 00:00 [#####################] 100% (2/2) キーリングのキーを確認 [#####################] 100% (2/2) パッケージの整合性をチェック [#####################] 100% (2/2) パッケージファイルのロード [#####################] 100% (2/2) ファイルの衝突をチェック [#####################] 100% (2/2) 空き容量を確認 [#####################] 100% :: パッケージの変更を処理しています... (1/2) 更新 filesystem [#####################] 100% WARNING: the shell starting scripts have been unified. Please update your shortcuts to the following targets, otherwise they will STOP WORKING: * MSYS2_ROOT\msys2_shell.cmd -mingw32 * MSYS2_ROOT\msys2_shell.cmd -mingw64 * MSYS2_ROOT\msys2_shell.cmd -msys (2/2) 更新 mintty [#####################] 100% 警告: terminate MSYS2 without returning to shell and check for updates again 警告: for example close your terminal window instead of calling exit
$ pacman -Syuu
:: Starting core system upgrade...
警告: terminate other MSYS2 programs before proceeding
依存関係を解決しています...
衝突するパッケージがないか確認しています...

パッケージ (2) filesystem-2016.07-2  mintty-1~2.5.0-1

合計ダウンロード容量:  0.18 MiB
合計インストール容量:  0.39 MiB
最終的なアップグレード容量:  0.02 MiB

:: インストールを行いますか? [Y/n] y
:: パッケージを取得します...
 filesystem-2016.07-...    37.4 KiB  18.2M/s 00:00 [#####################] 100%
 mintty-1~2.5.0-1-x86_64  151.2 KiB   445K/s 00:00 [#####################] 100%
(2/2) キーリングのキーを確認                       [#####################] 100%
(2/2) パッケージの整合性をチェック                 [#####################] 100%
(2/2) パッケージファイルのロード                   [#####################] 100%
(2/2) ファイルの衝突をチェック                     [#####################] 100%
(2/2) 空き容量を確認                               [#####################] 100%
:: パッケージの変更を処理しています...
(1/2) 更新 filesystem                              [#####################] 100%

      WARNING: the shell starting scripts have been unified. Please update your
      shortcuts to the following targets, otherwise they will STOP WORKING:

          * MSYS2_ROOT\msys2_shell.cmd -mingw32
          * MSYS2_ROOT\msys2_shell.cmd -mingw64
          * MSYS2_ROOT\msys2_shell.cmd -msys

(2/2) 更新 mintty                                  [#####################] 100%
警告: terminate MSYS2 without returning to shell and check for updates again
警告: for example close your terminal window instead of calling exit

アップデートが完了したらターミナルウィンドウを閉じましょう。

メッセージに書かれているように、起動スクリプトが変更されています。
起動スクリプトを次のように変更をしました。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
■ MinGW-w64 Win32 Shell
C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\mingw32_shell.bat
C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -mingw32
■ MinGW-w64 Win64 Shell
C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\mingw64_shell.bat
C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -mingw64
■ MSYS2 Shell
C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\msys2_shell.bat
C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -msys
■ MinGW-w64 Win32 Shell C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\mingw32_shell.bat ↓ C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -mingw32 ■ MinGW-w64 Win64 Shell C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\mingw64_shell.bat ↓ C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -mingw64 ■ MSYS2 Shell C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\msys2_shell.bat ↓ C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -msys
■ MinGW-w64 Win32 Shell
C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\mingw32_shell.bat
↓
C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -mingw32

■ MinGW-w64 Win64 Shell
C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\mingw64_shell.bat
↓
C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -mingw64

■ MSYS2 Shell
C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\msys2_shell.bat
↓
C:\Windows\System32\cmd.exe /A /Q /C C:\msys64\msys2_shell.cmd -msys

もう一度ターミナル(MinGW-w64 Win64 Shell)を起動して、アップデートがないか確認しておきましょう。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ pacman -Syuu
:: パッケージデータベースの同期中...
mingw32 は最新です
mingw64 は最新です
msys は最新です
:: Starting core system upgrade...
何も行うことがありません
:: システム全体の更新を開始...
:: repman-git を msys/pactoys-git に置き換えますか? [Y/n] y
依存関係を解決しています...
衝突するパッケージがないか確認しています...
パッケージ (42) bash-completion-2.3-1 bsdcpio-3.2.1-1 bsdtar-3.2.1-1
coreutils-8.25-1 crypt-1.3-1 curl-7.50.1-1 file-5.25-1
flex-2.6.1-1 gawk-4.1.4-1 gcc-libs-5.3.0-3 gettext-0.19.7-3
gmp-6.1.0-2 gnupg-1.4.20-1 grep-2.22-3 gzip-1.7-1
heimdal-libs-1.5.3-9 info-6.1-1 libarchive-3.2.1-1
libasprintf-0.19.7-3 libassuan-2.4.2-1 libcrypt-1.3-1
libcurl-7.50.1-1 libexpat-2.1.1-1 libgettextpo-0.19.7-3
libgpg-error-1.23-1 libgpgme-1.6.0-1 libidn-1.33-1
libintl-0.19.7-3 liblzma-5.2.2-1 libnettle-3.2-1
libopenssl-1.0.2.h-1 libssh2-1.7.0-1 libtasn1-4.9-1
mpfr-3.1.4-1 msys2-launcher-git-0.3.32.56c2ba7-2
ncurses-6.0.20160220-1 openssl-1.0.2.h-1
pactoys-git-r2.07ca37f-1 rebase-4.4.2-1
repman-git-r23.87bf865-1 [削除] wget-1.17.1-3 xz-5.2.2-1
合計ダウンロード容量: 0.90 MiB
合計インストール容量: 87.40 MiB
最終的なアップグレード容量: 6.47 MiB
:: インストールを行いますか? [Y/n] y
$ pacman -Syuu :: パッケージデータベースの同期中... mingw32 は最新です mingw64 は最新です msys は最新です :: Starting core system upgrade... 何も行うことがありません :: システム全体の更新を開始... :: repman-git を msys/pactoys-git に置き換えますか? [Y/n] y 依存関係を解決しています... 衝突するパッケージがないか確認しています... パッケージ (42) bash-completion-2.3-1 bsdcpio-3.2.1-1 bsdtar-3.2.1-1 coreutils-8.25-1 crypt-1.3-1 curl-7.50.1-1 file-5.25-1 flex-2.6.1-1 gawk-4.1.4-1 gcc-libs-5.3.0-3 gettext-0.19.7-3 gmp-6.1.0-2 gnupg-1.4.20-1 grep-2.22-3 gzip-1.7-1 heimdal-libs-1.5.3-9 info-6.1-1 libarchive-3.2.1-1 libasprintf-0.19.7-3 libassuan-2.4.2-1 libcrypt-1.3-1 libcurl-7.50.1-1 libexpat-2.1.1-1 libgettextpo-0.19.7-3 libgpg-error-1.23-1 libgpgme-1.6.0-1 libidn-1.33-1 libintl-0.19.7-3 liblzma-5.2.2-1 libnettle-3.2-1 libopenssl-1.0.2.h-1 libssh2-1.7.0-1 libtasn1-4.9-1 mpfr-3.1.4-1 msys2-launcher-git-0.3.32.56c2ba7-2 ncurses-6.0.20160220-1 openssl-1.0.2.h-1 pactoys-git-r2.07ca37f-1 rebase-4.4.2-1 repman-git-r23.87bf865-1 [削除] wget-1.17.1-3 xz-5.2.2-1 合計ダウンロード容量: 0.90 MiB 合計インストール容量: 87.40 MiB 最終的なアップグレード容量: 6.47 MiB :: インストールを行いますか? [Y/n] y
$ pacman -Syuu
:: パッケージデータベースの同期中...
 mingw32 は最新です
 mingw64 は最新です
 msys は最新です
:: Starting core system upgrade...
 何も行うことがありません
:: システム全体の更新を開始...
:: repman-git を msys/pactoys-git に置き換えますか? [Y/n] y
依存関係を解決しています...
衝突するパッケージがないか確認しています...

パッケージ (42) bash-completion-2.3-1  bsdcpio-3.2.1-1  bsdtar-3.2.1-1
                coreutils-8.25-1  crypt-1.3-1  curl-7.50.1-1  file-5.25-1
                flex-2.6.1-1  gawk-4.1.4-1  gcc-libs-5.3.0-3  gettext-0.19.7-3
                gmp-6.1.0-2  gnupg-1.4.20-1  grep-2.22-3  gzip-1.7-1
                heimdal-libs-1.5.3-9  info-6.1-1  libarchive-3.2.1-1
                libasprintf-0.19.7-3  libassuan-2.4.2-1  libcrypt-1.3-1
                libcurl-7.50.1-1  libexpat-2.1.1-1  libgettextpo-0.19.7-3
                libgpg-error-1.23-1  libgpgme-1.6.0-1  libidn-1.33-1
                libintl-0.19.7-3  liblzma-5.2.2-1  libnettle-3.2-1
                libopenssl-1.0.2.h-1  libssh2-1.7.0-1  libtasn1-4.9-1
                mpfr-3.1.4-1  msys2-launcher-git-0.3.32.56c2ba7-2
                ncurses-6.0.20160220-1  openssl-1.0.2.h-1
                pactoys-git-r2.07ca37f-1  rebase-4.4.2-1
                repman-git-r23.87bf865-1 [削除]  wget-1.17.1-3  xz-5.2.2-1

合計ダウンロード容量:   0.90 MiB
合計インストール容量:  87.40 MiB
最終的なアップグレード容量:   6.47 MiB

:: インストールを行いますか? [Y/n] y

以上でインストールが完了しました。

続いて、設定を行いましょう。

MSYS2 の設定

現在だと最低限のツールしかインストールされていないため、よく使われるパッケージをインストールします。

ターミナル(MinGW-w64 Win64 Shell)を起動します。

base-develパッケージをインストールします。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ pacman -S base-devel
:: 54 のパッケージがグループ base-devel にあります:
:: リポジトリ msys
1) asciidoc 2) autoconf 3) autoconf2.13 4) autogen 5) automake-wrapper
6) automake1.10 7) automake1.11 8) automake1.12 9) automake1.13
10) automake1.14 11) automake1.15 12) automake1.6 13) automake1.7
14) automake1.8 15) automake1.9 16) bison 17) diffstat 18) diffutils
19) dos2unix 20) file 21) flex 22) gawk 23) gdb 24) gettext
25) gettext-devel 26) gperf 27) grep 28) groff 29) help2man
30) intltool 31) lemon 32) libtool 33) libunrar 34) m4 35) make
36) man-db 37) pacman 38) pactoys-git 39) patch 40) patchutils 41) perl
42) pkg-config 43) pkgfile 44) quilt 45) rcs 46) scons 47) sed
48) swig 49) texinfo 50) texinfo-tex 51) ttyrec 52) unrar 53) wget
54) xmlto
選択して下さい (デフォルト=all):
依存関係を解決しています...
衝突するパッケージがないか確認しています...
パッケージ (76) db-5.3.28-2 docbook-xml-4.5-2 docbook-xsl-1.78.1-3
expat-2.1.1-1 gdbm-1.11-3 glib2-2.48.0-1 libgc-7.2.d-1
libgcrypt-1.6.4-1 libgdbm-1.11-3 libguile-2.0.11-3
libiconv-devel-1.14-2 libltdl-2.4.6-2 libpipeline-1.4.0-1
libunistring-0.9.6-1 libxslt-1.1.28-7
perl-Locale-Gettext-1.05-4 perl-Module-Build-0.4212-1
perl-Test-Pod-1.50-1 perl-XML-Parser-2.44-1
perl-YAML-Syck-1.29-1 python2-2.7.11-1 tar-1.29-1
asciidoc-8.6.9-4 autoconf-2.69-3 autoconf2.13-2.13-2
autogen-5.18.4-2 automake-wrapper-10-1 automake1.10-1.10.3-3
automake1.11-1.11.6-3 automake1.12-1.12.6-3
automake1.13-1.13.4-4 automake1.14-1.14.1-3
automake1.15-1.15-2 automake1.6-1.6.3-2 automake1.7-1.7.9-2
automake1.8-1.8.5-3 automake1.9-1.9.6-2 bison-3.0.4-1
diffstat-1.58-1 diffutils-3.3-3 dos2unix-7.3.4-1 file-5.25-1
flex-2.6.1-1 gawk-4.1.4-1 gdb-7.9-2 gettext-0.19.7-3
gettext-devel-0.19.7-3 gperf-3.0.4-3 grep-2.22-3
groff-1.22.3-1 help2man-1.47.3-1 intltool-0.51.0-2
lemon-3.8.7.0-1 libtool-2.4.6-2 libunrar-5.3.7-1 m4-1.4.17-4
make-4.2.1-1 man-db-2.7.4-1 pacman-5.0.1-1
pactoys-git-r2.07ca37f-1 patch-2.7.5-1 patchutils-0.3.3-2
perl-5.22.1-1 pkg-config-0.29.1-1 pkgfile-15-1 quilt-0.64-1
rcs-5.9.4-1 scons-2.5.0-1 sed-4.2.2-2 swig-3.0.10-1
texinfo-6.1-1 texinfo-tex-6.1-1 ttyrec-1.0.8-1 unrar-5.3.7-1
wget-1.17.1-3 xmlto-0.0.28-1
合計ダウンロード容量: 50.00 MiB
合計インストール容量: 282.87 MiB
最終的なアップグレード容量: 227.11 MiB
:: インストールを行いますか? [Y/n] y
$ pacman -S base-devel :: 54 のパッケージがグループ base-devel にあります: :: リポジトリ msys 1) asciidoc 2) autoconf 3) autoconf2.13 4) autogen 5) automake-wrapper 6) automake1.10 7) automake1.11 8) automake1.12 9) automake1.13 10) automake1.14 11) automake1.15 12) automake1.6 13) automake1.7 14) automake1.8 15) automake1.9 16) bison 17) diffstat 18) diffutils 19) dos2unix 20) file 21) flex 22) gawk 23) gdb 24) gettext 25) gettext-devel 26) gperf 27) grep 28) groff 29) help2man 30) intltool 31) lemon 32) libtool 33) libunrar 34) m4 35) make 36) man-db 37) pacman 38) pactoys-git 39) patch 40) patchutils 41) perl 42) pkg-config 43) pkgfile 44) quilt 45) rcs 46) scons 47) sed 48) swig 49) texinfo 50) texinfo-tex 51) ttyrec 52) unrar 53) wget 54) xmlto 選択して下さい (デフォルト=all): 依存関係を解決しています... 衝突するパッケージがないか確認しています... パッケージ (76) db-5.3.28-2 docbook-xml-4.5-2 docbook-xsl-1.78.1-3 expat-2.1.1-1 gdbm-1.11-3 glib2-2.48.0-1 libgc-7.2.d-1 libgcrypt-1.6.4-1 libgdbm-1.11-3 libguile-2.0.11-3 libiconv-devel-1.14-2 libltdl-2.4.6-2 libpipeline-1.4.0-1 libunistring-0.9.6-1 libxslt-1.1.28-7 perl-Locale-Gettext-1.05-4 perl-Module-Build-0.4212-1 perl-Test-Pod-1.50-1 perl-XML-Parser-2.44-1 perl-YAML-Syck-1.29-1 python2-2.7.11-1 tar-1.29-1 asciidoc-8.6.9-4 autoconf-2.69-3 autoconf2.13-2.13-2 autogen-5.18.4-2 automake-wrapper-10-1 automake1.10-1.10.3-3 automake1.11-1.11.6-3 automake1.12-1.12.6-3 automake1.13-1.13.4-4 automake1.14-1.14.1-3 automake1.15-1.15-2 automake1.6-1.6.3-2 automake1.7-1.7.9-2 automake1.8-1.8.5-3 automake1.9-1.9.6-2 bison-3.0.4-1 diffstat-1.58-1 diffutils-3.3-3 dos2unix-7.3.4-1 file-5.25-1 flex-2.6.1-1 gawk-4.1.4-1 gdb-7.9-2 gettext-0.19.7-3 gettext-devel-0.19.7-3 gperf-3.0.4-3 grep-2.22-3 groff-1.22.3-1 help2man-1.47.3-1 intltool-0.51.0-2 lemon-3.8.7.0-1 libtool-2.4.6-2 libunrar-5.3.7-1 m4-1.4.17-4 make-4.2.1-1 man-db-2.7.4-1 pacman-5.0.1-1 pactoys-git-r2.07ca37f-1 patch-2.7.5-1 patchutils-0.3.3-2 perl-5.22.1-1 pkg-config-0.29.1-1 pkgfile-15-1 quilt-0.64-1 rcs-5.9.4-1 scons-2.5.0-1 sed-4.2.2-2 swig-3.0.10-1 texinfo-6.1-1 texinfo-tex-6.1-1 ttyrec-1.0.8-1 unrar-5.3.7-1 wget-1.17.1-3 xmlto-0.0.28-1 合計ダウンロード容量: 50.00 MiB 合計インストール容量: 282.87 MiB 最終的なアップグレード容量: 227.11 MiB :: インストールを行いますか? [Y/n] y
$ pacman -S base-devel
:: 54 のパッケージがグループ base-devel にあります:
:: リポジトリ msys
   1) asciidoc  2) autoconf  3) autoconf2.13  4) autogen  5) automake-wrapper
   6) automake1.10  7) automake1.11  8) automake1.12  9) automake1.13
   10) automake1.14  11) automake1.15  12) automake1.6  13) automake1.7
   14) automake1.8  15) automake1.9  16) bison  17) diffstat  18) diffutils
   19) dos2unix  20) file  21) flex  22) gawk  23) gdb  24) gettext
   25) gettext-devel  26) gperf  27) grep  28) groff  29) help2man
   30) intltool  31) lemon  32) libtool  33) libunrar  34) m4  35) make
   36) man-db  37) pacman  38) pactoys-git  39) patch  40) patchutils  41) perl
   42) pkg-config  43) pkgfile  44) quilt  45) rcs  46) scons  47) sed
   48) swig  49) texinfo  50) texinfo-tex  51) ttyrec  52) unrar  53) wget
   54) xmlto

選択して下さい (デフォルト=all):
依存関係を解決しています...
衝突するパッケージがないか確認しています...

パッケージ (76) db-5.3.28-2  docbook-xml-4.5-2  docbook-xsl-1.78.1-3
                expat-2.1.1-1  gdbm-1.11-3  glib2-2.48.0-1  libgc-7.2.d-1
                libgcrypt-1.6.4-1  libgdbm-1.11-3  libguile-2.0.11-3
                libiconv-devel-1.14-2  libltdl-2.4.6-2  libpipeline-1.4.0-1
                libunistring-0.9.6-1  libxslt-1.1.28-7
                perl-Locale-Gettext-1.05-4  perl-Module-Build-0.4212-1
                perl-Test-Pod-1.50-1  perl-XML-Parser-2.44-1
                perl-YAML-Syck-1.29-1  python2-2.7.11-1  tar-1.29-1
                asciidoc-8.6.9-4  autoconf-2.69-3  autoconf2.13-2.13-2
                autogen-5.18.4-2  automake-wrapper-10-1  automake1.10-1.10.3-3
                automake1.11-1.11.6-3  automake1.12-1.12.6-3
                automake1.13-1.13.4-4  automake1.14-1.14.1-3
                automake1.15-1.15-2  automake1.6-1.6.3-2  automake1.7-1.7.9-2
                automake1.8-1.8.5-3  automake1.9-1.9.6-2  bison-3.0.4-1
                diffstat-1.58-1  diffutils-3.3-3  dos2unix-7.3.4-1  file-5.25-1
                flex-2.6.1-1  gawk-4.1.4-1  gdb-7.9-2  gettext-0.19.7-3
                gettext-devel-0.19.7-3  gperf-3.0.4-3  grep-2.22-3
                groff-1.22.3-1  help2man-1.47.3-1  intltool-0.51.0-2
                lemon-3.8.7.0-1  libtool-2.4.6-2  libunrar-5.3.7-1  m4-1.4.17-4
                make-4.2.1-1  man-db-2.7.4-1  pacman-5.0.1-1
                pactoys-git-r2.07ca37f-1  patch-2.7.5-1  patchutils-0.3.3-2
                perl-5.22.1-1  pkg-config-0.29.1-1  pkgfile-15-1  quilt-0.64-1
                rcs-5.9.4-1  scons-2.5.0-1  sed-4.2.2-2  swig-3.0.10-1
                texinfo-6.1-1  texinfo-tex-6.1-1  ttyrec-1.0.8-1  unrar-5.3.7-1
                wget-1.17.1-3  xmlto-0.0.28-1

合計ダウンロード容量:   50.00 MiB
合計インストール容量:  282.87 MiB
最終的なアップグレード容量:  227.11 MiB

:: インストールを行いますか? [Y/n] y

現状だと、Windows の PATH が参照されないため、Windows にインストールされているプログラムを実行できません。
そこで、これを参照するようにします。
C:\msys64\msys2_shell.cmd を以下のように変更します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
rem set MSYS2_PATH_TYPE=inherit
set MSYS2_PATH_TYPE=inherit
rem set MSYS2_PATH_TYPE=inherit ↓ set MSYS2_PATH_TYPE=inherit
rem set MSYS2_PATH_TYPE=inherit
↓
set MSYS2_PATH_TYPE=inherit

以上で設定が完了しました。

使ってみましょう

ホームディレクトリは、/home/username で、実体は、C:\msys64\home\username です。

ssh をインストールしてみます。パッケージのインストールは、pacman -S パッケージ名 で行えます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pacman -S openssh
pacman -S openssh
pacman -S openssh

インストール可能なパッケージは、次のコマンドで確認できます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pacman -Sl
pacman -Sl
pacman -Sl

おわりに

今回は、Windows に Unix ライクな環境を構築することを目的に、MSYS2 を用いて Bash 環境を構築しました。

Mac や Linux と同一の環境とまではいきませんが、ローカル環境でちょっとコマンドを実行したいとき、Mac で作成したスクリプトを Windows でも実行したいときなどに、大いに役立てられるのではないでしょうか。

そして、ウエディングパークでは、技術のウエディングパークを創っていく、未来の仲間を募集しています。

興味のある方は、まずはお気軽にオフィスに遊びにきてください。

IT×ブライダルで業界を変える!プロフェッショナルなWEBエンジニア募集!

Join Us !

ウエディングパークでは、一緒に働く仲間を募集しています!
ご興味ある方は、お気軽にお問合せください(カジュアル面談から可)

採用情報を見る