$30 off During Our Annual Pro Sale. View Details »

Ruby on Railsの開発環境をつくってみよう! / GMO HosCon #19 Fu...

Ruby on Railsの開発環境をつくってみよう! / GMO HosCon #19 Fukuoka

Ken’ichiro Oyama

July 11, 2018
Tweet

More Decks by Ken’ichiro Oyama

Other Decks in Technology

Transcript

  1. λʔϛφϧͬͯԿʁ w จࣈͰ.BD#PPL΍ͦͷଞ͍Ζ͍ΖϓϩάϥϜΛૢ࡞͢ΔͨΊͷϞϊɾπʔϧɾΞϓ Ϧέʔγϣϯ ◦ CUIʢΩϟϥΫλʔɾϢʔβɾΠϯλʔϑΣʔε : จࣈUIʣ ◦ ൓ରʹϚ΢εͰΫϦοΫͨ͠Γը໘Ͱͷૢ࡞͕͋Δͷ͸GUIʢάϥϑΟΧϧɾϢʔ

    βɾΠϯλʔϑΣʔε : άϥϑΟΧϧͳUIʣ • ίϚϯυ΍εΫϦϓτʢϓϩάϥϜ͕ղऍͰ͖ΔจࣈྻʣΛೖྗ͢Δ͜ͱͰ༷ʑͳૢ ࡞͕Ͱ͖Δ • ͳΜͰλʔϛφϧʁ ◦ ίϚϯυ͕จࣈͳͷͰϋοΩϦ͍ͯ͠Δͷ͕޷·Ε͍ͯΔ ◦ ʮ**ͱ͍͏ίϚϯυΛ࣮ߦͯ͠Έͯʯ ɹɹɹλʔϛφϧɺ#BTI  
  2. ϓϩάϥϛϯάݴޠ3VCZͷΠϯετʔϧ > brew install readline ruby-build rbenv > echo 'export

    PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile > echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile > source ~/.bash_profile > rbenv install 2.5.1 > rbenv global 2.5.1 > ruby -v ɹɹɹl.BD3VCZSCFOWz  
  3. όʔδϣϯ؅ཧπʔϧ(JUͷΠϯετʔϧ > brew install git > git config --global user.name

    "[໊લΛೖΕ͍ͯͩ͘͞]" > git config --global user.email "[ϝʔϧΞυϨεΛೖΕ͍ͯͩ͘͞]" > git --version ɹɹɹ(JU  
  4. 3VCZPO3BJMTΛ࢖͏લͷલ४උ .Z42-ͷΠϯετʔϧɺىಈɺ.Z42-؅ཧΞϓϦͷΠϯετʔϧ > brew install mysql mysql-client # MySQLͷΠϯετʔϧ >

    brew cask install sequel-pro # MySQL؅ཧΞϓϦ Sequel Pro ͷΠϯε τʔϧ > brew services start mysql # MySQLͷىಈ > brew services list # MySQLͷىಈͷ֬ೝ ɹɹɹσʔλϕʔε.Z42-4FRVFM1SP  
  5. > mysql -uroot mysql> CREATE USER myuser@localhost identified with mysql_native_password

    by ‘mypass'; mysql> exit > ɹɹɹl.Z42-zlσʔλϕʔεzl4FRVFM1SPz   w ࠷৽ͷ.Z42-Ͱ͸σϑΥϧτͷೝূํ͕ࣜDBDIJOH@TIB@QBTTXPSEͱͳ͓ͬͯΓ4FRVFM1SPͳͲ͕ ରԠ͍ͯ͠ͳ͍ͨΊɺ.Z42-ҎલͰར༻͞Ε͍ͯͨNZTRM@OBUJWF@QBTTXPSEΛར༻ͨ͠ϢʔβΛ࡞ ੒ͯ͠ར༻͠·͢ 3VCZPO3BJMTΛ࢖͏લͷલ४උ .Z42-ͷϢʔβͷ௥Ճ
  6. σʔλϕʔεͷ઀ଓઃఆΛ͠Α͏ default: &default adapter: mysql2ɹ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5

    } %> timeout: 5000 development: <<: *default ɹusername: root database: hoscon host: 127.0.0.1 test: <<: *default username: root database: hoscon_test host: 127.0.0.1 production: <<: *default database: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] username: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] production: <<: *default database: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] username: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] password: [ϝϞͨ͠σʔλϕʔεͷύεϫʔυ] host: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ]  
  7. ϓϩδΣΫτͷιʔείʔυΛίϛοτ͠Α͏ wόʔδϣϯ؅ཧπʔϧ(JUΛར༻ͯ͠ࠓ·ͰͷιʔείʔυΛه࿥ʢί ϛοτʣ͠·͢ > git init # σΟϨΫτϦΛGitͰ؅ཧ͢ΔΑ͏ʹઃఆ > git

    add . # શͯͷ௥Ճͯ͠Α͍ϑΝΠϧΛGitʹ؅ཧͤ͞Δ > git commit -m 'My First Commit’ # ίϛοτ > git log # ίϛοτͷϩάΛ֬ೝ ɹɹɹ(FNpMFl3BJMTNZTRM  
  8. ιʔείʔυΛमਖ਼ͯ͠ίϛοτ͠Α͏ wϒϥ΢βͰIUUQMPDBMIPTUJEFBT ʹΞΫηεͯ͠ΈΑ͏ wSequel ProͰσʔλϕʔεͷঢ়ଶΛ֬ೝͯ͠Έ·͠ΐ͏ > rails generate scaffold idea

    name:string description:text picture:string # ideas ςʔϒϧΛ࡞ͬͯૢ࡞͢ΔͨΊͷίʔυΛੜ੒ > rails db:migrate # ideas ςʔϒϧΛ࡞੒ > rails server # αʔόΛىಈ ɹɹɹlSBJMTίϚϯυzl$36%zlTDB⒎PMEz  
  9. ιʔείʔυΛमਖ਼ͯ͠ίϛοτ͠Α͏ wSBJMTHFOFSBUFͰࣗಈͰߦΘΕͨमਖ਼Λ(JUΛར༻ͯ֬͠ೝɾه࿥ ʢίϛοτʣ͠Α͏ > git status # ιʔείʔυͷมߋঢ়ଶΛ֬ೝͰ͖·͢ > git

    diff # ιʔείʔυͷࠩ෼Λ֬ೝͰ͖·͢ > git add . > git commit -m 'My Second Commit' > git log ɹɹɹl(JUίϚϯυz  
  10. σϓϩΠલͷલ४උ 44)ͷެ։伴ͷઃఆ wެ։伴ͱൿີ伴ͷରΛ࡞੒ͯ͠ɺެ։伴ΛΫϦοϓϘʔυʹίϐʔ͠ ·͢ > install -m 0700 -d ~/.ssh

    # σΟϨΫτϦͷ࡞੒ > ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa # ެ։伴ͱൿີ伴Λ࡞੒ > cat ~/.ssh/id_rsa.pub | pbcopy # ެ։伴ΛΫϦοϓϘʔυʹίϐʔ ɹɹɹlDBUίϚϯυlQCDPQZz  
  11. ϥΠηϯε w͜ͷϋϯζΦϯͷࢿྉͷҰ෦͸3BJMT(JSMTΨΠυ ೔ຊޠ൛  IUUQ SBJMTHJSMTKQ Λࢀߟʹ͍ͯ͠·͢ɻ·ͨɺ3BJMT(JSMTΨΠυʹͭͳ͕ ΔΑ͏ʹ࡞ΒΕ͍ͯ·͢ɻ 3BJMT(JSMTΨΠυϥΠηϯε 5IJTXPSLJTMJDFOTFEVOEFSB$SFBUJWF$PNNPOT"UUSJCVUJPO4IBSF"MJLF-JDFOTF

    IUUQDSFBUJWFDPNNPOTPSHMJDFOTFTCZTB 3BJMT(JSMT IUUQ SBJMTHJSMTDPN u$SBGUFEXJUIFYDJUFNFOUGSPN)FMTJOLJ 'JOMBOEu'PMMPXVTPO5XJUUFS IUUQTUXJUUFSDPNSBJMTHJSMT BOE'BDFCPPL IUUQTXXXGBDFCPPLDPNSBJMTHJSMT   
  12. .Z42-ͱ.Z42-ͷΞϯΠϯετʔϧ wϋϯζΦϯ౰೔ʹCSFXJOTUBMMNZTRM!΋࣮ߦͨ͠ํ͸ҎԼͷରԠ Ͱ.Z42-ͷΞϯΠϯετʔϧ͕ՄೳͰ͢ > brew services list # [email protected]͕͍Δ͜ͱΛ֬ೝ >

    brew services stop [email protected] > brew uninstall [email protected] > brew services stop mysql # brew services listʹmysql͕͍Ε͹stop > brew uninstall mysql # brew services listʹmysql͕͍Ε͹stop > rm -rf /usr/local/var/mysql # MySQLͷશͯͷσʔλ͕ফ͑·͢  
  13. CSFXTFSWJDFTMJTUͰNZTRMͷද͕ࣔΦϨϯδͷ৔߹ w.Z42-Λσʔλ΋ؚΊΞϯΠϯετʔϧޙɺ.Z42-Λ࠶౓Πϯετʔ ϧ͍ͯͩ͘͠͞   > brew services list #

    mysql ͕ଘࡏ͍ͯ͠Δ͜ͱΛ֬ೝ > brew services stop mysql > brew uninstall mysql > rm -rf /usr/local/var/mysql # MySQLͷશͯͷσʔλ͕ফ͑·͢ > brew install mysql > brew services start mysql