Missing files (or seemingly so)

I have been in and out of jRuby over the past couple of years and I got
around to installing jRuby 1.7.16 on my IBM i (Power 6) box. It is
running Java 6 using the J9 JDK. Installation went fine, smoother than
usual.

But when I tried to run rails commands. I got a series of Errno::ENOENT
on various files. The first was a ENOENT on
‘/home/PETE/.gem/jruby/1.9’. I found a post that indicated adding that
path would fix the issue as a workaround (and it did). When I ran
rails new /Path_to_App it seemed like the failures were due to an
environment issue because it was looking for rails in /home/pete/bin,
/usr/bin, /usr/local/bin although none of those folders were on the path
(and I couldn’t figure out why it would look for rails there anyway).
My jruby/bin folder was on the path so I was mystified as to why it
looked elsewhere for rails. Again, a work around was to copy rails
where it seemed to be looking (for whatever reason).

Here is what I see when I try to run rails:

rails new /RailsApps/NewDemo

Errno::ENOENT: ENOENT - /home/pete/bin/rails

         file? at org/jruby/RubyFileTest.java:131

find_executable at
/usr/local/jruby-1.7.16/lib/ruby/gems/shared/gems/railties-4.1.6/lib/rails/app_rails_loader.rb:58

          find at org/jruby/RubyEnumerable.java:592

find_executable at
/usr/local/jruby-1.7.16/lib/ruby/gems/shared/gems/railties-4.1.6/lib/rails/app_rails_loader.rb:58

exec_app_rails at

/usr/local/jruby-1.7.16/lib/ruby/gems/shared/gems/railties-4.1.6/lib/rails/app_rails_loader.rb:33

          loop at org/jruby/RubyKernel.java:1501

exec_app_rails at

/usr/local/jruby-1.7.16/lib/ruby/gems/shared/gems/railties-4.1.6/lib/rails/app_rails_loader.rb:32

        (root) at

/usr/local/jruby-1.7.16/lib/ruby/gems/shared/gems/railties-4.1.6/lib/rails/cli.rb:5

       require at org/jruby/RubyKernel.java:1065

        (root) at

/usr/local/jruby-1.7.16/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1

       require at

/usr/local/jruby-1.7.16/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55

          load at org/jruby/RubyKernel.java:1081

        (root) at /usr/local/jruby-1.7.16/bin/rails:23

Rather than just keep chasing these issues, perhaps someone can suggest
what the root cause of the problem is. I can’t seem to find anything
that points to a specific configuration step I missed. Any help would
be appreciated.


Pete H.
www.petesworkshop.com
GIAC Secure Software Programmer-Java

Pete -

Since the rails command is part of a gem (the Rails gem), wouldn’t it be
in
the gem bin directory? (I use rvm and it handles path stuff
automatically
for me.)

Where are your gems being installed? You should probably have a
GEM_HOME
environment variable pointing to the root of your gem directory tree.
There should be a bin subdirectory there somewhere, and that needs to be
in
your PATH environment variable AFAIK.

  • Keith

Thanks Keith…

Where should the GEM_HOME environment variable point? I have a boatload
of gems in /usr/local/jruby-1.7.16/lib/ruby/gems/shared/gems. Is that
where it should point?

Pete

Pete -

I’m not sure…the “shared” in the directory name makes it sound like
there
could be more than one directory. And I suspect you should go one
directory
up, because gems is the name of one of several subdirectories GEM_HOME
should have.

When I do a directory of my GEM_HOME I get this:

➜ ~GEM_HOME ls
bin cache environment gems wrappers
build_info doc extensions specifications

Is that something like the directory you mentioned?

One way I figure out where it is is to install a random gem (e.g. my
“trick_bag” gem) that I don’t yet have (check with “gem list”), and see
if
it was installed in that directory

  • Keith

Nothing like that. I still think there is something messed up in the
path or home folder. Can’t quite figure out what is out of place.
There IS a ruby installation as well and I am trying to figure out if
that is what is causing the issue. Neither install is working at the
moment (ruby or jruby).

Thanks for trying!

Pete

How exactly did you install jruby.

I recommend you use rvm, rbenv, or chruby.

Clearly something went wrong with your installation and your environment
got screwed up. I have used jruby complete before with some scripts
and
some environment manipulation before but that’s kind of an involved
process
and you are much better off using one of the above mentioned projects.

Tim,

I’ll check that out. This is on an IBM i which is a bit different from
any other mainline OS. Anything that executes java is A-OK because the
J9 JVM that IBM has is rock solid on this platform but if we are talking
about any executable binaries, then things get interesting. Most of
what I run I run in an environment called PASE which is an AIX-like
shell that can execute most binaries that can run in AIX. Sometimes I
have to compile to run in PASE (PPC64) so it will vary based on what the
binary does. Because of those unknowns, sticking with a “pure” java
install: Unzip, set path and classpath, and go, is the way I deploy
most applications in the java world.

But, I’ll give it a whirl…

Pete H.
www.petesworkshop.com
GIAC Secure Software Programmer-Java

In that case you need to write shell scripts to invoke your jruby
complete
gem. I normally put these scripts in the project directory so each
project is completely isolated from the general environment and each can
have it’s own jruby complete. I install my gems into ./vendor/bundle.
Any
binstubs you create will try to reference an executable called ‘jruby’
so
they will work fine. Give it a shot and let me know how it works.

First you need to set up jruby complete. Here is a shell script to do
that. This will download the jar and install bundler into it.


#!/bin/sh
set -ex
version=1.7.8
jar=jruby-complete-$version-with-bundler.jar
curl -o $jar
http://jruby.org.s3.amazonaws.com/downloads/$version/jruby-complete-$version.jar
java -jar $jar -S gem install -i ./bundler-gems bundler --no-rdoc
–no-ri
java -jar $jar -S gem install -i ./bundler-gems rake --no-rdoc --no-ri
jar uf $jar -C bundler-gems .
java -jar $jar -S bundle --version

Now you need some scripts to invoke the jar. This one is called “jruby”.

#!/bin/bash
JRUBY_VERSION=“1.7.8”
RAILS_ENV=${RAILS_ENV:=‘development’}
BASEDIR=“$( cd “$( dirname “$0” )” && pwd )”
RAILS_DIR=“$( cd ${BASEDIR}/… && pwd)”
JRUBY_DIR=“${RAILS_DIR}/jruby”
JAVA_OPTS=“-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none
-Xmx500m -Xss2048k -Xcompile.invokedynamic=false
-Djruby.launch.inproc=false -Dcompat.version=2.0 -Dcext.enabled=false
-Djruby.compile.mode=OFF”
JAVA=“which java ${JAVA_OPTS}”
JRUBY_COMPLETE_WITH_BUNDLER_JAR=“${JRUBY_DIR}/jruby-complete-${JRUBY_VERSION}-with-bundler.jar”
JRUBY=“${JAVA} -jar ${JRUBY_COMPLETE_WITH_BUNDLER_JAR}”
${JRUBY} $*


You will also want to create scripts for “bundle” and “rake”

My bundle script looks like this

— bundle —
#!/bin/bash
BASEDIR=“$( cd “$( dirname “$0” )” && pwd )”
${BASEDIR}/jruby -S bundle $*

– rake

#!/bin/bash
BASEDIR=“$( cd “$( dirname “$0” )” && pwd )”
${BASEDIR}/jruby -S bundle exec rake $*

I also create one called "be " which comes in handy

----be
#!/bin/bash
BASEDIR=“$( cd “$( dirname “$0” )” && pwd )”
${BASEDIR}/jruby -S bundle exec $*

Last thing you need to so is to set all your paths this is my script for
that. This ones fires off a new bash where the paths of your app come
first.


#!/bin/bash

am_I_sourced()
{
if [ “${FUNCNAME[1]}” = source ]; then
return 0
else
return 1
fi
}

Highlights the current git branch

function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo “(”${ref#refs/heads/}“)”
}

pwd=${PWD##}
GEM_LOCATION=“${pwd}/vendor/bundle”
export GS_NAME=$(basename ${PWD##/})
export GEM_HOME=${GEM_LOCATION}
export GEM_PATH=“${GEM_HOME}:${GEM_PATH}”
export PATH=“./bin:vendor/bundle/bin:./jruby:${PATH}”

##colors
RED=‘[\033[0;31m]’
GREEN=‘[\033[0;32m]’
YELLOW=‘[\033[1;33m]’
DEFAULT=‘[\033[00m]’

if ! am_I_sourced -v ; then
export PS1="[\e]0;\u@\h: \w\a]$GREEN\w$YELLOW
$(parse_git_branch)$DEFAULT (${GS_NAME} isolated) quot;
bash
fi

I’ll give this a try but I am going to post this last piece of info in
hopes that it might trigger some “Aha!” for someone because this seems
very much like a path/profile issue:

I ran juby -v to display the version info. Then I changed to my
RailsApps folder and ran rails new. Here is what I see:

jruby -v
jruby 1.7.16 (1.9.3p392) 2014-09-25 575b395 on IBM J9 VM
jvmap3260_26sr8fp1-20140706_022.6 +jit [OS/400-PowerPC]
$
cd /RailsApps
$
jruby -S rails new NewDemo
Errno::ENOENT: ENOENT - /RailsApps/bin/rails

What I don’t get is why it is looking for rails at
/RailsApps/bin/rails? That seems strange. The PATH is:

echo $PATH
/usr/bin:/usr/local/jruby-1.7.16/bin:/QOpenSys/usr/bin

which rails returns:
which rails
/usr/local/jruby-1.7.16/bin/rails

Something just doesn’t add up (for me at least)

Pete

Pete -

What happens when you omit the jruby -S and just call rails new NewDemo?

  • Keith

I think the pure Java approach of my scripts would probably work best
for
you. As I said I do that per project but a slight modification or two
would enable to you set up a shared gem path as well.

So…I think I have sorted this out. This seems to be a case of red
herrings, lack of understanding of the environment and some stupid moves
on my part to get things “working”. Scrolling back a minute, I have had
several issues over the years getting JRuby installed and operational.
There was a sweet spot for a while where I had no trouble installing and
then had several releases that no matter what I did I couldn’t get
things to work. I chalked that up to running under the IBM J9 JVM and
really didn’t have time to run down the issues. This time, however, I
wanted to get it sorted out.

The problem was that I had a ruby install as well and had copied some
binaries around trying to get that installation to work (any port in a
storm). But that didn’t help and it turned out to complicate my efforts
to sort out my JRuby issues as well. I had rails, bundle and a couple
of other binaries in a folder higher up in the path (/usr/bin) which I
shouldn’t have copied there but at least should have remembered.

Once I scrubbed the folders in the path, I installed JRuby 1.7.15 (one
release back) and re-installed rails and managed to get a new rails app
up and running. The JRuby “install” was simply unzipping the jruby
folder and putting that folder in the path. That did it. I had a
problem with tzinfo that I solved by installing the tzinfo gem but the
rails app started up. I am out of the woods.

So thanks for the ideas and the scripts. I am going to stick with what
I have for the time being but the scripts are helpful and I am going to
save them for future reference.

Pete