我需要在 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>'
对于 Mac OSX,这拯救了我:
RUBY_CONFIGURE_OPTS=--with-openssl-dir=<openssl install dir> rbenv install
来自 Ruby 构建 wiki
但是..如何找到openssl安装目录?:
$ 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安装目录是:
/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
(和其他 Linux 发行版)
$ # Display the installation directory:
$ openssl version -d
OPENSSLDIR: "/usr/lib/ssl"
$ # May need to uninstall the previous installation:
$ rbenv uninstall 3.1.2
rbenv: remove /home/aidan/.rbenv/versions/3.1.2? [yN] Y
$ # Then reinstall (using the dir from the first step)
$ RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/lib/ssl rbenv install 3.1.2
Installing ruby-3.1.2...
Installed ruby-3.1.2 to /home/aidan/.rbenv/versions/3.1.2
首先,安装openssl:
sudo apt-get -y install build-essential zlib1g-dev libreadline-dev libssl-dev libcurl4-openssl-dev
然后,重新编译 Ruby。
注意:仅修复上面@Nebojsa 的评论
这可能对您有帮助:Rails:无法加载此类文件 - openssl。
编辑:请注意,此答案可能已过时。 相关问题已在 v0.8.1中解决。
在阅读了这个问题的多个答案后,我设法使用以下命令让它在 macOS 10.15 上运行:
brew install rbenv/tap/[email protected]
OPENSSL_1_0_DIR=$(brew --prefix rbenv/tap/[email protected])
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}
我的 M2 Mac 上通过 Brew 安装了两个版本的 openssl(1.1 和 3)。
我使用 1.1 版本的路径为
--with-openssl-dir
设置了一个环境变量。
鱼:
set -gx RUBY_CONFIGURE_OPTS "--with-openssl-dir=/opt/homebrew/opt/[email protected]"
bash/zsh:
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"
我导出后构建成功。
注意:我还为编译器导出了相应的
CPPFLAGS
和LDFLAGS
。
export LDFLAGS=-L/opt/homebrew/opt/[email protected]
export CPPFLAGS=-I/opt/homebrew/opt/[email protected]/include