LoginSignup
2
2

More than 3 years have passed since last update.

WindowsでRuby/GTK3を実行する

Last updated at Posted at 2019-07-08

MacやLinuxの場合,
gem install gtk3
でインストールできるらしいのですが,Windowsだと少し面倒なのでメモ.

RubyInstaller for Windows をダウンロード

  • 以下からRubyInstallerをダウンロードします.
  • 以後 rubyinstaller-2.6.3-1-x64.exe をダウンロードしたものとして説明します.

ダウンロードしたrubyinstaller-2.6.3-1-x64.exeを実行

  • ウィザードに従って進めます.
    ri1.png

  • ダブルクリックでrbを起動したい場合は,「Associate .rb and .rbw files ~」にチェックを入れます.
    ri2.png

  • 最後の画面で「Run 'ridk install' to setup MSYS2 ~」にチェックを入れます.
    ri3.png

  • 以下のコンソールが起動します.
    ri4.png

MSYS2をインストール

  • 「1」を入力し,「MSYS2 base installation」を実行します.
    ri5.png

  • 以下のウィザードが起動するので「次へ」をクリックします.

ri6.png
  • インストール先フォルダを選択します.(以後「C:\msys64」にインストールしたものとします)
    ri7.png

  • 「次へ」をクリックします.
    ri8.png

  • 「完了」をクリックします.
    ri9.png

  • 続いて「2」を入力し,「MSYS2 system update (optional)」を実行します.
    ri10.png

  • 続いて「3」を入力し,「MSYS2 and MINGW development toolchain」を実行します.
    ri11.png

  • 完了したらEnterを押します.
    ri12.png

GTK3のインストール

  • コマンドプロンプトを開き,インストールしたRuby環境を用いて,GTK3をインストールします.
> cd C:\Ruby26-x64\bin  
> gem install gtk3
  • 結構時間がかかりますが,インストールが完了すると以下のようになります.
    ri14.png

動作確認

  • 以下のコードを任意の場所へ保存します.
test.rb
#!ruby -w

require "gtk3"
cWindow = Gtk::Window.new()
cWindow.signal_connect(:destroy){Gtk.main_quit()}
cWindow.show()
Gtk.main()
  • インストールしたRuby環境でtest.rbを実行します.
> C:\Ruby26-x64\bin\ruby.exe test.rb
  • 以下のウィンドウが起動すればOKです.
    ri15.png
2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2