Capistrano rbenv未配置为使用正确的ruby:1.9.1系统ruby而不是2.2.3

时间:2017-07-07 19:21:36

标签: ruby-on-rails ruby capistrano rbenv

我正在尝试修复一个生产服务器的部署过程,该过程由于使用了错误的ruby而导致当前失败。 rbenv的目标红宝石为2.2.3。但是,服务器上的Ubuntu 14系统似乎默认为ruby 1.9.1。我希望有人在S.O.也许可以确定问题可能存在的地方。以下是完整错误:

Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as serv-deployer@server: cd '/var/local/fisbot/releases/20170707184851'; RAILS_ENV=production ./slave restart exit status: 1
cd '/var/local/fisbot/releases/20170707184851'; RAILS_ENV=production ./slave restart stdout: Nothing written
cd '/var/local/fisbot/releases/20170707184851'; RAILS_ENV=production ./slave restart stderr: /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /var/local/fisbot/releases/20170707184851/config/boot.rb:3:in `<top (required)>'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /var/local/fisbot/releases/20170707184851/config/application.rb:1:in `<top (required)>'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /var/local/fisbot/releases/20170707184851/config/environment.rb:2:in `<top (required)>'
    from ./slave:4:in `require_relative'
    from ./slave:4:in `<main>'

因此,请参阅rbenv rbenv的文档。

步骤1:检查垫片是否在我的路径中

printenv | grep PATH

PATH=/home/serv-deployer/.rbenv/shims:/home/serv-deployer/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/puppetlabs/bin

从上面PATH可以看出,垫片正确放置在路径的前面。

第2步:检查RBENV_VERSION

rbenv shell

rbenv: no shell-specific version configured

所以这里不适用于我的shell,但是根据文档,如果失败了,下一步将会执行。

第3步:检查.ruby-version

当我执行rbenv localrbenv global时,我可以看到输出为ruby 2.2.3。此外,在目标服务器上的rails应用程序中,.ruby-version的内容包含2.2.3。所以在这些方面,我应该没事。

第4步:检查~/.rbenv/versions

查看此目录显示我有2.2.3

步骤5:我执行了echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc,Ran,〜/ .rbenv / bin / rbenv init,并打开了一个新窗口。

最后,通过执行gem env我可以看到我正在使用2.2.3

    RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5.1
  - RUBY VERSION: 2.2.3 (2015-08-18 patchlevel 173) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/serv-deployer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0
  - RUBY EXECUTABLE: /home/serv-deployer/.rbenv/versions/2.2.3/bin/ruby
  - EXECUTABLE DIRECTORY: /home/serv-deployer/.rbenv/versions/2.2.3/bin
  - SPEC CACHE DIRECTORY: /home/serv-deployer/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/serv-deployer/.rbenv/versions/2.2.3/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/serv-deployer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0
     - /home/serv-deployer/.gem/ruby/2.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/serv-deployer/.rbenv/versions/2.2.3/bin
     - /home/serv-deployer/.rbenv/libexec
     - /home/serv-deployer/.rbenv/plugins/ruby-build/bin
     - /home/serv-deployer/.rbenv/shims
     - /home/serv-deployer/.rbenv/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /opt/puppetlabs/bin

我在这里遗漏了什么?一切都表明我应该运行正确的ruby,为什么命令失败?

-------------- EDIT ------------

执行rbenv versions表示我有两个ruby版本

system 2.2.3 (set by /var/local/fisbot/current/.ruby-version)

我应该,是否建议清除系统红宝石。如果我可以摆脱系统版本,那么也许我可以设置。我不知道这是否是推荐的,因为这是一个生产系统。

1 个答案:

答案 0 :(得分:0)

我不清楚问题是您在本地计算机上运行的命令以及您在服务器上运行的命令。但我认为最可能的情况是:1)您的本地计算机有rbenv但是2)您的服务器没有。在这种情况下,您的服务器不知道.ruby-version文件是什么,并且需要更新其系统Ruby以匹配您用于开发的.ruby-version