Skip to content

Configure Ruby Environment on Windows

This is a simple guide for configuring a Ruby 2 environment on Windows 11. All scripts are PowerShell.

PowerShell

This will allow you to execute PowerShell scripts locally on your machine. In PowerShell as Administrator:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Chocolatey

In PowerShell as Administrator:

Set-ExecutionPolicy AllSigned
Set-ExecutionPolicy Bypass -Scope Process -Force
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Close and reopen PowerShell after that.

Set cache directory

In PowerShell as Administrator:

choco config set cacheLocation C:/ChocoCache

Upgrade

choco upgrade chocolatey

Ruby

In PowerShell as Administrator:

choco install ruby -version 2.7.2.1 -m

Ruby DevKit (2.0+)

Install

Open PowerShell as Administrator and run the following command:

choco install ruby2.devkit

This will install Ruby DevKit 2.0+ and its dependencies- in C:\tools\DevKit2.

Configure

Open C:\tools\DevKit2\config.ymland add C:\tools\ruby27 path at the end. The complete config.yml should look like this:

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
---
 - C:/tools/ruby27

Run the DevKit installer:

cd C:/tools/DevKit2
ruby dk.rb install

Ruby Version Manager

Download latest uru.x.y.z.nupkg from uru's downloads. This was uru.0.8.5.nupkg at the time of writing.

In PowerShell as Administrator:

cd ~/Downloads
Invoke-WebRequest -Uri "https://bitbucket.org/jonforums/uru/downloads/uru.0.8.5.nupkg" -outfile "uru.0.8.5.nupkg"
choco install uru.0.8.5.nupkg

Register Ruby Versions

This will work only if you previously have installed Ruby via Chocolatey.

In PowerShell:

uru admin rm --all
uru admin add --recurse C:\tools

Test:

uru ls

Install Ruby Native Environment

This is needed for gems that requre antive compilation.

# activate Ruby 2.7
uru 2.7.2

# use a recent MSYS2 version
$env:MSYS2_VERSION="20230526"

# install
ridk install

A list of the available MSYS2 versions is available here.