【问题标题】:How to copy a rubygem from one installation to another one如何将 ruby​​gem 从一个安装复制到另一个安装
【发布时间】:2019-10-30 22:07:06
【问题描述】:

如果我想在不使用gem 命令的情况下将已安装的 gem 从一个安装复制到另一个安装,我必须做什么?

我必须在没有 Internet 连接的服务器上安装 SQLite3。通常我可以使用 gem 文件的副本来完成:

gem install --local sqlite3-1.4.0.gem --platform ruby

但对于 SQLite3,它需要连接到 Internet 以获取库来编译一些二进制文件。安装在具有 Internet 连接的计算机上运行良好。

所以我的想法是在相同的操作系统和相同的 Ruby 版本上成功安装并复制所有相关组件,但这不起作用。

当我打电话时:

require 'sequel'
db = Sequel.sqlite

我收到了这个错误:

LoadError: The specified module could not be found
d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.1/lib/sqlite3/sqlite3_native.so 
(Sequel::AdapterNotFound)

在跟踪中是:

d:/bin/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': LoadError: 126: The specified module could not be found.   - d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.1/lib/sqlite3/sqlite3_native.so (Sequel::AdapterNotFound)
  from d:/bin/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.1/lib/sqlite3.rb:6:in `rescue in <top (required)>'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.1/lib/sqlite3.rb:2:in `<top (required)>'
  from d:/bin/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
  from d:/bin/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
  from d:/bin/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sequel-5.17.0/lib/sequel/adapters/sqlite.rb:3:in `<top (required)>'
  from d:/bin/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from d:/bin/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sequel-5.17.0/lib/sequel/database/connecting.rb:88:in `load_adapter'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sequel-5.17.0/lib/sequel/database/connecting.rb:17:in `adapter_class'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sequel-5.17.0/lib/sequel/database/connecting.rb:45:in `connect'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sequel-5.17.0/lib/sequel/core.rb:121:in `connect'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sequel-5.17.0/lib/sequel/core.rb:399:in `adapter_method'
  from d:/bin/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sequel-5.17.0/lib/sequel/core.rb:406:in `block (2 levels) in def_adapter_method'
  from _ruby_version.rb:21:in `<main>'

但文件存在:

我的错误是什么?

我使用的是 Windows Server 2016。

我在 GitHub issue 中找到了适合我的 precompiled version of SQLite3,但我想使用更新的版本。

【问题讨论】:

    标签: ruby sqlite sequel


    【解决方案1】:

    为此使用Bundler

    简而言之:

    • 在您使用的每台机器上运行 gem install bundler
    • 维护一个项目Gemfile 列出所有要求
    • 当您的 Gemfile 更改时运行 bundle install 并运行 bundle update 以更新到最新版本。这将生成 Gemfile.lock 文件。
    • 使用 bundle exec 为 ruby​​ 执行添加前缀,例如bundle exec ruby myscriptbundle exec rails c

    这是一个简短的摘要,但请阅读有关 Bundler 的更多信息。它是现代 Ruby 部署的重要组成部分。

    【讨论】:

      【解决方案2】:

      你需要使用 bundler 的package 选项。

      首先,您需要将依赖项缓存到 vendor/cache 中:

      bundle package --all --all-platforms
      

      这将在本地安装您的 Gemfile 的所有依赖项,然后将目录添加到您的源代码存储库。

      部署时确保使用bundle install --local 以使用本地版本。

      有关更多信息,请参阅documentation bundle package

      【讨论】:

      • 我试着按照你写的步骤做,我收到了Bundle complete!的消息。但我的错误仍然是一样的。 “捆绑”是否包含所有源,以编译安装的本机部分?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 2011-05-20
      • 1970-01-01
      • 2019-11-10
      • 2012-01-09
      • 1970-01-01
      相关资源
      最近更新 更多