0

每次登录服务器时,在运行 /bin/bash 之前,我都无法运行任何 rails 命令;见下文

Last login: Mon Oct 29 16:28:07 2012 from natint3.company.com
user1@company.com [~]# 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
user1@company.com [~]# 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 <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [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:       ""


user1@company.com [~]#

在我运行 /bin/bash 之后,我有不同的行为

user1@company.com [~]# /bin/bash
user1@company.com [~]# rails -v
Rails 3.2.8
user1@company.com [~]# 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 <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [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:       ""


user1@company.com [~]#

任何人都知道发生了什么,我该如何解决这个问题?

谢谢

编辑1

这是我的 .bashrc 和 .bash_profile 文件内容

user1@company.com [~]# 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
user1@company.com [~]# 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*
user1@company.com [~]#
4

1 回答 1

2

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).

于 2012-10-30T00:11:34.140 回答