在docker安裝Ruby!

事情總會歷經波折

docker container是以ubuntu 14.04為base image,基本是是按照ihower大大的部落格在安裝Ruby。

正當裝完Ruby,要執行

install```時,將啷!
1
2
3
4
5
6
7

ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommand

別慌張,請先試著安裝zlib1g-dev

sudo apt-get install zlib1g-dev

1
2

若是顯示已為最新版本,就表示已經安裝過了。接下來要做的就是,**到Ruby的Source Code中重新編譯zlib**,根據Ruby的安裝路徑做調整:

~/ruby-2.1.5/ext/zlib
```
執行命令

$ruby ./extconf.rb
$make
$make install

之後就照理來說能夠安裝gem了。

正當我滿心歡喜準備開始安裝gem時

Error: while executing gem (Gem::Exception)
Unable to require openssl. install openSSL and rebuilt ruby (preferred) or use non HTTPs sources

馬上詢問google大神,得知可能是因為在container當中對於rubygem website的openssl有問題(詳細原因我不太清楚),因此執行

gem source -r https://rubygems.org/        (Remove)
gem source -a http://rubygems.org/          (Read)

接著再進行gem的install就成功了!

gem install nokogiri

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2

解決安裝nokogiri的問題!