Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:53:03+00:00 2026-06-11T12:53:03+00:00

There are some batch files in the Ruby installation that reference this Ruby exe

  • 0

There are some batch files in the Ruby installation that reference this Ruby exe ($~dp0ruby.exe). For example, gem.bat (note the last line)

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
GOTO :EOF
:WinNT
@"%~dp0ruby.exe" "%~dpn0" %*

But, some gems get a batch file that references the system Ruby (ruby.exe), whichever one is on the PATH. For example, bundle.bat

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "C:/Ruby192/bin/bundle" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*

I have an isolated Ruby environment for a .NET project (where it’s unlikely that the developers or build agents have a system Ruby). But, many gems (bundler, rake, etc) are trying to execute in a non-existent system Ruby.

C:\
  Ruby192\            <-- System Ruby, would be here
    bin\                  and this bin would be in the
      bundle.bat          PATH
      gem.bat
      ruby.exe

  <some-other-path>\  <-- An isolated environment, in
    Ruby\                 my problem, this is deployed 
      bin\                to a build agent
        bundle.bat
        gem.bat
        ruby.exe

What gives? Is this a defect in the way that rubygems creates the batch file?

def windows_stub_script(bindir, bin_file_name)
  ruby = File.basename(Gem.ruby).chomp('"')
  return <<-TEXT
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"#{ruby}" "#{File.join(bindir, bin_file_name)}" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"#{ruby}" "%~dpn0" %*
TEXT
end

What’s the thinking of not referencing the ruby.exe that you used to gem install this gem? Am I just doing it wrong? Should I require a system Ruby and then using Bundler or something to isolate it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:53:05+00:00Added an answer on June 11, 2026 at 12:53 pm

    I’m one of the maintainers of RubyInstaller project, which is the one that produced the first batch files you shown.

    When Ruby is compiled, we replace the generated batch files that Ruby builds with our own batch_stub

    This stub considers %~dp0 as the place where Ruby’s executable is, relative to this batch file, because we know these batch files will be along the executable.

    Gems can be installed anywhere, not only inside Ruby’s tree (e.g. by using Bundler or gem install --install-dir or --bindir).

    RubyGems batch files can’t use %~dp0 to determine Ruby in those cases, which is why these batchfile stubs contains only ruby.exe in them.

    The problem, as you indicated, is that ruby.exe will be found from PATH, which contains your global Ruby installation and not the isolated one you’re working on.

    A quick fix will be prepend the PATH with the directory of this isolated Ruby:

    SET PATH=C:\<some-other-path>\Ruby\bin;%PATH%
    

    You can put that in a batch file like setenv.bat that adjust the environment prior execution of Ruby (or as startup script).

    The other alternative is use something like gem-exefy, which will replace the batch files for executable stubs and will use the Ruby dlls found relative to it, so will use the isolated version instead of the global one.

    For homework I’m not sure if bundle exec will work as it will use PATH to look for the executable to run, so can’t tell you in detail.

    Hope this explains why the batch files generated by RubyGems differ from the ones generated by RubyInstaller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Windows batch files, but I'm writing a .bat file that just
Just converting some shell scripts into batch files and there is one thing I
I have a pile of batch files that do something like this with program
Is there some kind of software that I can feed uploaded images to and
Is there some regex that can be passed to re-seq such that it will
I'm cleaning up some old Windows batch files at work, and keep seeing lines
I found some this promising code on activestate.com to sort huge files. I'm trying
I would like to create some batch scripts to move some files around. But
I'm writing my own batch script to backup some files to an external. here's
I'm using MsBuild and the TransformXml task to set up some web.config files. That's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.