documentation for installing Ruby/Tk on Windows

Hello, I’m the author of the TkDocs.com <http://tkdocs.com/> site which provides a tutorial on using Tk from various languages, Ruby being one of them.

I’m working through a site update and as part of that bringing everything up to date with current versions of Ruby, Tk, etc. The last time I updated the Ruby part was for 1.9, and those install instructions no longer work.

After a couple of hours of beating my head against a wall, I finally figured out how to get everything working. I’m including below a draft of the new installation instructions. I’d appreciate any feedback or suggestions for improvement before I fully incorporate them into the next TkDocs update.

Thanks
Mark

* * *

Ruby/Tk is the binding for Tk. In the distant past, installing it on your Windows machine used to be pure hell, involving installing a separate version of Tcl/Tk, downloading a development environment like Visual Studio, downloading the Ruby source code, carefully compiling Ruby, ...

Luckily, it is now only mildly painful, thanks to the good folks behind RubyInstaller for Windows.

  FYI: The one-click installer used to include everything you needed to run Ruby/Tk, including the underlying Tcl/Tk libraries. Unfortunately, Tk was removed from the Ruby standard library (stdlib) in version 2.4, and made available as an external gem. RubyInstaller followed suit.

*Install ActiveTcl*

First, you'll need to install Tcl/Tk.

On Windows, the easiest way to get Tcl/Tk onto your machine is to install the "ActiveTcl" distribution from ActiveState, which includes Tcl, Tk, plus a number of other extension libraries.

In your web browser, go to www.activestate.com, and follow along the links to download the Community Edition of ActiveTcl for Windows. Make sure you're downloading an 8.6.x version. Note that you will need to create an account with ActiveState (no cost) to download it.

Run the installer, and follow along. You'll end up with a fresh install of ActiveTcl in C:\ActiveTcl.

*Install Ruby*

Next, go to rubyinstaller.org. Download and run the installer, which will install everything into the directory you choose, e.g. C:\Ruby26.

*Install Ruby/Tk*

Next, you'll need to download and install Ruby's Tk module, which is packaged as a Ruby gem. To do so, open a command prompt and run:

gem install tk

*Tell Ruby Where to Find ActiveTcl*

You're not done yet. If you try to use Tk from Ruby, it will complain that it can't find the underlying Tcl/Tk libraries. We'll need to do a couple of things to fix that.

First, Ruby needs to find the tcl86t.dll and tk86t.dll shared libraries. These are located in C:\ActiveTcl\bin. Make a copy of them somewhere Ruby can find them, e.g. C:\Ruby26\bin.

Second, the Tcl and Tk shared libraries will look for a bunch of initialization and other scripts which were installed as part of ActiveTcl. The best way to specify where to find them is to set the TCL_LIBRARY and TK_LIBRARY system environment variables.

This can be done in the Windows control panel (or search for "system environment variables" from the taskbar). In Windows 10, you'll find a button labelled "Environment Variables..." in the "Advanced" tab of "System Properties". Add these system variables:

TCL_LIBRARY C:\ActiveTcl\lib\tcl8.6
TK_LIBRARY C:\ActiveTcl\lib\tk8.6

If you're running a shell via command prompt you'll need to restart it to see those new additions.

To verify the version of Tk, start up your newly installed copy of 'irb' (which would have been installed in C:\Ruby26\bin), and type:

% require 'tk'

% Tk::TK_PATCHLEVEL
The first line should load Ruby/Tk. The second line will return the version of Tk that you're running, which should be something like "8.6.9".

One of the best names in software tickle tock :grin::rofl::+1::+1:t5:

···

On Sun, Sep 6, 2020, 1:36 PM Mark Roseman <mark@markroseman.com> wrote:

Hello, I’m the author of the TkDocs.com site which provides a tutorial on
using Tk from various languages, Ruby being one of them.

I’m working through a site update and as part of that bringing everything
up to date with current versions of Ruby, Tk, etc. The last time I updated
the Ruby part was for 1.9, and those install instructions no longer work.

After a couple of hours of beating my head against a wall, I finally
figured out how to get everything working. I’m including below a draft of
the new installation instructions. I’d appreciate any feedback or
suggestions for improvement before I fully incorporate them into the next
TkDocs update.

Thanks
Mark

* * *

Ruby/Tk is the binding for Tk. In the distant past, installing it on your
Windows machine used to be pure hell, involving installing a separate
version of Tcl/Tk, downloading a development environment like Visual
Studio, downloading the Ruby source code, carefully compiling Ruby, ...

Luckily, it is now only mildly painful, thanks to the good folks
behind RubyInstaller for Windows.

FYI: The one-click installer used to include everything you needed to run
Ruby/Tk, including the underlying Tcl/Tk libraries. Unfortunately, Tk was
removed from the Ruby standard library (stdlib) in version 2.4, and made
available as an external gem. RubyInstaller followed suit.

*Install ActiveTcl*

First, you'll need to install Tcl/Tk.

On Windows, the easiest way to get Tcl/Tk onto your machine is to install
the "ActiveTcl" distribution from ActiveState, which includes Tcl, Tk, plus
a number of other extension libraries.

In your web browser, go to www.activestate.com, and follow along the
links to download the Community Edition of ActiveTcl for Windows. Make sure
you're downloading an 8.6.x version. Note that you will need to create an
account with ActiveState (no cost) to download it.

Run the installer, and follow along. You'll end up with a fresh install of
ActiveTcl in C:\ActiveTcl.

*Install Ruby*

Next, go to rubyinstaller.org. Download and run the installer, which will
install everything into the directory you choose, e.g. C:\Ruby26.

*Install Ruby/Tk*

Next, you'll need to download and install Ruby's Tk module, which is
packaged as a Ruby gem. To do so, open a command prompt and run:

gem install tk

*Tell Ruby Where to Find ActiveTcl*

You're not done yet. If you try to use Tk from Ruby, it will complain that
it can't find the underlying Tcl/Tk libraries. We'll need to do a couple of
things to fix that.

First, Ruby needs to find the tcl86t.dll and tk86t.dll shared libraries.
These are located in C:\ActiveTcl\bin. Make a copy of them somewhere Ruby
can find them, e.g. C:\Ruby26\bin.

Second, the Tcl and Tk shared libraries will look for a bunch of
initialization and other scripts which were installed as part of
ActiveTcl. The best way to specify where to find them is to set
the TCL_LIBRARY and TK_LIBRARY system environment variables.

This can be done in the Windows control panel (or search for "system
environment variables" from the taskbar). In Windows 10, you'll find a
button labelled "Environment Variables..." in the "Advanced" tab of "System
Properties". Add these system variables:

TCL_LIBRARY C:\ActiveTcl\lib\tcl8.6
TK_LIBRARY C:\ActiveTcl\lib\tk8.6

If you're running a shell via command prompt you'll need to restart it to
see those new additions.

To verify the version of Tk, start up your newly installed copy of 'irb'
(which would have been installed in C:\Ruby26\bin), and type:

% require 'tk'

% Tk::TK_PATCHLEVEL
The first line should load Ruby/Tk. The second line will return the
version of Tk that you're running, which should be something like "8.6.9".

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>