本文介绍了除非sudo使用“未定义的局部变量或main:Object的方法'r'",否则JRuby安装将失败.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:当我使用sudo(例如sudo rbenv install jruby-9.1.2.0)时,一切正常.但我不想要那:).

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]

在安装过程中寻找有关在哪里寻找需要sudo的内容的提示.无需sudo,C Ruby的安装/运行就很好.

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.

尝试安装JRuby,但出现问题,其中-r标志被解释为变量.在使用rvm以及JRuby 1.7.x版本时,存在类似的问题.同事没有任何相同的问题.以前能够使用rvm和rbenv来安装JRuby 1.7,但是从那时起我就不知道系统上发生了什么变化.尝试将JAVA_HOME设置为1.7和1.8版本,结果相同.

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

这是我的操作系统信息

$ 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

jruby-launcher也有问题,但不确定是否只是症状:

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_OPTS中的-S选项.

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

我取消了用户会话中的所有环境变量,并确保envsudo env完全匹配,除了以下内容:

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

  • 邮件
  • LOGNAME
  • USER
  • USERNAME
  • SUDO_COMMAND
  • SUDO_USER
  • SUDO_UID
  • SUDO_GID

然后使用没有sudo的用户,我就可以没有问题地安装JRuby.

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

现在,即使使用与遇到问题时完全相同的环境变量,我现在也可以在闲暇时安装/执行JRuby.仍然不知道为什么这样做,或者哪​​个环境变量有问题.

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.

这篇关于除非sudo使用“未定义的局部变量或main:Object的方法'r'",否则JRuby安装将失败.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:39