Cygwinとは?
みなさんやWindows環境でCygwinを利用したことはありますでしょうか?
CygwinはWindows環境でありながら、UNIXのような環境が利用できるフリーのソフトです。そのためUNIXのシェアやコマンドをWindows上で動作させる環境が手に入るので重宝しているエンジニアの方も多いかと思います。
一方でWindowsのGUIに慣れていて、これから初めてCygwinやCUIを利用する方にとっては、未知の領域です。

そこで今回はCygwinをWindows10にインストールする方法から、日本語化までを丁寧にご紹介していきます。
はじめての方はぜひあの黒い画面に入門しましょう!
Cygwinのインストール方法
それでは早速Cygwinのインストール方法をご紹介していきます。インストーラーをダウンロードして、インストーラーでsetupをする流れになります。
ダウンロード
まずはCygwinをダウンロードしましょう。下記のサイトからダウンロードすることが出来ます。

Windows10が64bitの方は「setup-x86_64.exe」を、32bitの方は「setup-x86.exe」をダウンロードしましょう。
またご自身のWindows10のPCが64bitなのか32bitなのか分からないという方は下記の記事を参考にbit数を調べましょう。
インストール
ダウンロードされたCygwinのexeファイルを実行してインストーラーを起動しましょう。


こちらはそのままで「次へ」をクリックします。

特に変更がなければ、そのままで「次へ」をクリックしましょう。

「次へ」をクリックしましょう。

特に特殊な環境でなければ、そのままで「次へ」をクリックします。



おすすめのパッケージ
ちなみにCygwinで入れておくべきおすすめのパッケージをご紹介します。
おすすめのパッケージ
- Archive: unzip、zip、bzip2、xz
- Devel: git, git-completion, libiconv, subversion, gcc, gcc-g++, make、patchutils、ctag
- Editors: vim、emacs
- Net: connect-proxy, curl, inetutils, lftp, netcat, openssh, tftp, whois、ca-certificates 、rsync
- Shells: zsh, pdksh, tcsh
- System: procps, psmisc
- Tcl: expect
- Utils: bc, cpio, rpm, ncurses, screen, util-linux
- Web: wget
- Graphics: imagemagick、optipng、exif
- 言語: python、ruby、perl
ではCygwinのインストールの続きを見ていきます。


必要に応じてチェックをして、「完了」をクリックしてインストールを完了させましょう。
Cygwinの日本語化方法
次にCygwinの日本語化の方法について見ていきます。Cygwinの各種設定ファイルを日本語化していく方法となります。
Linuxをお使いの方でbashの設定をカスタマイズをしている方にはおなじみの.bashrcや普段エディターにvimを利用している方におなじみの.vimrcなど設定ファイルを日本語化していきます。
Cygwinの設定
基本ユニコードのutf8を使っていきましょう。一部sjisじゃないと文字化けするものもありますが、現代であればデフォルトはutf8を使うのがスタンダートです。

続いて「Text」を選択し、フォントはMS ゴシックに、Localeの箇所を「ja_JP」に、Character setを「UTF-8」に設定します。
.bashrc
.bashrcで言語の指定と、日本時間の時差、出力文字をUTF8に設定します。Cygwinを立ち上げviなどで.bashrcのファイルを編集して、下記を追記しましょう。
export LANG=ja_JP.UTF-8 export OUTPUT_CHARSET=utf8 export TZ=JST-9 alias ls='ls --show-control-chars'
.inputrc
set kanji-code utf8 set convert-meta off set meta-flag on set output-meta on
.vimrc
エディターのvimも言語とエンコーディングを設定しておきましょう。
let $LANG='ja' set encoding=utf-8
設定ファイルを書き換えたらCygwinを再起動させましょう。これで設定ファイルが反映されるはずです。
以上となります。
まとめ
Cygwinのインストールと日本語化するまでをご紹介していきました。UNIXライクな環境は今までGUIに慣れ親しんだ方にとっては少し慣れが必要です。
ぜひいつもCUI環境を使う習慣をCygwinを使ってつけていきましょう。