hAcKTion

日々のアウトプット場所。

cocoapodsをインストールするとエラーが出た

なんと、私用のPCはXcode周りの設定していなく、cocoapodsが入っていなかった。 というわけで、インストール!

$ sudo gem install cocoapods

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
        ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200829-62169-14h3sh9.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/gem_make.out

gemのネイティブ拡張のビルドに失敗とな?
rubyのheaderファイルを見つけられなかったとな?

アドバイスとして「Ruby開発用に個別のパッケージをインストールする必要があるかもしれません」と言われたので、情報を探す。

ひとまず、ruby入ってるよね?というところから確認。

$ ruby --version 
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

入ってた。

もしかして、Command Line Tools for Xcodeが入っていない...?

$ xcode-select -print-path 
/Applications/Xcode.app/Contents/Developer

$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

ある。あれ、これどこかで見覚えが...。

hacktion.hateblo.jp

というわけで

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

よし。入った。これで、もいちど実行!

$ sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
        ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200829-62169-14h3sh9.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/gem_make.out

ブッブー。

エラーをよく見直してみると、 ffi というのが怪しい? というわけで、こいつをインストールしてみる。

$ sudo gem install ffi

Building native extensions. This could take a while...
ERROR:  Error installing ffi:
        ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200829-62264-1nmcu4z.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/gem_make.out

おんなじエラーがでた!

ということは、こいつが原因っぽい。

しかし、ここから迷宮入りして、いろいろやったのでコマンドだけメモしておくと・・・

$ bundle update
 -> 途中でエラー
$ bundle install
 -> 途中でエラー
$ sudo gem update --system
 -> 途中でエラー。。
$ make clean
 -> なんかライセンス同意してねって言われた。

とやってて、突破口が見えん!!ってなってたので、もっかいやってみると・・・

$ sudo gem install ffi
Building native extensions. This could take a while...
Successfully installed ffi-1.13.1
Parsing documentation for ffi-1.13.1
Installing ri documentation for ffi-1.13.1
Done installing documentation for ffi after 19 seconds
1 gem installed

えっ。

$ sudo gem install cocoapods
Successfully installed ethon-0.12.0
Successfully installed typhoeus-1.4.0
Successfully installed netrc-0.11.0
Successfully installed cocoapods-core-1.9.3
Successfully installed claide-1.0.3
Successfully installed cocoapods-deintegrate-1.0.4
Successfully installed cocoapods-downloader-1.4.0
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-search-1.0.0
Successfully installed cocoapods-stats-1.1.0
Successfully installed cocoapods-trunk-1.5.0
Successfully installed cocoapods-try-1.2.0
Successfully installed molinillo-0.6.6
Successfully installed atomos-0.1.3
Successfully installed colored2-3.1.2
Successfully installed nanaimo-0.3.0
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

おお、やっといけ・・・・て・ない・・・・・・・・?

こちらを参考にしてみました。

qiita.com

sudo gem install cocoapods
Password:
Successfully installed ethon-0.12.0
Successfully installed typhoeus-1.4.0
Successfully installed netrc-0.11.0
Successfully installed cocoapods-core-1.9.3
Successfully installed claide-1.0.3
Successfully installed cocoapods-deintegrate-1.0.4
Successfully installed cocoapods-downloader-1.4.0
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-search-1.0.0
Successfully installed cocoapods-stats-1.1.0
Successfully installed cocoapods-trunk-1.5.0
Successfully installed cocoapods-try-1.2.0
Successfully installed molinillo-0.6.6
Successfully installed atomos-0.1.3
Successfully installed colored2-3.1.2
Successfully installed nanaimo-0.3.0
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.
aktuehr@akt-mbp20 ~/D/h/g/lab-ncmb-with-capacitor> sudo gem install cocoapods -n /usr/local/bin
Successfully installed xcodeproj-1.18.0
Successfully installed escape-0.0.4
Successfully installed fourflusher-2.3.1
Successfully installed gh_inspector-1.1.3
Successfully installed ruby-macho-1.4.0
Successfully installed cocoapods-1.9.3
Parsing documentation for xcodeproj-1.18.0
Installing ri documentation for xcodeproj-1.18.0
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for gh_inspector-1.1.3
Installing ri documentation for gh_inspector-1.1.3
Parsing documentation for ruby-macho-1.4.0
Installing ri documentation for ruby-macho-1.4.0
Parsing documentation for cocoapods-1.9.3
Installing ri documentation for cocoapods-1.9.3
Done installing documentation for xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 3 seconds
6 gems installed

できたーーーーーー!