简体   繁体   English

MacOS:尝试安装 Rails 时出现 Ruby LoadError

[英]MacOS: Ruby LoadError when trying to install Rails

I've already tried Googling everything;我已经尝试过用谷歌搜索所有内容; don't just point me towards the first few results you get when Google searching the same error.不要只指出我在 Google 搜索相同错误时获得的前几个结果。

This is what I've tried: ruby 2.0 rails gem install error "cannot load such file -- openssl" .这是我尝试过的: ruby 2.0 rails gem install error "cannot load such file -- openssl"

When I try to do gem install rails , I get this error.当我尝试执行gem install rails时,出现此错误。 Frankly it happens when I try to gem install anything.坦率地说,当我尝试gem install任何东西时就会发生这种情况。

ERROR:  Loading command: install (LoadError)
        cannot load such file -- openssl
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

Also, I should have Ruby 2.7.1 installed (I've installed it multiple times with brew , rbenv , and rvm ), but when I do ruby -v it always returns ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18] . Also, I should have Ruby 2.7.1 installed (I've installed it multiple times with brew , rbenv , and rvm ), but when I do ruby -v it always returns ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18] I read somewhere that any Ruby version < 2.4 isn't compatible with OpenSSL 1.1.我在某处读到任何 Ruby 版本 < 2.4 与 OpenSSL 1.1 不兼容。 I need Ruby > 2.4.4 to install rails.我需要 Ruby > 2.4.4 来安装导轨。

Here's my gem env这是我的宝石环境

[14:21:23] jasper.huang ruby-2.7.1 gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.1.2
  - RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-darwin18]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.7.0
  - USER INSTALLATION DIRECTORY: /Users/jasper.huang/.gem/ruby/2.7.0
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /Users/jasper.huang/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-18
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/2.7.0
     - /Users/jasper.huang/.gem/ruby/2.7.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/jasper.huang/Documents/School/USC/SPRING20/CSCI310/Project2/google-cloud-sdk/bin
     - /Library/Frameworks/Python.framework/Versions/3.7/bin
     - /usr/local/CrossPack-AVR/bin
     - /Library/Frameworks/Python.framework/Versions/3.5/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/share/dotnet
     - /opt/X11/bin
     - ~/.dotnet/tools
     - /Library/Frameworks/Mono.framework/Versions/Current/Commands
     - /usr/local/CrossPack-AVR/bin
     - /Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin
     - /Users/jasper.huang/.rvm/bin

I recently faced this issue and the problem was that ruby command was using core default ruby installation (ie 2.3) instead of rvm ruby version.我最近遇到了这个问题,问题是 ruby 命令使用核心默认 ruby 安装(即 2.3)而不是 rvm ruby 版本。 I am not sure how this happened but I faced this issue after I installed 'ohmyzsh' plugin.我不确定这是怎么发生的,但我在安装“ohmyzsh”插件后遇到了这个问题。 This is again a guess and I am not 100% sure if this plugin caused this issue.这又是一个猜测,我不能 100% 确定这个插件是否导致了这个问题。 So, I had to uninstall the plugin and re installed rvm and openssl package.所以,我不得不卸载插件并重新安装 rvm 和 openssl package。 Than, install the ruby version with openssl directory as parameter as suggested in the link you have shared.然后,按照您共享的链接中的建议,安装 ruby 版本,其中 openssl 目录作为参数。

You can also use the system installed openssl directory as well.您也可以使用系统安装的 openssl 目录为好。 Also try using this parameter while installing the gem '-- --with-opt-dir=/usr/local/opt/openssl'.在安装 gem '-- --with-opt-dir=/usr/local/opt/openssl' 时也可以尝试使用这个参数。 The path should the openssl installed directory on your machine.该路径应为您机器上的 openssl 安装目录。

You need to make sure that you have rvm and ruby is installed and working fine by checking the ruby installed in rvm is activated in your machine.您需要通过检查安装在 rvm 中的 ruby 是否已在您的机器中激活来确保您有 rvm 并且 ruby 已安装并且工作正常。 I hope this helps and please let me know if you have any further queries.我希望这会有所帮助,如果您有任何进一步的疑问,请告诉我。 Thank you.谢谢你。

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

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