安裝nokogiri gem 會遇到的問題,以及正確安裝rails 的步驟

Tien Shun Lo
Aug 26, 2017 · 5 min read

根據 Dissecting Ruby on Rails 5 — Become a Professional Developer 這門課的介紹,

正確的(建議)安裝流程(課程的教學流程)應該是:

  1. xcode
  2. git
  3. homebrew
  4. GPC Security System(好像要先安裝這個才能安裝RVM)
  5. RVM
  6. Nokogiri
  7. Rails
  8. Protgres
  9. Sublime

按照影片的教學,先安裝Nokogiri在安裝Rails才不會發生問題(?)

不過,我在安裝Nokogiri的時候,還是出現問題:

Installing nokogiri 1.6.8.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.


所以還是只能按照這一頁去做: 灌舊版本的Nokogiri

$ gem install nokogiri -v 1.6.3.1 -- --with-iconv-dir=`xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr --with-xml2-include=`xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2

新發現是這個論壇上面有寫解答:要看16樓

但是仔細去看一下官方文件,其實在Mac OS X的部分,也有講到解法:


xcode-select — install

gem install nokogiri


只要下載再安裝xcode-select(雖然我不知道這是什麼,也不知道為什麼我在灌Xcode的時候沒有安裝這個),其實就可以解決了

錯誤訊息太多了,照著做反而都弄不好,原來官方文件就有了。


另外,使用RVM的時候,

每一個gem (如Nokogiri)

在不同的版本的Ruby(如2.2.0,2.3.0 ,2.4.0)都要重新灌一次,

但是xcode-select只要安裝一次就好了。


[不負責心得]

另外一個小節(Deep Dive: Analyzing the Application Generator — Part 1 of 2),在解釋rails -h裡面的功能,有提到Srping Gem滿麻煩的,雖然不是很懂為什麼,但是真的遇到一些問題。

其實在剛開始的時候,對於ruby 跟 rails都沒有明確的概念,到現在也只能夠說可以比剛開始的時候稍微清楚一點,所以我其實不知道當初在練習的時候,用了什麼版本的ruby 和 rails。

搞的現在在練習用RVM的時候,處處卡關。

會一直出現一個GEM_PATH錯誤的訊息。

這一頁中,有一個解答看起來很仔細,但是好像沒有用:是在terminal中先輸入env,找到GEM_PATH跟GEM_HOME,然後在/profile.d/appspecific.sh(這又是啥?)輸入:

export GEM_PATH=/usr/local/rvm/gems/ruby-1.9.3-p551:/usr/local/rvm/gems/ruby-1.9.3-p551@globalexport GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p551

後來在這裡找到解答了:

原來是在bin/sprin,難怪老師說spring有點buggy

Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(File::PATH_SEPARATOR) }

好了是好了,但是因為我搞不請楚我之前到底是用哪個版本的ruby做的網站,所以要每個版本都要重複一次,所以我放棄了,就想乾脆把整個.rvm刪掉

雖然網路上有看到

rvm implode

這會移除 rvm/ 目錄下的 ruby 和 gem 文件。

gem uninstall rvm

這會移除RVM gem

可是都會出現錯誤訊息,所以我決定聽龍哥的話,

很乾脆地用Command + Shift + .來快速(在Finder 中)顯示和隱藏隱藏文件,然後把.rvm刪掉了。

可能,要做下一個網站的時候,再來研究RVM吧。

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade