简体   繁体   English

如何修复服务器上 Sinatra 损坏的依赖项

[英]How to fix broken dependencies for Sinatra on server

I had a Sinatra project running with Ruby v2.4.3.我有一个使用 Ruby v2.4.3 运行的 Sinatra 项目。

Using rbenv, I updated the Ruby version on my machine to 2.6.1 and modified the Gemfile of the project, specifying the new version.使用 rbenv,我将机器上的 Ruby 版本更新为 2.6.1 并修改了项目的 Gemfile,指定了新版本。

Here's the update Gemfile:这是更新的 Gemfile:

source "https://rubygems.org"

ruby '2.6.1'
gem 'sinatra', '1.4.6'
gem 'ralyxa'
gem 'alexa_verifier'
gem 'activesupport'
gem 'pg'
gem 'rake'
gem 'sinatra-activerecord'
gem 'openssl'

group :production do
  gem "puma"
end

Now, when I launch the server with ruby server.rb , I get several error messages:现在,当我使用ruby server.rb启动服务器时,我收到几条错误消息:

2: from server.rb:2:in `<main>'
    1: from /Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- sinatra/activerecord (LoadError)

/Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:103:in `require': dlopen(/Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/pg-1.2.2/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
  Referenced from: /usr/local/opt/postgresql/lib/libpq.5.dylib
  Reason: image not found - /Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/pg-1.2.2/lib/pg_ext.bundle
/Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:103:in `require': Error loading the 'postgresql' Active Record adapter. Missing a gem it depends on? dlopen(/Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/pg-1.2.2/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
  Referenced from: /usr/local/opt/postgresql/lib/libpq.5.dylib
  Reason: image not found - /Users/vimbro/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/pg-1.2.2/lib/pg_ext.bundle

I tried downgrading the Ruby version, removed and reinstalled OpenSSL, updated all gems manually, but nothing worked.我尝试降级 Ruby 版本,删除并重新安装 OpenSSL,手动更新所有 gem,但没有任何效果。

Aha, I have run into this recently too.啊哈,我最近也遇到了这个。 It happened because the version of OpenSSL distributed with Homebrew has been updated to 1.1.发生这种情况是因为随 Homebrew 分发的 OpenSSL 版本已更新到 1.1。 I suspect that your 2.6.1 gems were built before, perhaps on another project, using the old version of OpenSSL hence the message我怀疑你的 2.6.1 gem 是以前构建的,也许是在另一个项目上,使用旧版本的 OpenSSL 因此消息

Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)`

You should be able to reinstall the gem using:您应该能够使用以下方法重新安装 gem:

gem uninstall pg_ext

If you have multiple versions then you should remove them all then run:如果你有多个版本,那么你应该将它们全部删除然后运行:

bundle install

and, fingers crossed, you should be good to go.祝你好运,你应该可以开始了。

However, I also found that for some gems this still didn't work, perhaps because they had specified the version of OpenSSL to use.但是,我还发现对于某些 gem,这仍然不起作用,可能是因为它们指定了要使用的 OpenSSL 版本。 If the problem still persists you can still get to the old version of OpenSSL.如果问题仍然存在,您仍然可以使用旧版本的 OpenSSL。 This is a little drastic, but is probably OK for running things on your own local/dev environment - You have been warned.这有点过激,但对于在您自己的本地/开发环境中运行东西可能没问题——您已被警告过。

brew uninstall openssl
brew uninstall openssl
brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb

Yes, run the uninstall twice.是的,运行卸载两次。

As per a comment below, this helped when running an older version of Ruby that was compiled with the older version of OpenSSL.根据下面的评论,这有助于运行使用旧版 OpenSSL 编译的旧版 Ruby。 With newer Rubies I simply had to reinstall them which picked up the newer version of OpenSSL and then everything else worked.使用较新的 Rubies,我只需重新安装它们即可选择较新版本的 OpenSSL,然后其他一切正常。 Reinstall the gems too.也重新安装宝石。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM