gem install rails の openssl エラーを ruby の入れ直しで解決した
https://guides.rubyonrails.org/getting_started.html
why
Ruby 開発 を受けるから
what is rails?
https://www.ruby-lang.org/en/documentation/
Ruby の公式ドキュメントはこっち
https://guides.rubyonrails.org/getting_started.html
ここによると
Rails is a web application development framework written in the Ruby programming language.
It is designed to make programming web applications easier by making assumptions about what every developer needs to get started.
- 全ての開発者が(仕事を)始めるのに必要な全ての「思い込み」を簡単にする アプリケーション?
It allows you to write less code while accomplishing more than many other languages and frameworks
- 他の多くの言語やフレームワークよりも、(仕事を)遂行するのにより少ないコード数でかける
If you learn "The Rails Way" you'll probably discover a tremendous increase in productivity
- 「Rails の方法」を学べば、生産性がすごく上がる
DRY
Don't Repeat Yourself "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." By not writing the same information over and over again, our code is more maintainable, more extensible, and less buggy.
- 自身を繰り返すな
- 全ての知識のピース単一で、明白で、誤解の余地のない表現が システムに載っているべきだ。
- 同じ情報を何度も何度も書かないことで、私たちのコードはメンテナンス性が高く、拡張性が高く、バグが少なくなる
React でもよく言われる考えだ
Convention Over Configuration
- config file の configuration.
- 設定より規約
Rails has opinions about the best way to do many things in a web application, * and defaults to this set of conventions, rather than require that you specify minutiae through endless configuration files.
- Rails は Web アプリで多くのものを作るための 最善策のオプションがある
- conventions という デフォルトをセットすることで、特殊な詳細を延々と config file に書くことを避けられる(?)
https://ja.wikipedia.org/wiki/%E8%A8%AD%E5%AE%9A%E3%82%88%E3%82%8A%E8%A6%8F%E7%B4%84
この言葉の本質的な意味は、開発者が指定しなければならないのはアプリケーションの慣例に従わない点だけだ、ということである。例えば、モデルの中にSalesというクラスがあれば、データベース中の対応する表の名前はデフォルトでsalesである、という規約を定める。
- CakePHP で Model も Controller も 名前を合わせるのがあったがそれのことか。Table が Articles で、Controller が ArticlesController だと読み込むが、そうでないとエラーになるみたいな。
Create New Project
2020.09.13 23:58
Install dependencies
実際に作ってみる
まずは
ruby -v ruby 2.6.1p33 sqlite3 --version 3.7.17 node -v v12.13.1 yarn -v bash: yarn: command not found
yarn はなかったので install
brew install yarn 🍺 /usr/local/Cellar/yarn/1.22.5: 14 files, 5MB, built in 5 seconds yarn -v 1.22.5
入った。
では rails を...
gem install rails ERROR: Loading command: install (LoadError) dlopen(/Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle Reason: image not found - /Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass
おおん...
Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
- openSSL が load されないらしい。
- 場所は
/usr/local/opt/openssl/lib/libssl.1.0.0
https://qiita.com/Capotasto/items/16be7620c4eed42efccb
この記事を見ると
- brew uninstall --無理やり openssl
- brew update
- brew install openssl/libcrypto
- brew install openssl/libssl
- brew install openssl ...
で解決したらしい。は?
これはやらない
https://qiita.com/YoshiyukiKato/items/e4f67c588d2943c1253d
これを勧められたのでやる
brew install openssl Warning: openssl@1.1 1.1.1g is already installed and up-to-date To reinstall 1.1.1g, run `brew reinstall openssl@1.1`
既に最新ですと出た。
brew link openssl --force Warning: Refusing to link macOS provided/shadowed software: openssl@1.1 If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> /Users/kaede/.bash_profile For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
link するのを refuse された?
当然この段階では rails は gem install できない
書かれているとおりに PATH を.bash_profileに打ち込むか
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
これをして brew link をもう一度してもダメだった。 for compilers, pkg-config も必要か?
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
両方追加 sh を reflesh
それでも refuse されてしまう
とりあえず rbenv の入れ直しをやる
rbenv -v rbenv 1.1.2 rbenv uninstall 1.1.2 rbenv: version `1.1.2' not installed
おや?????
rbenv uninstall rbenv -v rbenv 1.1.2
rbenv も PATH が通ってない
eval "$(rbenv init -)" export PATH="$HOME/.rbenv/shims:$PATH"
よくわかってないが、.bash_profile のこれが原因か???
消してしまえ!!!
rbenv uninstall rbenv 1.1.2 rbenv -v rbenv 1.1.2
これでも消えない。
どこにあるのを指してるんだ??
which rbenv /usr/local/bin/rbenv
ユーザーのローカルのバイナリにあるのを指している。
brew で入れた rbenv と違う? いや rbenv は rbenv で入れるものだから...
https://qiita.com/dasisyouyu/items/c9621c29b0fe79d2b7c4
Mac の仕様変更で brew link --force ができないから、直接 PATH を通す必要があるらしい
rbenv は置いといて、openSSL がおかしいらしい
which openssl /Applications/XAMPP/bin/openssl
XAMPP のopenSSLが使われている
だが 先ほど openSSL の PATH は通してある。これ以上わからない!!
PATH の中身を見て見る
echo $PATH /Users/kaede/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/opt/libiconv/bin:/usr/local/opt/libxslt/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/libxslt/bin:/usr/bin/rails:/usr/local/opt/ruby/bin:/Applications/XAMPP/bin:/usr/local/opt/php@7.1/bin/:/opt/local/bin:~/code/sh:~/bin:/usr/local/bin:/Users/kaede/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/opt/libiconv/bin:/usr/local/opt/libxslt/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/libxslt/bin:/usr/bin/rails:/usr/local/opt/ruby/bin:/Applications/XAMPP/bin:/usr/local/opt/php@7.1/bin/:/opt/local/bin:~/code/sh:~/bin:/usr/local/bin:/usr/local/opt/openssl@1.1/bin:/usr/local/opt/php@7.1/bin:/Users/kaede/.rbenv/shims:/Users/kaede/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/kaede/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/opt/libiconv/bin:/usr/local/opt/libxslt/bin:/usr/local/opt/libxml2/bin:/usr/bin/rails:/usr/local/opt/ruby/bin:/Applications/XAMPP/bin:/usr/local/opt/php@7.1/bin/:~/code/sh:~/bin:/usr/local/opt/openssl@1.1/bin:/usr/local/opt/php@7.1/bin
多すぎないか?????何かがループしてる???
.bashrc
を
GitHub から見てみると
### php,xampp,ruby,rails,man, export PATH="/usr/local/opt/php@7.1/bin/:$PATH" export PATH="/Applications/XAMPP/bin:$PATH" export PATH="/usr/local/opt/ruby/bin:$PATH" export PATH="/usr/bin/rails:$PATH" export MANPATH=/opt/local/man:$MANPATH
XAMPP のはここに入っていた!!
この一文を消すと
which openssl /usr/local/opt/openssl@1.1/bin/openssl
通った!!!!
では rails を gem で入れるぞ!!
gem install rails ERROR: Loading command: install (LoadError) dlopen(/Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle Reason: image not found - /Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass
ダメだ!!!!
openssl は usr/local/bin のを読めてるけど、その openssl を rbenv が読み込んでくれない。入れ直して link するにも、rbenv は .bashrc の PATH に記載がないしどうしようもない!
上司に相談したところ
rbenv での Ruby の再インストール Ruby がビルドされるときのライブラリのリンク先が違う可能性を疑って再インストールを試す
OpenSSL のバージョンを変えてみる
を勧められた。
後者を行う
[Railsの環境構築時にLibrary not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)で苦しんだ] (https://qiita.com/yamazaki8934/items/48e65850873f3ecbee26)
brew switch openssl 1.1.0 Error: openssl does not have a version "1.1.0" in the Cellar. openssl's installed versions: 1.1.1g
ダメだった。1.1.1g から 1.1.0 に変えられない
現状は確かに
openssl OpenSSL> version OpenSSL 1.1.1g 21 Apr 2020
1.1.1g になっている
さらに指定してみる
brew switch openssl 1.1.1g Cleaning /usr/local/Cellar/openssl@1.1/1.1.1g Opt link created for /usr/local/Cellar/openssl@1.1/1.1.1g
Clean されて opt link が作成された???? これはもしや...!!
gem install rails ERROR: Loading command: install (LoadError) dlopen(/Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle Reason: image not found - /Users/kaede/.rbenv/versions/2.6.1/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass
ダメでした....
openssl 1.0.0 を入れてみるか
Error: No available formula with the name "1.0.0"
[Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)] (https://qiita.com/utsu_san/items/a35437faea1c0d2f357d)
brew reinstall openssl@1.1
クッソ長かったが最後、
==> Installing php@7.1 Error: An exception occurred within a child process: FormulaUnavailableError: No available formula with the name "/usr/local/opt/php@7.1/.brew/php@7.1.rb"
で中断されたっぽい?
ruby を入れ直す
rbenv install 2.6.1 rbenv: /Users/kaede/.rbenv/versions/2.6.1 already exists continue with installation? (y/N) y Installing ruby-2.6.1... ruby-build: using readline from homebrew Installed ruby-2.6.1 to /Users/kaede/.rbenv/versions/2.6.1
これは無事に入れ直しできた
まぁこれでも動かないんだろうな....
gem install rails Fetching thread_safe-0.3.6.gem Fetching rack-test-1.1.0.gem Fetching i18n-1.8.5.gem Fetching tzinfo-1.2.7.gem Fetching activesupport-6.0.3.3.gem Fetching rack-2.2.3.gem Fetching concurrent-ruby-1.1.7.gem Fetching zeitwerk-2.4.0.gem Fetching mini_portile2-2.4.0.gem Fetching rails-dom-testing-2.0.3.gem Fetching nokogiri-1.10.10.gem ...
嘘やろ!!!!!!!!!!!!(大絶叫)
Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, zeitwerk, activesupport, rack, rack-test, mini_portile2, nokogiri, crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, actionmailbox, actiontext, thor, method_source, railties, sprockets, sprockets-rails, rails after 39 seconds 40 gems installed
documentation になるんだ。 できた。これで...?
rails --version Rails 6.0.3.3
キタコレ!!!
rails new rails-blog Fetching sassc 2.4.0 Installing sassc 2.4.0 with native extensions ... ✨ Done in 14.01s. Webpacker successfully installed 🎉 🍰
yarn での js などの依存関係?が莫大で CRA (create-react-app) や CRN の比ではなかった。
だがこれでアプリケーションが作成完了
/Users/kaede/code/rails-blog/ ▸ app/ ▸ bin/ ▸ config/ ▸ db/ ▸ lib/ ▸ log/ ▸ node_modules/ ▸ public/ ▸ storage/ ▸ test/ ▸ tmp/ ▸ vendor/ babel.config.js config.ru Gemfile Gemfile.lock package.json postcss.config.js Rakefile README.md yarn.lock
この構成になっている。
rails server
ようやくここまでたどり着いた... 長かった...