新手问题 安装 Rails 出现 cannot load such file -- openssl

a4652097 · 2020年05月17日 · 最后由 501225658 回复于 2020年05月21日 · 5563 次阅读

ruby 版本是 2.3.0,mac os x 是 10.13.6

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin17]

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

执行 gem install rails -v 3.2.16,安装 rails 出现 openssl 问题, 参考了一下https://ruby-china.org/topics/8966的解决方案, 尝试安装 openssl

$ brew install openssl
Warning: [email protected] 1.1.1g is already installed and up-to-date
To reinstall 1.1.1g, run `brew reinstall [email protected]`

已经是最新的 openssl,继续尝试 rvm pkg install openssl 给出如下错误

$ brew install openssl
Beware, 'rvm pkg ...' is deprecated, read about the new autolibs feature: 'rvm help autolibs'.

Checking requirements for osx.
Certificates bundle '/usr/local/etc/[email protected]/cert.pem' is already up to date.
Requirements installation successful.
Fetching openssl-1.0.1i.tar.gz to /Users/alan/.rvm/archives
Extracting openssl to /Users/alan/.rvm/src/openssl-1.0.1i.....
Configuring openssl in /Users/alan/.rvm/src/openssl-1.0.1i.....................-
Compiling openssl in /Users/alan/.rvm/src/openssl-1.0.1i.......................|
Installing openssl to /Users/alan/.rvm/usr.....................................-
Error running '__rvm_make install',
please read /Users/alan/.rvm/log/1589712289/openssl_make.install.log

Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

Updating openssl certificates.......

继续尝试 rvm reinstall all 命令后还是错误,请问这个是什么问题?

也尝试过重新安装 ruby,出现

Error running 'env GEM_HOME=/Users/alan/.rvm/gems/ruby-2.3.0@global GEM_PATH= /Users/alan/.rvm/rubies/ruby-2.3.0/bin/ruby -d /Users/alan/.rvm/src/rubygems-3.0.8/setup.rb --no-document',
please read /Users/alan/.rvm/log/1589713192_ruby-2.3.0/rubygems.install.log

既然 openssl 已经安装了,可以尝试一下:

rvm reinstall 2.3.0 --with-openssl-dir=`brew --prefix openssl`

楼上已经有答案了,这是我当时遇到这个问题记录的解决过程~~

cool_i 回复
$ rvm reinstall 2.3.0 --with-openssl-dir=`brew --prefix openssl`

Error running 'env GEM_HOME=/Users/alan/.rvm/gems/ruby-2.3.0@global GEM_PATH= /Users/alan/.rvm/rubies/ruby-2.3.0/bin/ruby -d /Users/alan/.rvm/src/rubygems-3.0.8/setup.rb --no-document',
please read /Users/alan/.rvm/log/1589781619_ruby-2.3.0/rubygems.install.log

查看 rubygems.install.log

Exception `LoadError' at /Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems.rb:1241 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems.rb:1250 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- did_you_mean
/Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- openssl (LoadError)
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/specification.rb:2481:in `to_ruby'
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/commands/setup_command.rb:405:in `install_default_bundler_gem'
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/commands/setup_command.rb:167:in `execute'
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/command.rb:321:in `invoke_with_build_args'
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/command_manager.rb:184:in `process_args'
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/command_manager.rb:148:in `run'
    from /Users/alan/.rvm/src/rubygems-3.0.8/lib/rubygems/gem_runner.rb:59:in `run'
    from setup.rb:41:in `<main>'

To link Rubies to Homebrew's OpenSSL 1.1 (which is upgraded) add the following to your ~/.zshrc: export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"

Note: this may interfere with building old versions of Ruby (e.g <2.4) that use OpenSSL <1.1.

ruby2.4 以前需要安装 openssl 1.1 以下的版本。你安装 openssl 1.0.2,然后 --with-openssl-dir=1.0.2 的目录就可以了。

zhuoerri rails 框架装不上 提及了此话题。 05月25日 20:35
a4652097 关闭了讨论。 05月28日 20:33
需要 登录 后方可回复, 如果你还没有账号请 注册新账号