本文介绍了管理ruby gem的系统依赖性(例如mysql2和openssl)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:以下是一个悲惨的故事:我如何失去约8个小时的人生,因为不同的宝石正在寻找不存在的opensl的​​不同版本.在到这里寻求帮助并写下我尝试过的所有内容的过程中,我设法实现了可以想象到的最hacky的修复程序,在这一点上,我必须继续进行实际工作.但是由于我在下面概述的原因,该解决方案似乎完全不够.所以我在问:是否有一种适当的方法来为ruby gem指定系统依赖项?

TL;DR: Below is a tragic story of a how I lost about 8 hours of my life because different gems were looking for different versions of openssl that weren't there. In the course of coming here to beg for help and writing up everything I tried I've managed to implement the hackiest fix imaginable, at which point I have to get back on with actual work. But this solution seems totally inadequate for reasons I outline below. So I'm asking: Is there a proper way of specifying system dependencies for a ruby gem?

====我的原始问题===========

====MY ORIGINAL PROBLEM===========

我在周末使用rvm installed ruby​​ 2.6.0,由于某种原因,这触发了自制程序,将Mac上的openssl更新为openssl@1.1.我现在无法运行我的工作的Rails应用程序(运行5.1.7,ruby 2.4.0),因为出现此错误:

I rvm installed ruby 2.6.0 over the weekend and for some reason this triggered homebrew to update openssl on my Mac to openssl@1.1. I now can't run my work's Rails app (running 5.1.7, ruby 2.4.0) because I get this error:

Roberts-MBP:website-upgrade Rob$ rails t
/Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.2/lib/mysql2.rb:33:in `require': dlopen(/Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
  Reason: image not found - /Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle (LoadError)

此SO帖子中基本上描述了相同的错误:

Basically the same error is described in this SO post:

rake db:mysql2 gem发生迁移错误-库未加载:libssl.1.0.0.dylib

那里的一些解决方案建议对您的openSSL安装进行符号链接,或将文件复制到所需的位置.这对我不起作用;看来旧版本(1.0.x)和新版本(1.1)的库不兼容.

Some solutions there suggest making symlinks to your installation of openSSL, or copying the files to where it wants them to be. This doesn't work for me; it seems that libraries of the old (1.0.x) and new (1.1) versions are incompatible.

简单地卸载并重新安装mysql gem会让我遇到相同的错误.根据该帖子的另一个建议,我尝试了:

Simply uninstalling and reinstalling the mysql gem leaves me with the same error.Following another suggestion from that post, I tried:

Roberts-MBP:website-upgrade Rob$ gem install mysql2 -- with-cppflags=-I/usr/local/opt/openssl@1.1/include --with-ldflags=-L/usr/local/opt/openssl@1.1/lib
Fetching: mysql2-0.5.3.gem (100%)
Building native extensions with: 'with-cppflags=-I/usr/local/opt/openssl@1.1/include --with-ldflags=-L/usr/local/opt/openssl@1.1/lib'
This could take a while...
Successfully installed mysql2-0.5.3
Parsing documentation for mysql2-0.5.3
Installing ri documentation for mysql2-0.5.3
Done installing documentation for mysql2 after 0 seconds
1 gem installed
Roberts-MBP:website-upgrade Rob$ rails t
Could not find mysql2-0.5.2 in any of the sources
Run `bundle install` to install missing gems.

注意到mysql版本与此处不匹配,我删除了Gemfile.lock并尝试再次运行测试:

Noticing that the mysql versions don't match here, I deleted my Gemfile.lock and tried to run the tests again:

Roberts-MBP:website-upgrade Rob$ rails t
Roberts-MBP:website-upgrade Rob$ /Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `require': dlopen(/Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
  Reason: image not found - /Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle (LoadError)

想知道问题是否与捆包有关,我运行了gem uninstall mysql2,并检查它是否确实删除了目录/Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.3/.然后根据 https://bundler.io/v2.0进行尝试/man/bundle-config.1.html :

Wondering if the problem could be anything to do with bundler, I ran gem uninstall mysql2, and checked that this actually deletes the directory /Rob.rvm/gems/ruby-2.4.0/gems/mysql2-0.5.3/. Then tried, as per https://bundler.io/v2.0/man/bundle-config.1.html :

 bundle config build.mysql2 --with-cppflags=-I/usr/local/opt/openssl@1.1/include --with-ldflags=-L/usr/local/opt/openssl@1.1/lib
bundle install
bundle exec rails t

但是我仍然遇到相同的错误,这使我想知道对v.1.0的依赖是否以某种方式进行了硬编码.

But I still get the same error, which makes me wonder if this dependency on v.1.0 is hardcoded somehow.

我尝试降级openssl版本.我尝试使用自制软件执行此操作,并且只能看到新版本.我四处搜索并使用了> https://github.com/kelaberetiv/TagUI/issues/86 结果是,现在spring抱怨找不到opensl@1.1的库.

I tried downgrading the openssl version. I tried to do this with homebrew and could only see the new version. I googled around and used the script from https://github.com/kelaberetiv/TagUI/issues/86The result was that now spring complained that it can't find the library for openssl@1.1.

Roberts-MBP:website-upgrade Rob$ rails t
/Rob.rvm/gems/ruby-2.4.0/gems/spring-2.1.0/lib/spring/env.rb:3:in `require': dlopen(/Rob.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/x86_64-darwin18/digest/md5.bundle, 9): Library not loaded: /usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib (LoadError)
  Referenced from: /Rob.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/x86_64-darwin18/digest/md5.bundle

我运行brew install openssl进行重置.

====== FIX ======================================== ===

======THE FIX==========================================

但是,今天早晨,我试图重做最后一步,但是我陷入了混乱,而正是通过解开这些混乱,我才解决了问题.尝试运行brew uninstall时,我收到类似1.0.2t is already installed的消息.我更新了我的定位数据库,发现我实际上已经安装了1.0.2和@ 1.1(大概是在昨天尝试了此操作之后,但是mysql2正在查找与@ 1.1进行符号链接的目录.将符号链接更改为1.0.2,现在可以运行了我的测试.

Trying to reproduce this last step this morning, however, I got a mess, and it was in disentangling this mess that I fixed my problem. I was getting messages like 1.0.2t is already installed when I tried to run brew uninstall. I updated my locate database and found that I actually had both 1.0.2 and @1.1 installed (presumably after trying this yesterday, but mysql2 was looking in the directory symlinked against @1.1. Changing the symlink to 1.0.2, I can now run my tests.

但这太糟糕了.我无法知道在v1.1的符号链接中是否还有其他gem.感觉应该有一种系统的方法来指定gems的系统依赖性-告诉gem使用哪个版本,或者至少是一种适当的方式来同时运行多个版本,并告诉gem在哪里可以找到所需的版本.如何正确执行此操作?

But this is awful. I have no way of knowing if some other gem is going to look in that symlink for v1.1. It feels like there should be a systematic way of specifying system dependencies of gems - either telling a gem which version to use, or at least a proper way of running multiple versions concurrently and telling a gem where to find the version it needs. How can I do this properly?

编辑以回应评论:这是我的gemfile:

EDIT in response to comment: Here's my gemfile:

source 'https://rubygems.org'

ruby '2.4.0'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

gem 'rails', '~> 5.1.2'
gem 'postmark-rails', '~> 0.15.0'
gem 'mysql2'
gem 'passenger', '= 5.1.5'
gem 'jbuilder', '~> 2.5'
gem 'jquery-rails'
gem 'figaro'
gem 'fastercsv', '~> 1.5', '>= 1.5.5'
gem 'jwt'
gem 'rack-cors'
gem 'rest-client'
gem 'sentry-raven'
gem 'activerecord-session_store'
gem 'timecop'
gem 'webpacker', '~> 3.5'
gem 'write_xlsx'

gem 'pry-rails'

gem 'ddtrace'

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
  gem 'minitest', '5.10.3'
end

group :development do

  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'

  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]



推荐答案

我已经看到了这个 rvm项目中的问题,您可以在此找到更多详细信息.

I've seen this issue on rvm project where you can find more detail about this.

此步骤对我有用,我们必须等待一些正式修复.

This step works for me, we have to wait for some official fix.

  1. 通过rvm pkg安装openssl安装openssl
  2. 使用rvm reinstall 2.6.0删除并重新安装红宝石--with-openssl-dir = $ HOME/.rvm/usr
  1. Install openssl via rvm pkg install openssl
  2. Remove and reinstall rubies with rvm reinstall 2.6.0 --with-openssl-dir=$HOME/.rvm/usr

这篇关于管理ruby gem的系统依赖性(例如mysql2和openssl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:56