Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ruby 環境構築 @Niigata.rb#3

82d6167c4d14393c2e20b37a74b363c5?s=47 kasacchiful
August 31, 2013
360

ruby 環境構築 @Niigata.rb#3

Niigata.rb #3 で発表した資料です。

82d6167c4d14393c2e20b37a74b363c5?s=128

kasacchiful

August 31, 2013
Tweet

Transcript

  1. ͸͡ΊͯͷRuby؀ڥߏங ּݪɹ޺ɹ( @kasacchiful ) 13೥8݄31೔౔༵೔

  2. ໨త Rubyͷ࣮ߦ؀ڥΛߏஙͯ͠Έ·͠ΐ͏ Ruby͕ಈ͔ͳ͍ͱɺษڧ΋··ͳΒͳ͍ʂ Ruby͕ಈ͔ͳ͍ͱɺศརͳRuby੡πʔϧ΋࢖ ͑ͳ͍ʂ OSผʹઆ໌͍͖ͯ͠·͢ 13೥8݄31೔౔༵೔

  3. ࣗݾ঺հ ּݪɹ޺ (@kasacchiful) ৽ׁࢢࡏॅ SIerۈ຿ ීஈ͸Macɺ࢓ࣄ͸Windows JaSST৽ׁɹ࣮ߦҕһ Ruby͕͓ؾʹೖΓ 13೥8݄31೔౔༵೔

  4. ຊ೔΍Δ͜ͱ Mac homebrew + rbenv, ruby-build Linux ( CentOS )

    rbenv, ruby-build Windows One-Click Installer bundlerʹΑΔgem؅ཧ αϯϓϧΞϓϦέʔγϣϯ࣮ߦ 13೥8݄31೔౔༵೔
  5. ࣮ߦ؀ڥߏங Macฤ 13೥8݄31೔౔༵೔

  6. ࣮ߦ؀ڥߏங (Macฤ) σϑΥϧτͰ࢖͑Δ Ruby 1.8.7 αϙʔτऴྃ ιʔείϯύΠϧ ·ͣ࢖༻͠ͳ͍ 13೥8݄31೔౔༵೔

  7. ࣮ߦ؀ڥߏங (Macฤ) rvm rbenv, ruby-build ෳ਺ͷRubyόʔδϣϯΛΠϯετʔϧɺ੾ Γସ͑Մೳ rvm͸ߴػೳɺrbenv͸γϯϓϧͱ͍͏ҹ৅ rvmͰ͸ෳ਺ͷgemϑΝΠϧΛ؅ཧՄೳ bundler͋Δ͔Βෆཁ͔΋ʢޙड़ʣ

    ͜͜Ͱ͸ɺrbenv, ruby-buildΛ࢖ͬͯߏஙͯ͠Έ·͠ΐ͏ɻ 13೥8݄31೔౔༵೔
  8. ࣮ߦ؀ڥߏங (Macฤ) ߏங؀ڥ MacOS X 10.8.3 homebrew 0.9.4 git 1.7.12.4

    (Apple Git-37) rbenv 0.4.0 ruby-build 20130518 13೥8݄31೔౔༵೔
  9. ࣮ߦ؀ڥߏங (Macฤ) HomebrewΠϯετʔϧ ཁjava, Xcode command line tools XcodeΛ։͖ɺʮpreferencesʯ 㱺ʮdownloadsʯ㱺ʮComponentsʯ͔Β

    ʮCommand Line ToolsʯΛΠϯετʔϧ Homebrew αΠτͷΠϯετʔϧίϚϯυ࣮ߦ 13೥8݄31೔౔༵೔
  10. $ ruby -e “$(curl -fsSL https:/ /raw.github.com/mxcl/hombrew/go)” $ brew --version

    $ brew update $ brew doctor 13೥8݄31೔౔༵೔
  11. ࣮ߦ؀ڥߏங (Macฤ) rbenv, rubu-buildΠϯετʔϧ $ brew install openssl $ brew

    install readline $ brew install ruby-build $ brew install rbenv $ echo ‘eval “$(rbenv init -)”’ >> ~/.bash_profile $ source ~/.bash_profile 13೥8݄31೔౔༵೔
  12. ࣮ߦ؀ڥߏங (Macฤ) rbenv, rubu-buildΠϯετʔϧ $ RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline` --with-openssl-dir=`brew --prefix

    openssl`" rbenv install 2.0.0-p195 $ rbenv rehash $ rbenv global 2.0.0-p195 ## ϓϩδΣΫτ͝ͱʹόʔδϣϯࢦఆ͢Δ৔߹ $ rbenv local 2.0.0-p195 ɹ#=> .ruby-versionϑΝΠϧʹॻ͖ࠐ·ΕΔ 13೥8݄31೔౔༵೔
  13. ࣮ߦ؀ڥߏங (Macฤ) ಈ࡞֬ೝ $ irb > require ‘openssl’ => true

    > require ‘zlib’ => true > require ‘open-uri’ => true > open (“https:/ /www.google.com”).read => <doctype html>... 13೥8݄31೔౔༵೔
  14. ࣮ߦ؀ڥߏங (Macฤ) rbenvͷ໘౗ͳ఺ gemίϚϯυΛΠϯετʔϧ͢Δͨͼʹɺ rbenv rehash͠ͳ͍ͱ͍͚ͳ͍ ~/.rbenv/shims ҎԼͷߋ৽ gem install

    rbenv-rehash 13೥8݄31೔౔༵೔
  15. ࣮ߦ؀ڥߏங Linuxฤ 13೥8݄31೔౔༵೔

  16. ࣮ߦ؀ڥߏங (Linuxฤ) yum ΍ apt-get ͰೖखՄೳ Ͱ΋όʔδϣϯ͸ݹ͍ʢ͔ͨ͠ͳ͍ʣ ιʔείϯύΠϧ ιʔε͔Βrpmbuild࢖ͬͯrpmΛ࡞੒͢Δ͜ ͱ΋Ͱ͖Δɻ

    13೥8݄31೔౔༵೔
  17. ࣮ߦ؀ڥߏங (Linuxฤ) rvm rbenv, ruby-build Macͱಉ༷ʹར༻Մೳɻ ྫͱͯ͠ɺCentOS 6.4্ʹrbenv, ruby- buildΛΠϯετʔϧͯ͠Έ·͢

    γεςϜϫΠυʹ࢖͑ΔΑ͏ʹͯ͠Έ· ͢ 13೥8݄31೔౔༵೔
  18. # groupadd -g 600 staff # yum install git #

    cd /usr/local/src # git clone https:/ /github.com/sstephenson/rbenv.git rbenv # chgrp -R staff rbenv # chmod -R g+rwxXs rbenv # vi /etc/profile.d/rbenv.sh export RBENV_ROOT=/usr/local/rbenv export PATH="$RBENV_ROOT/bin:$PATH" eval "$(rbenv init -)" 13೥8݄31೔౔༵೔
  19. # cd /usr/local/src/rbenv # mkdir plugins # cd /usr/local/src/rbenv/plugins #

    git clone https:/ /github.com/sstephenson/ruby-build.git # chgrp -R staff ruby-build # chmod -R g+rwxs ruby-build 13೥8݄31೔౔༵೔
  20. # cd /usr/local/src/rbenv/plugins # git clone https:/ /github.com/sstephenson/rbenv-default-gems.git # chgrp

    -R staff rbenv-default-gems # chmod -R g+rwxs rbenv-default-gems # cd /usr/local/src/rbenv # vi default-gems bundler pry rbenv-rehash 13೥8݄31೔౔༵೔
  21. (rbenv installதͷcheckͰ͍Ζ͍Ζ଍Γͳ͍ͷͰɺyum install͓ͯ͘͠) # yum install gcc make zlib-devel readline-devel

    openssl-devel # rbenv install 1.9.3-p448 # rbenv install 2.0.0-p247 # rbenv rehash # rbenv global 2.0.0-p247 13೥8݄31೔౔༵೔
  22. ࣮ߦ؀ڥߏங Windowsฤ 13೥8݄31೔౔༵೔

  23. ࣮ߦ؀ڥߏங (Windowsฤ) Windows൛όΠφϦ͕༗ࢤʹΑΓ഑෍͞Εͯ ͍·͢ɻ ActiveScriptRuby One-Click Ruby Installer for Windows

    ͜͜Ͱ͸ɺOne-Click InstallerΛ࢖ͬͯߏஙͯ͠Έ·͠ΐ͏ɻ 13೥8݄31೔౔༵೔
  24. ࣮ߦ؀ڥߏங (Windowsฤ) μ΢ϯϩʔυ http:/ /rubyinstaller.org/downloads/ RubyΠϯετʔϥͱDevKitΛμ΢ϯϩʔυ DevKit: native extensionΛϏϧυ͢Δπʔϧ 13೥8݄31೔౔༵೔

  25. ࣮ߦ؀ڥߏங (Windowsฤ) RubyΠϯετʔϥ࣮ߦ Πϯετʔϥͷࢦࣔʹै͏͚ͩ σϑΥϧτͰ͸ɺC:¥Ruby200΍C:¥Ruby193ʹ Πϯετʔϧ͞Ε·͢ ύε͕௨͍ͬͯͳ͔ͬͨΒɺύεΛ௨͠·͠ΐ ͏ 13೥8݄31೔౔༵೔

  26. ࣮ߦ؀ڥߏங (Windowsฤ) DevKit࣮ߦ ࣗݾղౚܗࣜͳͷͰɺ࣮ߦͯ͠ղౚ͢Δ ίϚϯυ͔Βɺղౚͨ͠ϑΥϧμʹcdͨ͠ޙɺ ҎԼΛ࣮ߦ ruby dk.rb init ruby

    dk.rb install 13೥8݄31೔౔༵೔
  27. ࣮ߦ؀ڥߏங (Windowsฤ) Rubyͷόʔδϣϯ੾Γସ͑͸ʁ pikΛΠϯετʔϧ͢Δͱɺrubyͷόʔδϣ ϯ੾Γସ͕͑Ͱ͖ΔΒ͍͠ʢࣗ෼ະ֬ೝʣ ࣗ෼͸ɺύεΛ੾Γସ͑Δ͜ͱͰରԠͯ͠ ͍Δ 13೥8݄31೔౔༵೔

  28. ࣮ߦ؀ڥߏங (Windowsฤ) WindowsͰ΋໰୊ͳ͘ಈ͖·͕͢ɺWindows ͩͱ͢ΜͳΓಈ͔ͳ͍gem΋ଟ͍Ͱ͢ɻ Mac΍Linuxʹൺ΂ͯɺWindows͸࣮ߦ଎౓͕ ஗͍Β͍͠ʢࣗ෼Ͱ͸ະ֬ೝʣ ݸਓతʹ͸ɺମײ଎౓͸΄ͱΜͲؾʹͳΒͳ͍Ϩϕϧ͔ͳ WindowsͰ͏·͘ಈ͔ͳ͍৔߹͸ɺ Ծ૝؀ڥ্ͷLinuxͰಈ͔͢͜ͱ΋ ݕ౼ͨ͠΄͏͕͍͍͔΋ɻ

    13೥8݄31೔౔༵೔
  29. ࣮ߦ؀ڥߏங bundlerฤ 13೥8݄31೔౔༵೔

  30. ࣮ߦ؀ڥߏங (bundlerฤ) bundlerΛ࢖ͬͯgemΛ؅ཧ͠·͠ΐ͏ جຊతʹ͸ɺbundler͚ͩ gem install ϓϩδΣΫτ͝ͱʹGemfileʹͯ؅ཧ ϓϩδΣΫτ഑Լͷvendor/bundleʹgemΛ Πϯετʔϧ rvmͷgemset੾ସ͸ෆཁʹͳΔ

    13೥8݄31೔౔༵೔
  31. ࣮ߦ؀ڥߏங (bundlerฤ) bundler Πϯετʔϧ $ gem install bundler $ rbenv

    rehash 13೥8݄31೔౔༵೔
  32. ࣮ߦ؀ڥߏங (bundlerฤ) rubyϓϩδΣΫτ foo ͷ৔߹ $ cd ~/foo $ bundle

    init #=> Gemfileͻͳܗ࡞੒ # A sample Gemfile source "https:/ /rubygems.org" # gem "rails" gem ‘pp’ $ bundle install --path=vendor/bundle #=> ./vendor/bundle ʹΠϯετʔϧ 13೥8݄31೔౔༵೔
  33. ࣮ߦ؀ڥߏங (bundlerฤ) rubyϓϩδΣΫτ foo ͷ৔߹ $ vi main.rb require ‘bundler/setup‘

    #=> bundlerͷgemʹݻఆ require ‘pp‘ #=> ݸผʹrequire Bundler.require #=> Ұׅrequire pp “Foo!” $ ruby main.rb 13೥8݄31೔౔༵೔
  34. ࣮ߦ؀ڥߏங (bundlerฤ) railsϓϩδΣΫτ hoge ͷ৔߹ $ cd ~/hogehoge $ bundle

    init #=> Gemfileͻͳܗ࡞੒ # A sample Gemfile source "https:/ /rubygems.org" gem "rails" $ bundle install --path=vendor/bundle #=> ./vendor/bundle ʹΠϯετʔϧ 13೥8݄31೔౔༵೔
  35. ࣮ߦ؀ڥߏங (bundlerฤ) railsϓϩδΣΫτ hoge ͷ৔߹ $ bundle exec rails new

    hoge -B $ cd hoge $ bundle install --path=vendor/bundle 13೥8݄31೔౔༵೔
  36. ·ͱΊ 13೥8݄31೔౔༵೔

  37. ·ͱΊ Mac Linux ( CentOS ) rbenv, ruby-build Windows όΠφϦΠϯετʔϧ

    bundlerʹΑΔgem؅ཧ ϓϩδΣΫτ͝ͱʹ࣋ͭͱศར 13೥8݄31೔౔༵೔
  38. ׬ 13೥8݄31೔౔༵೔