Tmux会话中错误的ruby可执行路径

时间:2013-05-23 07:00:08

标签: ruby macos rvm tmux

我使用ruby 2.0安装了rvm。我是tmux的新手。

我在使用此配置的.tmux.conf中使用zsh

set-option -g default-shell /bin/zsh 
set-option -g default-command "/bin/zsh -i"

我也在.zshrc

中加载了rvm路径
source /Users/mgpyone/.rvm/scripts/rvm

现在,当我在tmux会话中尝试时,这些是配置。

which ruby/Users/mgpyone/.rvm/rubies/ruby-2.0.0-p0/bin/ruby

where ruby返回

/Users/mgpyone/.rvm/rubies/ruby-2.0.0-p0/bin/ruby 
/Users/mgpyone/.rvm/bin/ruby 
/Users/mgpyone/.rvm/bin/ruby

但为什么gem env显示我的Ruby executable路径设置为系统路径而不是rvm

RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 2.0.0 (2013-02-24 patchlevel 0) [x86_64-darwin12.3.0]
  - INSTALLATION DIRECTORY: /Users/mgpyone/.rvm/gems/ruby-2.0.0-p0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/mgpyone/.rvm/gems/ruby-2.0.0-p0/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-12
  - GEM PATHS:
     - /Users/mgpyone/.rvm/gems/ruby-2.0.0-p0
     - /Users/mgpyone/.rvm/gems/ruby-2.0.0-p0@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :benchmark => false
     - :sources => ["https://rubygems.org"]
  - REMOTE SOURCES:
     - https://rubygems.org

我无法运行rake之类的东西,因为我认为它已经用System Ruby执行了。

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby app.rb -s puma
app.rb:1:in `require': no such file to load -- sinatra (LoadError)
        from app.rb:1
        rake aborted!
        Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]
        /Users/mgpyone/work/rb/fileserver/Rakefile:9
        (See full trace by running task with --trace)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

启动tmux时,很可能设置了$ GEM_HOME或$ GEM_PATH。使用tmux继承这些环境变量时,无论rvm设置如何,其下包含的每个shell都会受到这些设置的影响。

检查tmux showenv -g GEM_HOME(或GEM_PATH)