JRuby installation failing unless sudo with “undef

2019-09-14 22:38发布

UPDATE: everything works when I use sudo (e.g. sudo rbenv install jruby-9.1.2.0). But I don't want that :).

$ ruby -v
NameError: undefined local variable or method `v' for main:Object
<top> at -v:1

$ sudo ruby -v
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f Java HotSpot(TM) 64-Bit Server VM 25.51-b03 on 1.8.0_51-b16 +jit [darwin-x86_64]

Looking for hints on where to look for what thing(s) are requiring sudo during the installation. C Ruby installs/runs just fine without sudo.


Trying to install JRuby but getting issue where -r flag is interpreted as a variable. Similar issues when using rvm, and with JRuby 1.7.x versions. Coworkers not having any of the same issues. Was previously able to install JRuby 1.7 using rvm and rbenv and am not aware of what has changed on my system since then. Tried with JAVA_HOME set to 1.7 and 1.8 versions with the same result.

I cannot figure out what on my system is causing this to be an issue -- looking for ideas on troubleshooting before re-imaging :).

rbenv install -v jruby-9.1.2.0
/var/folders/qt/xqr8qztj5tl94l0r3l9t0pm4zbpz12/T/ruby-build.20170420180901.3389 ~
Downloading jruby-bin-9.1.2.0.tar.gz...
HTTP/1.1 200 OK
Content-Type: binary/octet-stream
Content-Length: 32578117
Connection: keep-alive
Date: Thu, 20 Apr 2017 18:41:50 GMT
Last-Modified: Fri, 27 May 2016 22:23:15 GMT
ETag: "749bb917dde9666e365e12bbe776a5c2"
Accept-Ranges: bytes
Server: AmazonS3
Age: 16032
X-Cache: Hit from cloudfront
Via: 1.1 0b1b12cfcb11f71988a190f16ef65179.cloudfront.net (CloudFront)
X-Amz-Cf-Id: mKmI9h4xs22ajaNTInTyIeqrnwQw1XHOJzcbKc--yknq4CUOu3XUmg==

-> https://dqw8nmjcqpjn7.cloudfront.net/60598a465883ab4c933f805de4a7f280052bddc793b95735465619c03ca43f35
/var/folders/qt/xqr8qztj5tl94l0r3l9t0pm4zbpz12/T/ruby-build.20170420180901.3389/jruby-9.1.2.0 /var/folders/qt/xqr8qztj5tl94l0r3l9t0pm4zbpz12/T/ruby-build.20170420180901.3389 ~
Installing jruby-9.1.2.0...
Building native extensions.  This could take a while...
ERROR:  Error installing jruby-launcher:
  ERROR: Failed to build gem native extension.

    current directory: /Users/username/.rbenv/versions/jruby-9.1.2.0/lib/ruby/gems/shared/gems/jruby-launcher-1.1.2-java
/Users/username/.rbenv/versions/jruby-9.1.2.0/bin/jruby -r ./siteconf20170420-3455-1f44pgz.rb extconf.rb
NameError: undefined local variable or method `r' for main:Object
  <top> at -r:1

extconf failed, exit code 1

Gem files will remain installed in /Users/username/.rbenv/versions/jruby-9.1.2.0/lib/ruby/gems/shared/gems/jruby-launcher-1.1.2-java for inspection.
Results logged to /Users/username/.rbenv/versions/jruby-9.1.2.0/lib/ruby/gems/shared/extensions/universal-java-1.7/2.3.0/jruby-launcher-1.1.2-java/gem_make.out

BUILD FAILED (OS X 10.11.6 using ruby-build 20170322)

Inspect or clean up the working tree at /var/folders/qt/xqr8qztj5tl94l0r3l9t0pm4zbpz12/T/ruby-build.20170420180901.3389
Results logged to /var/folders/qt/xqr8qztj5tl94l0r3l9t0pm4zbpz12/T/ruby-build.20170420180901.3389.log

Last 10 log lines:

    current directory: /Users/username/.rbenv/versions/jruby-9.1.2.0/lib/ruby/gems/shared/gems/jruby-launcher-1.1.2-java
/Users/username/.rbenv/versions/jruby-9.1.2.0/bin/jruby -r ./siteconf20170420-3455-1f44pgz.rb extconf.rb
NameError: undefined local variable or method `r' for main:Object
  <top> at -r:1

extconf failed, exit code 1

Gem files will remain installed in /Users/username/.rbenv/versions/jruby-9.1.2.0/lib/ruby/gems/shared/gems/jruby-launcher-1.1.2-java for inspection.
Results logged to /Users/username/.rbenv/versions/jruby-9.1.2.0/lib/ruby/gems/shared/extensions/universal-java-1.7/2.3.0/jruby-launcher-1.1.2-java/gem_make.out

Here's my OS info

$ uname -a
Darwin username-mbp 15.6.0 Darwin Kernel Version 15.6.0: Fri Feb 17 10:21:18 PST 2017; root:xnu-3248.60.11.4.1~1/RELEASE_X86_64 x86_64

Also having issues with jruby-launcher, but not sure if that's just a symptom:

$ gem install jruby-launcher
ERROR:  Could not find a valid gem 'jruby-launcher' (>= 0) in any repository
ERROR:  Possible alternatives: tmux_launcher, RubyRun_CE, ass_launcher, ec2launcher, jruby-ehcache

标签: jruby
1条回答
一夜七次
2楼-- · 2019-09-14 23:12

Update: Appears using the -S option in JRUBY_OPTS is the culprit.


I unset all environment variables in my user session and made sure env exactly matched sudo env except for the following:

  • MAIL
  • LOGNAME
  • USER
  • USERNAME
  • SUDO_COMMAND
  • SUDO_USER
  • SUDO_UID
  • SUDO_GID

Then using the user without sudo I was able to install JRuby without issues.

Now, even with the exact same environment variables as when I had issues I can now install/execute JRuby at my leisure. Still no idea why that worked, or which environment variable(s) were at fault.

查看更多
登录 后发表回答