rh4games
rh4games

Reputation: 972

Ruby On rails : need to run /bin/bash before any rails command

every time I log into the server, I cannot run any rails command until I run /bin/bash ; see below

Last login: Mon Oct 29 16:28:07 2012 from natint3.company.com
[email protected] [~]# rails -v
/usr/lib64/ruby/site_ruby/1.8/rubygems.rb:926:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
    from /usr/lib64/ruby/site_ruby/1.8/rubygems.rb:244:in `activate_dep'
    from /usr/lib64/ruby/site_ruby/1.8/rubygems.rb:236:in `activate'
    from /usr/lib64/ruby/site_ruby/1.8/rubygems.rb:1307:in `gem'
    from /usr/bin/rails:18
[email protected] [~]# rvm info

ruby-1.9.3-p194:

system:
uname:       "Linux box726.bluehost.com 2.6.32-20120131.55.1.bh6.x86_64 #1 SMP Tue Jan 31 15:43:27 EST 2012 x86_64 x86_64 x86_64 GNU/Linux"
system:      "unknown/libc-2.12/x86_64"
bash:        "/ramdisk/bin/bash => GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)"
zsh:         "/usr/bin/zsh => zsh 4.3.10 (x86_64-redhat-linux-gnu)"

rvm:
version:      "rvm 1.16.17 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]"
updated:      "4 hours 10 minutes 5 seconds ago"

ruby:
interpreter:  "ruby"
version:      "1.9.3p194"
date:         "2012-04-20"
platform:     "x86_64-linux"
patchlevel:   "2012-04-20 revision 35410"
full_version: "ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]"

homes:
gem:          "/home3/user1/.rvm/gems/ruby-1.9.3-p194"
ruby:         "/home3/user1/.rvm/rubies/ruby-1.9.3-p194"

binaries:
ruby:         "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/ruby"
irb:          "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/irb"
gem:          "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/gem"
rake:         "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/rake"

environment:
PATH:         "/home3/user1/.rvm/gems/ruby-1.9.3-p194/bin:/home3/user1/.rvm/gems/ruby-1.9.3-p194@global/bin:/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin:/home3/user1/.rvm/bin:/usr/local/jdk/bin:/home3/user1/perl5/bin:/usr/lib64/qt-3.3/bin:/ramdisk/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/home3/user1//ruby/gems/bin:/home3/user1//ruby/gems:/home3/user1/bin"
GEM_HOME:     "/home3/user1/.rvm/gems/ruby-1.9.3-p194"
GEM_PATH:     "/home3/user1/.rvm/gems/ruby-1.9.3-p194:/home3/user1/.rvm/gems/ruby-1.9.3-p194@global"
MY_RUBY_HOME: "/home3/user1/.rvm/rubies/ruby-1.9.3-p194"
IRBRC:        "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/.irbrc"
RUBYOPT:      ""
gemset:       ""


[email protected] [~]#

and after I run /bin/bash, I have a different behavior

[email protected] [~]# /bin/bash
[email protected] [~]# rails -v
Rails 3.2.8
[email protected] [~]# rvm info

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.


system:

system:
uname:       "Linux box726.bluehost.com 2.6.32-20120131.55.1.bh6.x86_64 #1 SMP Tue Jan 31 15:43:27 EST 2012 x86_64 x86_64 x86_64 GNU/Linux"
system:      "unknown/libc-2.12/x86_64"
bash:        "/ramdisk/bin/bash => GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)"
zsh:         "/usr/bin/zsh => zsh 4.3.10 (x86_64-redhat-linux-gnu)"

rvm:
version:      "rvm 1.16.17 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]"
updated:      "4 hours 11 minutes 9 seconds ago"

homes:
gem:          "/home3/user1//ruby/gems"
ruby:         "/home3/user1/.rvm/rubies/ruby-1.9.3-p194"

binaries:
ruby:         "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/ruby"
irb:          "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/irb"
gem:          "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/gem"
rake:         "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin/rake"

environment:
PATH:         "/usr/local/jdk/bin:/home3/user1/.rvm/gems/ruby-1.9.3-p194/bin:/home3/user1/.rvm/gems/ruby-1.9.3-p194@global/bin:/home3/user1/.rvm/rubies/ruby-1.9.3-p194/bin:/home3/user1/.rvm/bin:/home3/user1/perl5/bin:/usr/lib64/qt-3.3/bin:/ramdisk/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/home3/user1//ruby/gems/bin:/home3/user1//ruby/gems:/home3/user1/bin"
GEM_HOME:     "/home3/user1//ruby/gems"
GEM_PATH:     "/home3/user1//ruby/gems:/usr/lib64/ruby/gems/1.8"
MY_RUBY_HOME: "/home3/user1/.rvm/rubies/ruby-1.9.3-p194"
IRBRC:        "/home3/user1/.rvm/rubies/ruby-1.9.3-p194/.irbrc"
RUBYOPT:      ""
gemset:       ""


[email protected] [~]#

Anyone has an idea what's going on and how can I fix this issue?

Thanks

EDIT1

Here are my .bashrc and .bash_profile file contents

[email protected] [~]# cat ~/.bashrc
# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

    export HPATH=/home3/user1/
    export GEM_HOME=$HPATH/ruby/gems
    export GEM_PATH=$GEM_HOME:/usr/lib64/ruby/gems/1.8
    export GEM_CACHE=$GEM_HOME/cache
    export PATH=$PATH:$HPATH/ruby/gems/bin
    export PATH=$PATH:$HPATH/ruby/gems  

PATH=$PATH:/home3/user1/.rvm/bin # Add RVM to PATH for scripting

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[email protected] [~]# cat ~/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME


[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
[email protected] [~]#

Upvotes: 0

Views: 2364

Answers (1)

jordanpg
jordanpg

Reputation: 6516

This looks like a path issue to me. When you run rails the first time, it's finding a global rubygems installation before your local rvm copy.

After you run /bin/bash from the command line, you are starting an interactive shell, which sources (executes) ~/.bashrc. My guess is that that contains the rvm initializations that are failing to run when you login with a login shell.

Take a look at ~/.bash_profile and ~/.bashrc. Here is what the latest RVM installer generates:

$ cat ~/.bashrc
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

$ cat ~/.bash_login 
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export NODE_PATH=/usr/local/lib/node_modules
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

If this is what you've got, then you're somehow logging in through an interactive shell and not a login shell (how???). You should be able to fix both issues with source ~/.bash_profile (.bash_login in OS X).

Upvotes: 2

Related Questions