2012-06-20 126 views
16

我需要在ruby中使用openssl。我應該如何安裝?我已經通過rbenv安裝了ruby,並且正在使用Ubuntu 12.04。在ruby/rbenv中安裝openssl

[email protected]:~$ ruby -v 
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux] 

[email protected]:~$ 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

我認爲你必須編譯OpenSSL的 –

+3

'sudo易於得到-y構建紅寶石 - 必須安裝zlib1g-dev libreadline-dev libssl-dev libcurl4-openssl-dev',而不是使用rbenv再次安裝ruby,並且您將擁有openssl支持 – Nebojsa

回答

21

openssl需要安裝在您的本地機器上。

然後您需要使用openssl支持編譯Ruby,這是通過--with-openssl-dir命令行開關實現的。

也許this會幫助你。

7

首先,安裝OpenSSL:已

sudo apt-get -y install build-essential zlib1g-dev libreadline-dev libssl-dev libcurl4-openssl-dev 

之後,重新編譯紅寶石。

注意:只有固定的評論從@Nebojsa上述

+0

從源碼安裝ruby-2.0.0-p451到Ubuntu-Saucy 13.10時,這對我有用。 –

7

對於Mac OSX這就是救了我:

RUBY_CONFIGURE_OPTS=--with-openssl-dir=<openssl install dir> rbenv install 

Ruby build 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_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/Cellar/openssl/1.0.2d_1/ rbenv install