LoginSignup
1
0

More than 1 year has passed since last update.

Mac で Ruby の環境が壊れてた

Posted at

環境

  • macOS Big Sur 11.4
  • MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
$ ruby --version
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-darwin18]
$ rbenv --version
rbenv 1.1.2

現象

React Native でモバイル開発をしていました.

iOS 向けのビルドをするためには, ios ディレクトリ内で pod install する必要があります.しかし,実行すると

$ pod install
zsh: /usr/local/bin/pod: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: no such file or d
irectory

といったエラーを吐かれます. /usr/local/bin/pod が呼び出そうとしている ruby スクリプトが見つからないようです.

解決

TL;DR

私の場合は,以下のコマンドをポチポチしたところ pod が復活しました.

ruby 及び rbenv を一度削除する作業が含まれるため,実行する場合は自己責任でお願いします.

brew remove rbenv && rm -rf $HOME/.rbenv && brew install rbenv
PATH="/usr/bin:$PATH" rbenv install 2.7.4
rbenv global 2.7.4
sudo gem install cocoapods

# iOS プロジェクトのディレクトリで実行する
cd $PROJ_DIR && pod install

以下,上のコマンド群を得るために行った一連の作業です.

1 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby を確認する

エラーにあるファイルが存在するかを確認します.

$ ls /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
ls: cannot access '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby': No such file or directory

というわけなので,ないようです.

したがって, /usr/local/bin/pod が呼び出す ruby インタープリタの場所を教えて上げる必要がありそうです.

2 gem update を行う

gg ったところ, 同じような現象を 解決している記事 が見つけられました. それに従い, sude gem update --system -n /usr/local/bin を実行し,以下のエラーを得ました.

/usr/local/Cellar/rbenv/1.1.2/libexec/rbenv-exec: /Users/(ユーザ名2)/.rbenv/versions/2.6.4/bin/gem: /Users/(ユーザ名1)/.rbenv/versions/2.6.4/bin/ruby: bad interpreter: No such file or directory
/usr/local/Cellar/rbenv/1.1.2/libexec/rbenv-exec: line 47: /Users/(ユーザ名2)/.rbenv/versions/2.6.4/bin/gem: Undefined error: 0

ユーザ名1 となっている部分は,以前この Mac で使っていた自分のユーザ名です. ユーザ名2 は,その後変更した名前です.

つまり,以前ユーザ名を変更してホームディレクトリが変わったにも関わらず,古いパスで ruby インタープリタを参照していることがいけないのだろうと推測できます.

この ruby 参照先を直接書き換えることも試しましたが,どうやら gem やらでも同じように環境の崩壊が起きているらしく,,結局うまく動きませんでした.なので,諦めて ruby 関係の環境を再構築することにしました.

3 rbenv を再インストール

# rbenv を削除→インストール
brew remove rbenv && rm -rf $HOME/.rbenv && brew install rbenv

再インストールされた rbenv 動いていることを確認します.

$ rbenv --version
rbenv 1.1.2

4 ruby を再インストール

先程再インストールした rbenv を使って, ruby も同様に再インストールします.

しかし,普通に実行すると以下のようにエラーが出ます.

$ rbenv install 2.7.3

Downloading openssl-1.1.1l.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1
Installing openssl-1.1.1l...

BUILD FAILED (macOS 11.4 using ruby-build 20210825)

Inspect or clean up the working tree at /var/folders/8h/dn5r97217qjgq63xlzzyhx640000gn/T/ruby-build.20210905171050.42531.lZwJzF
Results logged to /var/folders/8h/dn5r97217qjgq63xlzzyhx640000gn/T/ruby-build.20210905171050.42531.log

Last 10 log lines:
  "_test_uint_eq", referenced from:
      _dh_test in dhtest.o
      _rfc5114_test in dhtest.o
ld: symbol(s) not found for architecture x86_64
make[1]: *** [test/destest] Error 1
clang-12: error: clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [test/dhtest] Error 1
make[1]: *** [test/d2i_test] Error 1
make: *** [all] Error 2

インターネット上に 同様の症状 が発生している記事を見つけたので,こちらを参考にします.

上記サイトによると, binutils 製の arranlib が悪さをしているらしいです.なので, macOS 標準のそれら (/usr/bin 以下) を使うように, PATH を書き換えてから実行します.

$ PATH="/usr/bin:$PATH" rbenv install 2.7.4

Downloading openssl-1.1.1l.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1
Installing openssl-1.1.1l...
Installed openssl-1.1.1l to /Users/kino-ma/.rbenv/versions/2.7.4

Downloading ruby-2.7.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.4.tar.bz2
Installing ruby-2.7.4...
ruby-build: using readline from homebrew
Installed ruby-2.7.4 to /Users/kino-ma/.rbenv/versions/2.7.4

成功しました.

デフォルトで今インストールしたバージョンを使うように設定します.

$ ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
# システムで入っている ruby を使っているらしい
$ rbenv versions
* system (set by /Users/kino-ma/.rbenv/version)
  2.7.4
$ rbenv global 2.7.4
$ ruby --version
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-darwin20]

5 cocoapods をインストール

新しくインストールした ruby 環境で cocoapods を使えるようにします.

$ sudo gem install cocoapods


出力
Fetching zeitwerk-2.4.2.gem
Fetching fuzzy_match-2.0.4.gem
Fetching concurrent-ruby-1.1.9.gem
Fetching i18n-1.8.10.gem
Fetching tzinfo-2.0.4.gem
Fetching activesupport-6.1.4.1.gem
Fetching nap-1.1.0.gem
Fetching httpclient-2.8.3.gem
Fetching algoliasearch-1.27.5.gem
Fetching ffi-1.15.4.gem
Fetching ethon-0.14.0.gem
Fetching typhoeus-1.4.0.gem
Fetching netrc-0.11.0.gem
Fetching public_suffix-4.0.6.gem
Fetching addressable-2.8.0.gem
Fetching cocoapods-core-1.11.0.gem
Fetching claide-1.0.3.gem
Fetching cocoapods-deintegrate-1.0.5.gem
Fetching cocoapods-downloader-1.5.0.gem
Fetching cocoapods-plugins-1.0.0.gem
Fetching cocoapods-search-1.0.1.gem
Fetching cocoapods-trunk-1.6.0.gem
Fetching cocoapods-try-1.2.0.gem
Fetching molinillo-0.8.0.gem
Fetching atomos-0.1.3.gem
Fetching CFPropertyList-3.0.3.gem
Fetching colored2-3.1.2.gem
Fetching nanaimo-0.3.0.gem
Fetching rexml-3.2.5.gem
Fetching xcodeproj-1.21.0.gem
Fetching escape-0.0.4.gem
Fetching fourflusher-2.3.1.gem
Fetching gh_inspector-1.1.3.gem
Fetching ruby-macho-2.5.1.gem
Fetching cocoapods-1.11.0.gem
Successfully installed concurrent-ruby-1.1.9
Successfully installed i18n-1.8.10
Successfully installed tzinfo-2.0.4
Successfully installed zeitwerk-2.4.2
Successfully installed activesupport-6.1.4.1
Successfully installed nap-1.1.0
Successfully installed fuzzy_match-2.0.4
Successfully installed httpclient-2.8.3
A new major version is available for Algolia! Please now use the https://rubygems.org/gems/algolia gem to get the latest features.
Successfully installed algoliasearch-1.27.5
Building native extensions. This could take a while...
Successfully installed ffi-1.15.4
Successfully installed ethon-0.14.0
Successfully installed typhoeus-1.4.0
Successfully installed netrc-0.11.0
Successfully installed public_suffix-4.0.6
Successfully installed addressable-2.8.0
Successfully installed cocoapods-core-1.11.0
Successfully installed claide-1.0.3
Successfully installed cocoapods-deintegrate-1.0.5
Successfully installed cocoapods-downloader-1.5.0
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-search-1.0.1
Successfully installed cocoapods-trunk-1.6.0
Successfully installed cocoapods-try-1.2.0
Successfully installed molinillo-0.8.0
Successfully installed atomos-0.1.3
Successfully installed CFPropertyList-3.0.3
Successfully installed colored2-3.1.2
Successfully installed nanaimo-0.3.0
Successfully installed rexml-3.2.5
Successfully installed xcodeproj-1.21.0
Successfully installed escape-0.0.4
Successfully installed fourflusher-2.3.1
Successfully installed gh_inspector-1.1.3
Successfully installed ruby-macho-2.5.1
Successfully installed cocoapods-1.11.0
35 gems installed


6 pod install する

最後に,ちゃんと pod コマンドが使えるかどうかを確認しておきます.

# React Native の iOS 用ディレクトリで実行する
$ cd $PROJ_DIR/ios && pod install


出力
Auto-linking React Native modules for target `MatchingApp`: RNCMaskedView, RNGestureHandler, RNScreens, RNVectorIcons, and react-native-safe-area-context
Analyzing dependencies
Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
Fetching podspec for `RCT-Folly` from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`
Fetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec`
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Installing CocoaAsyncSocket (7.6.5)
Installing DoubleConversion (1.1.6)
Installing FBLazyVector (0.65.1)
Installing FBReactNativeSpec (0.65.1)
Installing Flipper (0.93.0)
Installing Flipper-Boost-iOSX (1.76.0.1.11)
Installing Flipper-DoubleConversion (3.1.7)
Installing Flipper-Fmt (7.1.7)
Installing Flipper-Folly (2.6.7)
Installing Flipper-Glog (0.3.6)
Installing Flipper-PeerTalk (0.0.4)
Installing Flipper-RSocket (1.4.3)
Installing FlipperKit (0.93.0)
Installing OpenSSL-Universal (1.1.180)
Installing RCT-Folly (2021.04.26.00)
Installing RCTRequired (0.65.1)
Installing RCTTypeSafety (0.65.1)
Installing RNCMaskedView (0.1.11)
Installing RNGestureHandler (1.10.3)
Installing RNScreens (3.5.0)
Installing RNVectorIcons (8.1.0)
Installing React (0.65.1)
Installing React-Core (0.65.1)
Installing React-CoreModules (0.65.1)
Installing React-RCTActionSheet (0.65.1)
Installing React-RCTAnimation (0.65.1)
Installing React-RCTBlob (0.65.1)
Installing React-RCTImage (0.65.1)
Installing React-RCTLinking (0.65.1)
Installing React-RCTNetwork (0.65.1)
Installing React-RCTSettings (0.65.1)
Installing React-RCTText (0.65.1)
Installing React-RCTVibration (0.65.1)
Installing React-callinvoker (0.65.1)
Installing React-cxxreact (0.65.1)
Installing React-jsi (0.65.1)
Installing React-jsiexecutor (0.65.1)
Installing React-jsinspector (0.65.1)
Installing React-perflogger (0.65.1)
Installing React-runtimeexecutor (0.65.1)
Installing ReactCommon (0.65.1)
Installing Yoga (1.14.0)
Installing YogaKit (1.18.1)
Installing boost-for-react-native (1.63.0)
Installing fmt (6.2.1)
Installing glog (0.3.5)
Installing libevent (2.1.12)
Installing react-native-safe-area-context (3.3.0)
Generating Pods project
Integrating client project
Pod installation complete! There are 56 dependencies from the Podfile and 48 total pods installed.

[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.


正常に動いているようなので,これで環境の作り直しは完了です.

感想

以上の手順で pod を使えるようにするまでに計3日ほど,作業時間としては 10 時間以上は使ったかと思います.

普段 ruby を使わないのですが, React Native での開発のためにここまでしなければいけないとは思いませんでした.しんどかったです.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0