1

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
Jasper Huang
  • 501
  • 2
  • 7
  • 15
  • At the risk of asking obvious questions, what ruby version are you attempting to use here? What happens when you run 'rvm list'? If 2.7.1 is not selected use that with 'rvm use 2.7.1' and run 'gem install rails' again? Do you have libssl-dev? – benjessop Jul 19 '20 at 14:14
  • 1
    Remove RVM, remove rbenv, remove your brew installed version of Ruby, then pick **one** method of installing Ruby and stick with it. You're way down a rabbit hole right now; make your life way easier by choosing one method and troubleshooting it. – anothermh Jul 19 '20 at 18:06

1 Answers1

0

I recently faced this issue and the problem was that ruby command was using core default ruby installation (i.e 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.

Deepak
  • 138
  • 1
  • 10