简体   繁体   中英

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.

This is what I've tried: ruby 2.0 rails gem install error "cannot load such file -- openssl" .

When I try to do gem install rails , I get this error. Frankly it happens when I try to gem install anything.

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] . I read somewhere that any Ruby version < 2.4 isn't compatible with OpenSSL 1.1. I need Ruby > 2.4.4 to install rails.

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. I am not sure how this happened but I faced this issue after I installed 'ohmyzsh' plugin. This is again a guess and I am not 100% sure if this plugin caused this issue. So, I had to uninstall the plugin and re installed rvm and openssl package. Than, install the ruby version with openssl directory as parameter as suggested in the link you have shared.

You can also use the system installed openssl directory as well. Also try using this parameter while installing the gem '-- --with-opt-dir=/usr/local/opt/openssl'. The path should the openssl installed directory on your machine.

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. I hope this helps and please let me know if you have any further queries. Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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