update-alternatives
Ruby Advent Calendar ã®è¨äºã§ http://blog.udzura.jp/2009/12/13/switch-your-ruby-on-ubuntu910/ã¨ããã®ããã£ãã
RVM ã¯ãããã®ã ããå©ç¨ãã¦ããç°å¢ã Ubuntu ã§ãããã®ã§ããã®æ¹æ³ã«ã¤ãã¦ã試ãã¦ã¿ããã¨ã«ããã
ãã ãåé·ãªæ¸ãã¶ããæ°ã«ãªã£ãã®ã§ãupdate-alternatives ãçæãã Ruby ã¹ã¯ãªãããä½æã
ãã®ã¹ã¯ãªãããå©ç¨ããã°ãrails ã³ãã³ããªã©æ°ãã«ã³ãã³ããå¢ããã¨ãã«ãç°¡åã«å¯¾å¿ã§ããã
1 RUBY186 = ["/usr/local/ruby/ruby-1.8.6-p383", "", 120] 2 RUBY187 = ["/usr/local/ruby/ruby-1.8.7-p174", "", 150] 3 system1 = ["/usr/", "1.8", 140] 4 system2 = ["/usr/", "1.9", 100] 5 RUBY191 = ["/usr/local/ruby/ruby-1.9.1-p376", "", 110] 6 7 commands = %w(ruby irb gem rake) 8 9 [RUBY186, RUBY187, system1, system2, RUBY191].each do |dir, suffix, priority| 10 args = commands.map do |command| 11 link = "/usr/bin/#{command}" 12 fullpathcmd = "#{File.join(dir, "bin", command)}#{suffix}" 13 if command == "ruby" then 14 "--install #{link} #{command} #{fullpathcmd} #{priority}" 15 else 16 "--slave #{link} ruby-#{command} #{fullpathcmd}" 17 end 18 end.join(" ") 19 altcmd = "sudo update-alternatives #{args}" 20 system altcmd 21 end
update-alternatives ã¯ãåãæ¿ããã®ã«ç®¡çè 権éãå¿ è¦ã¨ãªãããã ãã¦ã¼ã¶æ¨©éã§é »ç¹ã«å©ç¨ããRuby ãå¤æ´ãããã¨æãç¨éã«ã¯ãªããªãé£ãããããããªãã
update-alternatives --list ã«ãã£ã¦ãã¤ã³ã¹ãã¼ã«ããã¦ãã Ruby ãå¾ããã¨ãã§ããããããã®çµæãå©ç¨ãã¦ãã¤ã³ã¹ãã¼ã«ãã¦ãããã¹ã¦ã® Ruby ã§å®è¡ãã all-ruby ã³ãã³ãã®ä½æãªã©ãå¯è½ã¨ãªãããã ãæéãããã°åãçµã¿ããã