macOS Catalina version: 10.15.7 (19H2)
I'm currently doing the 6th edition of the Ruby on Rails tutorial! This tutorial recommends running on Cloud9. However, I'm using Cloud9, and around Chapter 3 of this tutorial, EC2 is full. I tried various solutions, but I couldn't solve them, so I had no choice but to build an environment locally.
When I built the Ruby on Rails environment locally, there were a lot of things that got stuck, so I've summarized the solutions for those things! At the same time as I recorded "why I solved it when I got stuck", I posted it in the hope that it would be helpful if there was someone who got stuck in the same place!
$ gem install rails
The following error occurs when executing.
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10/ext/nokogiri
/Users/user/.rbenv/versions/2.6.6/bin/ruby -I /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0 -r ./siteconf20200928-6506-ipfftu.rb extconf.rb
checking if the C compiler accepts -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/user/.rbenv/versions/2.6.6/bin/$(RUBY_BASE_NAME)
--help
--clean
/Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:532:in `with_werror'
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
from extconf.rb:138:in `nokogiri_try_compile'
from extconf.rb:162:in `block in add_cflags'
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:643:in `with_cflags'
from extconf.rb:161:in `add_cflags'
from extconf.rb:416:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-14/2.6.0/nokogiri-1.10.10/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10 for inspection.
Results logged to /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-14/2.6.0/nokogiri-1.10.10/gem_make.out
taibuchuu-no-MacBook-Air:Portfolio user$ sudo gem install rails
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10/ext/nokogiri
/Users/user/.rbenv/versions/2.6.6/bin/ruby -I /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0 -r ./siteconf20200928-6530-ffnnel.rb extconf.rb
checking if the C compiler accepts -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/user/.rbenv/versions/2.6.6/bin/$(RUBY_BASE_NAME)
--help
--clean
/Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:532:in `with_werror'
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
from extconf.rb:138:in `nokogiri_try_compile'
from extconf.rb:162:in `block in add_cflags'
from /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0/mkmf.rb:643:in `with_cflags'
from extconf.rb:161:in `add_cflags'
from extconf.rb:416:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-14/2.6.0/nokogiri-1.10.10/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10 for inspection.
Results logged to /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-14/2.6.0/nokogiri-1.10.10/gem_make.out
After investigating, I arrived at the following article. https://qiita.com/ksugawara61/items/fa9ebaa7d5fe4be630cf
Execute the following command in the same way as the method solved in the above article.
$ xcode-select --install
Then the following error occurs. .. ..
xcode-select: note: install requested for command line developer tools
If you look it up, it would be nice to manually insert the command line tool. Search for "command line tool" at the link below and I installed Command Line Tools for Xcode 12.
If you put in the corresponding Command Line Tools, __success! !! !! __
Successfully installed rails-6.0.3.3
31 gems installed
Finally, you can develop Rails locally! !!
If you think
$ bundle install
Then the following error ...
An error occurred while installing puma (4.3.4), and
Bundler cannot continue.
Make sure that `gem install puma -v '4.3.4' --source
'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
puma
I did a lot of research, but I couldn't solve it.
However, I finally solved it by referring to the following article ~ ~! !! God! !! https://qiita.com/ibarakishiminn/items/94bbee2109304468bf53
The procedure of the executed command is as follows! !!
# remove user-specific gems and git repos
rm -rf ~/.bundle/ ~/.gem/
# remove system-wide git repos and git checkouts
rm -rf $GEM_HOME/bundler/ $GEM_HOME/cache/bundler/
# remove project-specific settings and git repos
rm -rf .bundle/
# remove project-specific cached .gem files
rm -rf vendor/cache/
# remove the saved resolve of the Gemfile
rm -rf Gemfile.lock
# try to install one more time
bundle install
$ rails t
Then the following error occurred.
Error:
StaticPagesControllerTest#test_should_get_help:
ActionView::Template::Error: Webpacker can't find application in /Users/skydaibu/Desktop/Portfolio/sample_app/public/packs-test/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
By executing the following command referring to the following article, the test was executed normally!
$ rm -rf bin/webpack*
$ brew install yarn
$ rails webpacker:install
$ rails t
# Running:
...
Finished in 19.665327s, 0.1526 runs/s, 0.3051 assertions/s.
3 runs, 6 assertions, 0 failures, 0 errors, 0 skips
__ Test successful! !! !! __
__ Finally you can develop properly with this! !! I'm happy! !! __
Recommended Posts