There are times when you will need to try out if your code works with a new version of JRuby or maybe, even make a change to the JRuby code and see if this is a change you want to contribute. This post touches on how to set up and build JRuby on your Windows PC.
Downloading the snapshots
This post is more focused on setting up and building JRuby. However, if you just want to try if everything works as expected on a newer version of JRuby, you can actually use one of the nightly snapshots instead of building it yourself. Head on over to https://www.jruby.org/nightly and find the builds you need – there are snapshots for 9.2.x and right now, even for 126.96.36.199 as that release gets prepared.
This post does not go through all the details because the instructions on the JRuby page for building JRuby are actually very good and work almost as you would expect.
There are only a couple of things to know when you’re on Windows.
Grab the source
If you’re familiar with Git, this is easy – head on to https://github.com/jruby/jruby and clone or download the source. I’ve got it in a folder
d:\projects\github\jruby and I might refer to this path further down.
There are a few main prerequisites which are all covered here:
- C++ Compiler and make
- Java Development Kit (JDK)
- Maven and Ant
C++ Compiler and make
Some parts of the compilation require make and a C++ compiler. If you use multiple versions of Ruby, the easiest is to just point it to the DevKit for any of the Ruby versions that you already have. If you need, refer to the instructions for installing Ruby on your Windows PC on this site.
Once that’s done, you can just point to the correct directories for the compiler and make by adding the folowing directories to the PATH. Assuming you installed Ruby 2.6 for x64 into the default paths, the directories to add to the PATH are:
If you have Ruby 2.7 or Ruby 3.0, the base path will likely change to
c:\Ruby30-x64 and the rest will be the same.
You will need to add to the PATH temporarily by doing:
You can check that make is available on the PATH after making the changes by doing:
$ make -v GNU Make 4.3 Built for x86_64-pc-msys Copyright (C) 1988-2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
Java Development Kit (JDK)
You can install any version directly or if you need, follow this post to switch between JVMs on Windows
Maven and Ant
To be able to build JRuby using the JDK that you just installed requires two more tools:
Both the sites have instructions that help but I have put down the main points here.
Planning the Setup
In my setup, I have a few folders set up for managing where things go:
D:\Apps– a bunch of applications (Windows executable) and other things that I use
D:\Apps\jdk– place where all the alternative JDKs are stored
D:\Apps\jlib– place to store Java libraries/ applications
D:Tools– place for Windows Command or Powershell files or related executables that I might use from some place
There is some overlap between
d:\tools but for me, the main difference is that
d:\tools is on the PATH. This means that I can directly run executables or command files from
d:\tools and I use that to store small batch files that run things for me.
Of course, you are welcome to follow whatever convention works well for you. I will use these paths in the rest of the post.
The instructions for installing Maven on Windows are at: https://maven.apache.org/guides/getting-started/windows-prerequisites.html but in brief:
- Go to the Maven Download page and download the ZIP file for Windows (Binary zip archive)
- Unzip the package to a folder
- Add the Maven bin directory to your PATH
In my case, I unzipped the Maven folder into
d:\apps\jlib so that I have
d:\apps\jlib\apache-maven-3.8.1 and there is a
bin folder under it which has the maven command files.
Given that, we need to add the maven bin folder to the path so that it can be found. There are two ways to do this:
- Make it permanent by configuring it within Windows so that it’s part of your PATH always
- Do it temporarily for a session on the command line by doing (in my case):
$ set PATH=d:\apps\jlib\apache-maven-3.8.1\bin;%PATH%
With that done, you should be able to check that Maven is OK by doing:
$ mvn -version Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: d:\apps\jlib\apache-maven-3.8.1\bin\.. Java version: 11.0.11, vendor: AdoptOpenJDK, runtime: d:\apps\jdk\jdk-11.0.11_x64 Default locale: en_SG, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
This effects the change only for the current session, so you will need to do it again every time. I personally prefer it this way because I don’t build JRuby or similar applications very often, and my Windows path is already very long. So, I add it on when I need it, especially using the method in the section further down.
Ant is a little bit more complicated but the Ant site has working instructions that work well. To get up and running with the binary distribution of Ant quickly, follow these steps:
- From the binary downloads page get the latest version in the .zip format
- Unzip to some folder on your PC. As with Maven, I unzipped it to
d:\apps\jlibso I have it in
- Set environmental variables:
- JAVA_HOME to your Java environment – this will probably be set anyway when you installed Java
- ANT_HOME to the directory you uncompressed Ant to – in my case, this requires
- Set up the PATH to include
ANT_HOME\bin– in my case, we need to add
d:\apps\jlib\apache-ant-1.10.10\binto the PATH. Again, we can add it to the path permanentaly or temporarily by doing:
$ set PATH=d:\apps\jlib\apache-ant-1.10.10\bin;%PATH%
With this done, you should be able to check that Ant is OK by doing:
$ ant -version Apache Ant(TM) version 1.10.10 compiled on April 12 2021
The Ant site also recommends doing this:
- Optionally, from the ANT_HOME directory run ant -f fetch.xml -Ddest=system to get the library dependencies of most of the Ant tasks that require them. If you don’t do this, many of the dependent Ant tasks will not be available.
Once done, you are now quite ready.
JRuby comes with a wrapper for maven, called
mvnw.cmd and this is what we use. Go to your JRuby source directory and you can type this in.
d:\projects\github\jruby> mvnw D:\projects\github\jruby>mvnw [INFO] Scanning for projects... WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.jruby.runtime.encoding.EncodingService (file:/C:/Users/mohit/.m2/repository/org/jruby/jruby-core/188.8.131.52/jruby-core-184.108.40.206.jar) to field java.io.Console.cs WARNING: Please consider reporting this to the maintainers of org.jruby.runtime.encoding.EncodingService WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] JRuby [pom] [INFO] JRuby Base [jar] [INFO] JRuby Core [jar] [INFO] JRuby Lib Setup [jar] [INFO] [INFO] -----------------------< org.jruby:jruby-parent >----------------------- ...
Off it goes! It might take some time (12 – 15min in my case for the first time) and there were approximately 2500 lines of text that flew by but at the end it gave me the rather reassuring:
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for JRuby 220.127.116.11-SNAPSHOT: [INFO] [INFO] JRuby .............................................. SUCCESS [ 8.370 s] [INFO] JRuby Base ......................................... SUCCESS [01:13 min] [INFO] JRuby Core ......................................... SUCCESS [ 11.704 s] [INFO] JRuby Lib Setup .................................... SUCCESS [02:04 min] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 03:45 min [INFO] Finished at: 2021-07-18T15:00:31+08:00 [INFO] ------------------------------------------------------------------------
You will see that
mvnW contacts the Maven site every time you run it. You can prevent that by doing
mvnw -o or
mvnw -Pall -o instead which makes it offline.
Using the newly built JRuby
To use the newly built JRuby, you just need to add the
bin directory of your new Ruby distribution to the front of the PATH. In my case, this is what I need:
d:\projects\github\jruby> set PATH=d:\projects\github\ruby;%PATH% d:\projects\github\jruby> jruby -v jruby 18.104.22.168-SNAPSHOT (2.6.5) 2021-07-13 ebf1bcbaa9 OpenJDK 64-Bit Server VM 11.0.11+9 on 11.0.11+9 +jit [mswin32-x86_64]
You can also do all the regular stuff like
jruby -S gem install ... or
jruby -S irb as you normally would.
A Command File to kick it off
At this point, everything works as we expect. The next part is specific to my setup and it might help you, especially if you do this rarely.
As I mentioned above, I have the following setup:
- Maven installed to:
- Ant installed to:
- JRuby source at:
Since I do not build JRuby often enough, I have added a new CMD file to
d:\tools which is always on the PATH. The contents are as follows:
:: jrdev.cmd - sets up PATH and variables for building JRuby locally :: Trims the path as per what I might need :: Minimally add: Java, Maven, Ant, CRuby mingw Devkit and the newly built JRuby to the PATH set PATH=d:\apps\jdk\jdk-11.0.11_x64\bin;D:\projects\github\jruby\bin;d:\apps\jlib\apache-ant-1.10.10\bin;d:\apps\jlib\apache-maven-3.8.1\bin;c:\Ruby26-x64\msys64\mingw64\bin;c:\Ruby26-x64\msys64\usr\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\Program Files\TortoiseSVN\bin;C:\Go\bin;C:\Program Files\dotnet\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Ruby26-x64\bin;C:\Users\mohit\AppData\Local\Microsoft\WindowsApps;C:\Users\mohit\go\bin;C:\Program Files\IBM\Cloud\bin;D:\Tools;C:\Users\mohit\AppData\Roaming\npm;C:\Users\mohit\AppData\Local\Yarn\bin :: Set JAVA_HOME for the JDK above set JAVA_HOME=d:\apps\jdk\jdk-11.0.11_x64 :: Set ANT_HOME for Ant to work correctly set ANT_HOME=d:\apps\jlib\apache-ant-1.10.10 :: Move to the JRuby directory d: cd \projects\github\jruby :: Optional - show the version of the built JRuby :: will fail if you have not built JRuby yet or have removed it jruby -v
I’m sorry that the PATH line is a bit of a runaway line in the text above but you can see it better in the screenshot below. In my case, this file is stored as
It’s very important that you ensure that the coloured parts are in:
- The PATH must include the following:
- JAVA (shown in yellow)
- Ant and Maven (in green)
- Ruby Devkit (in green)
- (in my case) D:\Tools – so that I can call this file and others from that directory
- (optionally) New JRuby bin (in blue)
- Environment variables must be set
- JAVA_HOME (in yellow) – must match the JDK on the path
- ANT_HOME (in green) – must match the Ant on the path
In addition to this, the command file just moves to the JRuby directory and calls jruby to print the version.
Since this is in
d:\tools is on the path, I can do this from any console window to get ready to do something with the JRuby source.
With that, we come to the end of this post. I hope you find it useful. If you have any other information to add, please let me know below and I will add it in.