gakkie プログラミング 備忘録

tech::expert(現tech camp) 45期

rails tutorial (rails6)備忘録

【環境】
mac OS Mojave
・バージョン10.14.6
Visual Studio Code

学習テーマ rails tutorialの勉強の備忘録として残す。

rails6の環境構築

mba-2:rails6_tutorial #(myname)$ gem install rails -v 6.0.0

ERROR:  Loading command: install (LoadError)
        dlopen(/Users/#(myname)/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /Users/#(myname)/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/openssl.bundle
  Reason: image not found - /Users/#(myname)/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/openssl.bundle
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

#rails6はruby2.6.0以上から使えるようなのでinstallする

mba-2:rails6_tutorial #(myname)$ rbenv install 2.6.0
ruby-build: use openssl from homebrew
Downloading ruby-2.6.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.0.tar.bz2
Installing ruby-2.6.0...
ruby-build: use readline from homebrew
Installed ruby-2.6.0 to /Users/#(myname)/.rbenv/versions/2.6.0
mba-2:rails6_tutorial #(myname)$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]

#2.6.0に変更する

mba-2:rails6_tutorial #(myname)$ rbenv global 2.6.0
mba-2:rails6_tutorial #(myname)$ ruby -v
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]

#rails6をinstall
mba-2:rails6_tutorial #(myname)$ gem install rails -v 6.0.0

rails newまで

mba-2:rails6_tutorial #(myname)$ rails -v
Rails 6.0.0
mba-2:rails6_tutorial #(myname)$ source <(curl -sL https://cdn.learnenough.com/yarn_install)
mba-2:rails6_tutorial #(myname)$ (23) Failed writing body

mba-2:rails6_tutorial #(myname)$ yarn install --check-filesPlease run rails webpacker:install Error: No such file or directory @ rb_sysopen
bash: yarn: command not found
mba-2:rails6_tutorial #(myname)$ rails _6.0.0_ new hello_app

#成功。ここでmasterにpush
mba-2:rails6_tutorial #(myname)$ bundle install

#Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

rails s しかし。。。。

mba-2:hello_app #(myname)$ rails s

するとエラー発生。

エラー内容

/Users/#(myname)/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /Users/#(myname)/projects/rails6_tutorial/hello_app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/#(myname)/projects/rails6_tutorial/hello_app/config/webpacker.yml (RuntimeError)

run rails webpackerをしろと言われているので実行

mba-2:hello_app #(myname)$ rails webpacker:install
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/

エラーどうやらyarnをinstallしないとけないようだ。yarnをインストール

mba-2:hello_app #(myname)$ brew install yarn
mba-2:hello_app #(myname)$ rails webpacker:install
Webpacker successfully installed 🎉 🍰

image.png

今回はここまで

参考にした記事(いつもありがとうございます。)

Rails6 Webpackerでエラーが出た