takaya030の備忘録

PHP、Laravel、Docker などの話がメインです

MSYS2 と MinGW のインストール

MSYS2 と MinGW のインストール手順メモ。今回は共に x86_64 版をインストールする

検証環境

Windows10 Home Edition

MSYS2 のインストール

下記サイトから MSYS2 のインストーラをダウンロード、実行してインストールする
(2018-01-17現在、最新版は msys2-x86_64-20170918.exe)
MSYS2 download | SourceForge.net

インストール済みパッケージの更新

MSYS2 のシェルを起動して下記コマンドを実行する

# パッケージデータベースの更新
$ pacman -Sy
# プリインストールされているパッケージを最新版に更新
$ pacman -Suu

以下の警告が出た場合、MSYS2 のシェルをクローズボタンで終了し、再起動して再度 pacman -Suu を実行する

警告: terminate MSYS2 without returning to shell and check for updates again
警告: for example close your terminal window instead of calling exit

以上を更新パッケージが無くなるまで繰り返す。

.bash_profile, .bashrc の作成

環境変数 HOMEディレクトリに次の 2 ファイルを作成する
.bash_profile

test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

.bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
alias ls='ls -F --color=auto'
alias ll='ls -la --color=auto'
alias la='ls -a --color=auto'
alias sl='ls -F --color=auto'

MinGW-w64 のインストール

MSYS2 のシェルで下記コマンドを実行する

$ pacman -S base-devel
$ pacman -S mingw-w64-x86_64-toolchain

動作確認

MSYS2 MinGW 64bit のシェルを起動して下記コマンドを実行
インストールが成功していれば gcc のバージョンが表示される

$ gcc --version
gcc.exe (Rev2, Built by MSYS2 project) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.