【问题标题】:Setting path/gem_home in combination with 'bundler/inline', rbenv and a global ruby结合 'bundler/inline'、rbenv 和全局 ruby​​ 设置 path/gem_home
【发布时间】:2017-03-20 10:56:44
【问题描述】:

为了制作独立且可移植的 ruby​​ 脚本,我使用bundler/inline

我将此脚本配置到的服务器非常具体,它们具有 rbenv(因此我们可以回滚/使用多个 ruby​​ 版本)并且因为安装某些 gem(备份 gem)需要花费时间。我们使用全局 ruby​​ 安装。

导致非 root 用户执行带有“bundle/inline”的脚本引发错误:

Your user account isn't allowed to install to the system Rubygems.
You can cancel this installation and run:  

    bundle install --path vendor/bundle

to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to Rubygems using sudo.

遗憾的是,bundler/inline 没有选项可以将此作为参数。

所以我尝试通过设置捆绑路径来解决这个问题:bundle config path ~/.gem/ruby/2.3.0/,但这不起作用。 (我检查并正确保存了配置)

设置GEM_HOME=~/.gem/ruby/2.3.0/ 确实有效。 (对于这种情况,Ruby gems 支持两个 gem home,所以这实际上工作得很好)。唯一的问题是我需要做一些簿记以保持该环境变量与 rbenv 激活的 ruby​​ 的次要版本一致。我无法从我的 ruby​​ 脚本中设置此 ENV,我可以根据当前版本轻松计算此版本:

version_used_for_gem_home = RUBY_VERSION.gsub /\.\d+$/, '.0'
ENV['GEM_HOME'] = "/var/lib/postgresql/.gem/ruby/#{version_used_for_gem_home}/"
require 'bundler/inline'

有没有更好的解决方案,不需要我做任何簿记?我希望有一些 rbenv 钩子可以用来修改路径/gem home...

【问题讨论】:

    标签: ruby bundler rbenv


    【解决方案1】:

    我们刚刚遇到了同样的问题,我发现这可以解决问题

    require 'bundler/inline'
    require 'bundler'
    Bundler.configure # where the magic happens
    # passing true here does the install; in real scripts we
    # pass a boolean based on a --install flag.
    gemfile(true) do 
       ...gems go here...
    end
    

    您需要显式调用 Bundler.configure 以使其读取您的捆绑配置,并正确设置路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      • 1970-01-01
      • 2013-11-17
      • 2015-03-05
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      相关资源
      最近更新 更多