我需要在ruby中使用openssl。我该如何安装呢?我已经通过rbenv安装了ruby,并且使用的是ubuntu 12.04。
kprakasam@ubuntu:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
kprakasam@ubuntu:~$ irb
irb(main):001:0> require 'openssl'
LoadError: no such file to load -- openssl
from /home/kprakasam/.rbenv/versions/1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/kprakasam/.rbenv/versions/1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):1
from /home/kprakasam/.rbenv/versions/1.9.2-p180/bin/irb:12:in `<main>'
答案 0 :(得分:22)
答案 1 :(得分:10)
对于Mac OSX来说,这就是救了我:
RUBY_CONFIGURE_OPTS=--with-openssl-dir=<openssl install dir> rbenv install
但..如何找到 openssl install dir ?:
$ brew list openssl
/usr/local/Cellar/openssl/1.0.2d_1/bin/c_rehash
/usr/local/Cellar/openssl/1.0.2d_1/bin/openssl
...
然后 openssl install目录是:
/usr/local/Cellar/openssl/1.0.2d_1/
ruby安装命令以此结束:
RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/Cellar/openssl/1.0.2d_1/ rbenv install
答案 2 :(得分:8)
首先,安装openssl:
sudo apt-get -y install build-essential zlib1g-dev libreadline-dev libssl-dev libcurl4-openssl-dev
之后,重新编译Ruby。
注意:仅修复上述@Nebojsa的评论
答案 3 :(得分:6)
这可能会对您有所帮助:Rails: cannot load such file — openssl。
答案 4 :(得分:4)
在阅读了该问题的多个答案后,我设法使用以下命令在macOS 10.15上运行它:
brew install rbenv/tap/openssl@1.0
OPENSSL_1_0_DIR=$(brew --prefix rbenv/tap/openssl@1.0)
export CPPFLAGS=-I${OPENSSL_1_0_DIR}/include
export LDFLAGS=-L${OPENSSL_1_0_DIR}/lib
ruby-install ruby 2.2.10 -- --with-openssl-dir=${OPENSSL_1_0_DIR}