繁体   English   中英

在 ruby / rbenv 中安装 openssl

[英]Installing openssl in ruby / rbenv

我需要在 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 构建维基

但是..如何找到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

openssl需要安装在你的本地机器上。

然后,您需要使用 openssl 支持编译 Ruby,这是通过--with-openssl-dir命令行开关实现的。

也许会帮助你。

首先,安装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/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}

Ubuntu

(和其他 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 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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