postmodern / chruby

Changes the current Ruby
MIT License
2.86k stars 190 forks source link

Could not find bundler #333

Closed jlove4m closed 8 years ago

jlove4m commented 9 years ago

Hello!

We're using chruby and ruby install. Installing to /opt/rubies.

I have two versions of ruby installed on this system:

jenkins@Jenkins:~$ chruby
    ruby-1.9.3-p547
 * ruby-2.2.1

However, when I run 'bundle install' from a directory, I get the following:

jenkins@Jenkins:~/jobs/myapp-test/workspace$ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]

jenkins@Jenkins:~/jobs/myapp-test/workspace$ env | egrep -i 'gem|ruby'
GEM_HOME=/var/lib/jenkins/.gem/ruby/2.2.1
PATH=/var/lib/jenkins/.gem/ruby/2.2.1/bin:/opt/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/bin:/opt/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
RUBY_ENGINE=ruby
GEM_ROOT=/opt/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0
GEM_PATH=/var/lib/jenkins/.gem/ruby/2.2.1:/opt/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0
RUBY_ROOT=/opt/rubies/ruby-2.2.1
RUBYOPT=
RUBY_VERSION=2.2.1

jenkins@Jenkins:~/jobs/myapp-test/workspace$ bundle install
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [] (Gem::LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
    from /usr/local/bin/bundle:22:in `<main>'

I've made sure to install rubies and gems like so:

ruby-install -i /opt/rubies/ruby-#{ruby_version} ruby #{ruby_version}
cd /opt/rubies/ruby-#{ruby_version}/bin/ && sudo ./gem install #{gem} -v '#{version}'

This always worked for us in the past, but not sure why we're having this issue on this new box. Ubuntu 14.04 Server.

The jenkins user does not have a .gemrc file, there isnt an /etc/gemrc file.

I do have chruby.sh linked in /etc/profile.d though.

Any ideas?

jlove4m commented 9 years ago

Forgot to add this - definitely where some of the weirdness is coming from Im sure!

Even when I run chruby to a new version, when I run the bug report it seems the older stuff is there, even though the output of 'env' seems to disagree

jenkins@Jenkins:~$ ./chruby_bug_report.sh

## System

    Linux Jenkins 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
    GNU bash, version 4.3.8(1)-release (x86_64-pc-linux-gnu) [/bin/bash]
    tmux 1.8 [/usr/bin/tmux]
    ruby 1.9.3p547 (2014-05-14) [x86_64-linux] [/opt/rubies/ruby-1.9.3-p547/bin/ruby]
    Bundler version 1.9.2 [/opt/rubies/ruby-1.9.3-p547/bin/bundle]
    chruby version 0.3.8 [/usr/local/bin/chruby-exec]

## Environment

    CHRUBY_VERSION=0.3.8
    SHELL=/bin/bash
    PATH=/var/lib/jenkins/.gem/ruby/1.9.3/bin:/opt/rubies/ruby-1.9.3-p547/lib/ruby/gems/1.9.1/bin:/opt/rubies/ruby-1.9.3-p547/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    HOME=/var/lib/jenkins
    RUBIES=(/opt/rubies/ruby-1.9.3-p547 /opt/rubies/ruby-2.2.1)
    RUBY_ROOT=/opt/rubies/ruby-1.9.3-p547
    RUBY_VERSION=1.9.3
    RUBY_ENGINE=ruby
    RUBY_AUTO_VERSION=
    RUBYLIB=
    RUBYOPT=
    RUBYPATH=
    RUBYSHELL=
    GEM_ROOT=/opt/rubies/ruby-1.9.3-p547/lib/ruby/gems/1.9.1
    GEM_HOME=/var/lib/jenkins/.gem/ruby/1.9.3
    GEM_PATH=/var/lib/jenkins/.gem/ruby/1.9.3:/opt/rubies/ruby-1.9.3-p547/lib/ruby/gems/1.9.1

## Hooks

    trap -- '' SIGTSTP
    trap -- '' SIGTTIN
    trap -- '' SIGTTOU

## Aliases

jenkins@Jenkins:~$ env
XDG_SESSION_ID=24
GEM_HOME=/var/lib/jenkins/.gem/ruby/2.2.1
SHELL=/bin/bash
TERM=xterm
OLDPWD=/var/lib/jenkins/jobs
USER=jenkins
MAIL=/var/mail/jenkins
PATH=/var/lib/jenkins/.gem/ruby/2.2.1/bin:/opt/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/bin:/opt/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
PWD=/var/lib/jenkins
LANG=en_US.UTF-8
RUBY_ENGINE=ruby
SHLVL=1
HOME=/var/lib/jenkins
GEM_ROOT=/opt/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0
LOGNAME=jenkins
GEM_PATH=/var/lib/jenkins/.gem/ruby/2.2.1:/opt/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0
RUBY_ROOT=/opt/rubies/ruby-2.2.1
XDG_RUNTIME_DIR=/run/user/1001
RUBYOPT=
RUBY_VERSION=2.2.1
_=/usr/bin/env
postmodern commented 9 years ago

Did you make sure bundler was installed when using ruby-2.2.1? I'm also curious how ruby-1.9.3 is being loaded for the debug script?

nikhildamle commented 9 years ago

I faced this issue today and I think I know the what is causing this. gem install bundler under ruby 1.9.3 installs bundler into ~/.gem/ruby/1.9.1/bin. Where as chruby adds ~/.gem/ruby/1.9.3/bin to the PATH environment variable.

Also under ruby 1.9.3 ruby -e 'puts Gem.user_dir' prints ~/.gem/ruby/1.9.1. I don't know how chruby does this, but I think Gem.user_dir must be checked before adding into the PATH.

postmodern commented 9 years ago

@nikhildamle could you post the output of gem env?

postmodern commented 9 years ago

@jlove4m keep in mind that the bug_report.sh script runs in a sub-shell. It could be activating a .ruby-version or a chruby 1.9 in .bashrc could be overriding the current ruby.

nikhildamle commented 9 years ago

@postmodern Here is the output

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23.2
  - RUBY VERSION: 1.9.3 (2014-11-13 patchlevel 551) [x86_64-darwin14.4.0]
  - INSTALLATION DIRECTORY: /Users/nikhil/.gem/ruby/1.9.3
  - RUBY EXECUTABLE: /Users/nikhil/.rubies/ruby-1.9.3-p551/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/nikhil/.gem/ruby/1.9.3/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-14
  - GEM PATHS:
     - /Users/nikhil/.gem/ruby/1.9.3
     - /Users/nikhil/.rubies/ruby-1.9.3-p551/lib/ruby/gems/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--user-install"
  - REMOTE SOURCES:
     - http://rubygems.org/
postmodern commented 9 years ago

@nikhildamle ok so chruby is correctly setting GEM_HOME to .gem/ruby/1.9.3. What is the output of which bundle and head -n 1 $(which bundle)?

nikhildamle commented 9 years ago

@postmodern which bundle prints bundle not found and head -n 1 "$(which bundle)" prints head: bundle not found: No such file or directory

Before chruby I had used system ruby (ruby 2.0.0) that came with the OS and had gem: --user-install set in my ~/.gemrc to install gems without sudo. Today, with ruby 2.2.2 I noticed gem install warning EXECUTABLE DIRECTORY not in the PATH environment variable. Removing --user-install from ~/.gemrc and running gem install again did not produce any warning and resolved this issue with both ruby-1.9.3 and ruby-2.2.2 when i tried.

I think what happening is with --user-install, gem install ignores GEM_HOME set by chruby and instead install gems in value returned by Gem.user_dir and executables in "#(Gem.user_dir}/bin" (Gem.user_dir returns ~/.gem/ruby/1.9.1 for ruby-1.9.3 and ~/.gem/ruby/2.2.0 for ruby-2.2.2 in my computer). But chruby only adds $GEM_HOME/bin to the PATH.

postmodern commented 9 years ago

@nikhildamle yep, chruby uses different gem dirs per-ruby. Since the gem dirs are located in ~/.gem/, --user-install is redundant. Simply remove --user-install and gem install bundler.

nikhildamle commented 9 years ago

@postmodern - Yes. Have removed --user-install. No issues since. 👍

postmodern commented 8 years ago

Going to close this since it appears resolved now.