ruby / ruby/rubygems

System update breaks JRuby gem shebang on Darwin

Open
#4,404 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

RubyGems type: bug report
Dominant language
Ruby
Stars
4k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
81

Description

When updating RubyGems it installs a gem binscript. However the shebang for this script attempts to reference the jruby executable directly:

diff --git a/bin/gem b/bin/gem
index 37772c863f..fc75806dcc 100755
--- a/bin/gem
+++ b/bin/gem
@@ -1,4 +1,18 @@
-#!/usr/bin/env jruby
+#!/Users/headius/projects/jruby-9.2/bin/jruby

However, by default this executable is a bash script, and on Darwin (and I think on other BSDs as well) you cannot put a bash script in the shebang of another language's script. When you do, it attempts to run the language script with bash, producing errors like this:

$ gem list bundler
/Users/headius/projects/jruby-9.2/bin/gem: line 8: require: command not found
/Users/headius/projects/jruby-9.2/bin/gem: line 9: require: command not found
/Users/headius/projects/jruby-9.2/bin/gem: line 10: require: command not found
/Users/headius/projects/jruby-9.2/bin/gem: line 12: args: command not found
/Users/headius/projects/jruby-9.2/bin/gem: line 14: begin: command not found
/Users/headius/projects/jruby-9.2/bin/gem: line 15: Gem::GemRunner.new.run: command not found
/Users/headius/projects/jruby-9.2/bin/gem: line 16: rescue: command not found
/Users/headius/projects/jruby-9.2/bin/gem: line 17: exit: e.exit_code: numeric argument required

Perhaps the installation of the gem binscript should check if the executable is a script and use env instead? I am not sure what the best solution is.

Note: JRuby also has a gem jruby-launcher that when installed replaces the jruby bash script with a native binary. This executable can be put in the shebang line.

I will abide by the code of conduct.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated bin/gem binscript and reproduce the failure on Darwin using the reported gem list bundler command with JRuby. Compare behavior when jruby is the default bash script versus the native jruby-launcher; done means the installed gem binscript no longer runs Ruby code under bash.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.