How to solve the local environment construction of Ruby on Rails (MAC)!

environment

macOS Catalina version: 10.15.7 (19H2)

Introduction

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!

Error occurred in gem install rails

$ 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 

solution

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

I got an error with bundle install ...

$ 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

When you get an error in rails test

$ 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

How to solve the local environment construction of Ruby on Rails (MAC)!
Ruby on Rails development environment construction on M1 Mac
Environment construction of Ruby on Rails from 0 [Cloud9] (From Ruby version change to Rails installation)
[Ruby On Rails] How to search the contents of params using include?
Docker the development environment of Ruby on Rails project
[Ruby on Rails] How to change the column name
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
[Ruby on Rails] How to make the link destination part of the specified id
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
How to use Ruby on Rails
Ruby on Rails 6.0 environment construction memo
From 0 to Ruby on Rails environment construction [macOS] (From Homebrew installation to Rails installation)
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
part of the syntax of ruby ​​on rails
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
Ruby on Rails --From environment construction to simple application development on WSL2
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
[Ruby on Rails] "|| =" ← Summary of how to use this assignment operator
[Ruby On Rails] How to search and save the data of the parent table from the child table
How to find the cause of the Ruby error
[Ruby on Rails] Until the introduction of RSpec
How to link Rails6 Vue (from environment construction)
How to make an application with ruby on rails (assuming that the environment has been built)
[Personal memo] Ruby on Rails environment construction (Windows)
[Error] Switch environment construction to use Ruby on Rails oss (open source)
[Ruby on Rails] Let's build an environment on mac
How to debug the processing in the Ruby on Rails model only on the console
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] How to use session method
[Rails] How to solve the time lag of created_at after save method
How to resolve errors that occur in the "Ruby on Rails" integration test
[Ruby on Rails] How to write enum in Japanese
[Ruby] How to find the sum of each digit
[Rails] How to change the column name of the table
[Ruby On Rails] How to reset DB in Heroku
As of April 2018 How to get Java 8 on Mac
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
[Rails] How to get the contents of strong parameters
SSL in the local environment of Docker / Rails / puma
[Ruby on Rails] From MySQL construction to database change
(Ruby on Rails6) How to create models and tables
Try using the query attribute of Ruby on Rails
Rails6 development environment construction [Mac]
Rails engineer environment construction ruby2.7.1
Rails environment construction Rails5.2.1 ruby2.5.1 Catalina
[Rails / MySQL] Mac environment construction
[Ruby On Rails] How to use simple_format to display the entered text with line breaks
For those who want to use MySQL for the database in the environment construction of Rails6 ~.
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
[Ruby on Rails] Elimination of Fat Controller-First, logic to model-
(Ruby on Rails6) Display of the database that got the id of the database
Delete all the contents of the list page [Ruby on Rails]
A note about the seed function of Ruby on Rails
How to display a graph in Ruby on Rails (LazyHighChart)