Wednesday, 31 October 2012

OS X jruby 1.7.0 "require: command not found"

Had tons of trouble with this.
I have rvm and "raw" installs of ruby and jruby.
I do this so I can simulate a live environment.
Our servers don't allow rvm installs, but I like to use it to test stuff.
So I have to have an install of jruby like this:

bandit:~ kim$ ls -l /opt
lrwxr-xr-x   1 kim     admin    11 30 Oct 23:00 jruby@ -> jruby-1.7.0
drwxr-xr-x   9 kim     admin   306 30 Oct 22:59 jruby-1.7.0/
drwxr-xr-x   9 kim     admin   306 11 Oct 15:43 jruby-1.7.0.RC2/

This allows me to switch back and forth.
The problem arises when you have your path pointing at /opt/jruby/bin and install rails.
When you verify all paths:

bandit:~ kim$ which jruby
bandit:~ kim$ which rails
bandit:~ kim$ rails -v
/opt/jruby-1.7.0/bin/rails: line 10: require: command not found
/opt/jruby-1.7.0/bin/rails: line 12: version: command not found
/opt/jruby-1.7.0/bin/rails: line 16: syntax error near unexpected token `('
/opt/jruby-1.7.0/bin/rails: line 16: `  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding'

Which is a pain in the ass.

The issue is sort of to do with the environment.
I was first was led down several garden paths regarding interference from rvm.
That's not the case.
At the top of the /opt/jruby-1.7.0/bin/rails script is this:


What happens is that the jruby script has this at the top:

#!/usr/bin/env bash

This starts a new bash with virtually no included stuff.
You can try it yourself by doing "env bash" and when the shell starts, poke around in the path.

And that's the problem.
OS-X has an primitive install of ruby, rails etc.
You can check it yourself.
Just do a "ls -l /usr/bin/r*".
You'll see rails, rake and so on.

So how do you fix this?
Simple. Change the line at the top of the /opt/jruby-1.7.0/bin/rails script to this:

#!/usr/bin/env jruby

Just leave the old line in for reference.

bandit:~ kim$ rails -v
Rails 3.2.8


Caveat: You'll have other issues with rake et al.

No comments:

Post a Comment