DEV Community

Cover image for gem install rails 幫我們做了什麼事勒?
FRedwuSong
FRedwuSong

Posted on

gem install rails 幫我們做了什麼事勒?

會有這個想法,是因為心血來潮用比較舊的 ruby 版本( 2.5.9 )來安裝 rails 6( 6.1.7 ),結果噴錯!!!!!

ERROR:  Error installing rails:
    The last version of nokogiri (>= 1.8.5) to support your Ruby & RubyGems was 1.12.5. Try installing it with `gem install nokogiri -v 1.12.5` and then running the current command again
    nokogiri requires Ruby version >= 2.7.0. The current ruby version is 2.5.0.
Enter fullscreen mode Exit fullscreen mode

完全摸不著頭緒啊,rails 6 查資料應該有支持 ruby 2.5
https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
前輩指路https://qiita.com/murata0705/items/dfa2fed6c773f925a975
相依性
當您做

gem install rails --version=6.1.7

他在安裝完 activesupport 後要裝 actionpack 前,想幫您裝 rails-html-sanitizer 預設是裝 1.6 版 (明明 >= 1.2.0 就行),但裝 rails-html-sanitizer 前必須先裝 nokogiri 預設是 nokogiri 1.15.5 ~> 1.14 但是我 ruby 的版本是 2.5.9 沒辦法裝。
所以才會有圖一的問題。
怎麼辦哪:
Image description

1. gem install nokogiri -v 1.12.5;不裝的話會預設幫您裝 -v 1.15.5。
2. gem install rails-html-sanitizer -v 1.5.0
3. gem install rails -v 6.1.7
Enter fullscreen mode Exit fullscreen mode

處理完後會遇到目前此套件的版本只支持 ruby 2.6 ERRORs;

ERROR:  Error installing rails:
    The last version of bundler (>= 1.15.0) to support your Ruby & RubyGems was 2.3.27. Try installing it with `gem install bundler -v 2.3.27` and then running the current command again
    bundler requires Ruby version >= 2.6.0. The current ruby version is 2.5.0.
Enter fullscreen mode Exit fullscreen mode

必須手動安裝他建議的版本,總共裝了這些。

gem install bundler -v 2.3.27
gem install thor -v 1.2.2
gem install mini_mime -v 1.1.2
gem install timeout -v 0.4.0
gem install net-protocol -v 0.1.2
gem install net-imap -v 0.2.2
Enter fullscreen mode Exit fullscreen mode

之後終於成功裝好了 rails 6.1.7。

至於為何有那麼多 gem 要手動裝呢? 一般不是直接

gem install rails 
Enter fullscreen mode Exit fullscreen mode


就好了嗎?
因為 rails 是用很多 gem 包起來的,以 rails 6.1 為例
https://github.com/rails/rails/blob/6-1-stable/rails.gemspec

  s.add_dependency "activesupport", version
  s.add_dependency "actionpack",    version
  s.add_dependency "actionview",    version
  s.add_dependency "activemodel",   version
  s.add_dependency "activerecord",  version
  s.add_dependency "actionmailer",  version
  s.add_dependency "activejob",     version
  s.add_dependency "actioncable",   version
  s.add_dependency "activestorage", version
  s.add_dependency "actionmailbox", version
  s.add_dependency "actiontext",    version
  s.add_dependency "railties",      version
Enter fullscreen mode Exit fullscreen mode

被包起來的 gem 也包了其他 gem 以 net-protocol 來舉例 :

gem install rails -v 6.1.7
Fetching: net-protocol-0.2.2.gem (100%)
ERROR:  Error installing rails:
    The last version of net-protocol (>= 0) to support your Ruby & RubyGems was 0.1.2. Try installing it with `gem install net-protocol -v 0.1.2` and then running the current command again
    net-protocol requires Ruby version >= 2.6.0. The current ruby version is 2.5.0.
Enter fullscreen mode Exit fullscreen mode

上面的大意是我要 Fetching: net-protocol-0.2.2.gem 裝不了; 您 ruby 版本是 2.5.0 去裝 net-protocol -v 0.1.2

gem install net-protocol -v 0.1.2
Fetching: io-wait-0.3.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed io-wait-0.3.0
Fetching: net-protocol-0.1.2.gem (100%)
Successfully installed net-protocol-0.1.2
Parsing documentation for io-wait-0.3.0
Installing ri documentation for io-wait-0.3.0
Parsing documentation for net-protocol-0.1.2
Installing ri documentation for net-protocol-0.1.2
Done installing documentation for io-wait, net-protocol after 0 seconds
2 gems installed
Enter fullscreen mode Exit fullscreen mode

Where gem start fetching

為什麼 net-protocol -v 0.1.2 可以呢?
主要是因為 net-protocol -v 0.1.2 的版本需求是 >= 2.3.0
而且,io-wait >= 0 和 timeout >= 0 都沒有特別指定的版本,再加上 mail 對於 net-imap >= 0, net-pop >= 0, net-smtp >=0 的版本也沒有要求,而上開 gem 對 net-protocol >= 0 也沒有要求,所以就慢慢手動裝他要求的版本大概就不會有什麼問題。
為什麼都預設去抓只支持 2.6 以上的版本
原因我猜是因爲預設去抓最新版,但最新版無法使用 ruby 2.5 安裝的最新的版本。(/‵口′)/~╧╧ )
thanks god !!!!!!! 不免俗地說 happy coding installing~~
編按:
https://github.com/rails/rails-html-sanitizer/releases/tag/v1.6.0

Top comments (0)