Installation and your first window
This lesson gets wxRuby3 installed and running on your machine. The process has a few more steps than a typical gem install — wxRuby3 wraps a C++ toolkit, so there is a build step involved. This lesson walks through it on each platform and makes sure you know what a working installation looks like before moving on.
Prerequisites
Ruby
wxRuby3 requires Ruby 3.1 or later. Check your version:
|
|
If you are managing Ruby versions with rbenv, mise, or asdf, make sure the version is active before installing the gem. wxRuby3’s native extensions are compiled against the Ruby version that was active at install time — mixing versions later causes confusing errors.
Platform prerequisites
macOS
You need Xcode Command Line Tools:
|
|
If you have Homebrew, that is sufficient — it pulls in the tools wxRuby3 needs. No additional libraries are required on macOS; the setup process uses the system’s built-in WebKit and Cocoa frameworks.
Installing the gem
|
|
On macOS and Linux, this installs the gem but does not yet build the native extensions. That is the next step.
On Windows with RubyInstaller, the binary gem installs completely here and you can skip the setup step.
Building the native extensions (macOS and Linux)
|
|
This command compiles wxRuby3’s native extension libraries against your platform’s wxWidgets installation. Depending on your machine and whether wxWidgets needs to be built from source, this can take anywhere from two minutes to twenty.
You will see output as the build progresses. If it fails, the error is almost always a missing system library — the message will name the missing dependency.
To run setup without interactive prompts (useful in CI or scripted environments):
|
|
Verifying the installation
|
|
A working installation exits silently. If something is wrong, this command tells you what is missing.
For a more thorough check, run the test suite:
|
|
This takes a few minutes but confirms that the native extensions are working correctly. You do not need to run this every time — once after initial setup is enough.
Exploring the bundled sampler
wxRuby3 ships with dozens of working example applications. Before writing your own code, it is worth spending a few minutes here:
|
|
This opens a GUI window listing all bundled samples by category. Double-click any sample to run it. You will see menus, toolbars, custom drawing, grids, trees, dialogs — the full range of what wxRuby3 can do. We return to the sampler in the next lesson with more guidance on how to read the code.
Your first window
Create a file called hello.rb:
|
|
Run it:
|
|
A native, empty window should appear. That is a complete wxRuby3 application — an event loop is running, the window is responding to resize and close events, and the process will exit cleanly when you close the window.
A more structured first app
The one-liner above works, but real wxRuby3 apps use a class for the frame. Here is the pattern you will use throughout this series:
|
|
Run this and you have a window with a label, a button, and a working click handler that shows a native message dialog.
This is the skeleton of every wxRuby3 app you will write:
- A class inheriting from
Wx::Frame initializecallssuperwith the window title and size, then builds the widget tree- A
Wx::Panelimmediately inside the frame, widgets inside the panel - A sizer managing the layout (covered properly in Module 2)
evt_*methods registering handlers ininitialize- Handler methods defined privately
Save this file. You will modify it in the sampler lesson, and it is useful to have a working skeleton to hand throughout the series.
If something goes wrong
require 'wx' fails with a load error
The gem is installed but the native extensions are not built. Run wxruby setup.
wxruby: command not found
The gem’s executables are not on your PATH. Run gem environment to find the bin directory and add it to your shell profile. With rbenv or mise, try rbenv rehash or mise reshim.
The window appears but looks wrong (wrong colours, misaligned controls)
You are likely placing controls directly inside the frame rather than inside a panel. Always use Wx::Panel.new(self) and parent your controls to the panel.
Build fails on Linux with a missing header The wxWidgets development libraries are not installed. Return to the platform prerequisites section above and install the listed packages for your distribution.
Previous: The mental model shift | Next: Exploring the sampler