LoginSignup
17
14

More than 3 years have passed since last update.

Cocoapodsのインストールでハマった件

Last updated at Posted at 2019-08-13

概要

 iOSアプリ作成でswiftを勉強をしているのですが、教材通りにCocoapodsのインストールしたらエラーが出て、ネットで調べていろいろ試した結果、インストールができてしまったのでメモレベルで残したいと思います。

実行コマンド

 コマンドは以下の通り。

% sudo gem update --system
% sudo gem install cocoapods
% pod setup

gemのアップデート

 実行したコマンドは以下の通りです。

% sudo gem update --system
Password:
Updating rubygems-update
Fetching: rubygems-update-3.0.4.gem (100%)
Successfully installed rubygems-update-3.0.4
Parsing documentation for rubygems-update-3.0.4
Installing ri documentation for rubygems-update-3.0.4
Installing darkfish documentation for rubygems-update-3.0.4
Done installing documentation for rubygems-update after 38 seconds
Parsing documentation for rubygems-update-3.0.4
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.0.4
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem

パスワードを聞いてきたのでログインしているアカウントのパスワードを入力。ログが進んだのであっていると思われます。
実行結果はオペレーションが許可されていないみたいなエラーになりました:scream:

試したこと

その1 バージョン名を指定する

 とりあえずバージョン名を指定するとできるかもしれないと記事があったので試してみました。実行したコマンドは以下の通り。

% sudo gem update --system 2.7.4

今度は違うエラーが出ました:worried:(この時はパスワードの入力は要求されなかった)

Updating rubygems-update
Fetching rubygems-update-2.7.4.gem
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

/usr/binのディレクトリーに書き込み権限がないと言うエラーになりました。

その2 パスも指定する

 それでも出来なかった時にパスの指定をすると出来たと言う書き込みがあったので試してみました。バージョン名も変更してみました。実行したコマンドは以下の通り。

% sudo gem update --system 2.7.8 -n /usr/local/bin

振り出しに戻ったようなエラーとなりました:scream:

Updating rubygems-update
Fetching rubygems-update-2.7.8.gem
Successfully installed rubygems-update-2.7.8
Parsing documentation for rubygems-update-2.7.8
Installing ri documentation for rubygems-update-2.7.8
Installing darkfish documentation for rubygems-update-2.7.8
Done installing documentation for rubygems-update after 34 seconds
Parsing documentation for rubygems-update-2.7.8
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 2.7.8
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem

その3 バージョン名を変えてみた

 指定したバージョンがまずかったのかを確認するために、バージョン名だけを変更して実行してみたが、同じ結果となりました。

% sudo gem update --system 2.7.4 -n /usr/local/bin
Password:
Updating rubygems-update
Successfully installed rubygems-update-2.7.4
Parsing documentation for rubygems-update-2.7.4
Installing ri documentation for rubygems-update-2.7.4
Installing darkfish documentation for rubygems-update-2.7.4
Done installing documentation for rubygems-update after 29 seconds
Parsing documentation for rubygems-update-2.7.4
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 2.7.4
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem

(この時はパスワード入力を要求されました。同じエラーなので関係ないのか?)

その4 バージョン名を指定しない

 今度はバージョン名を指定せずパスだけ指示して実行してみたが結果は変わりませんでした:confounded:

% sudo gem update --system -n /usr/local/bin
Updating rubygems-update
Successfully installed rubygems-update-3.0.4
Parsing documentation for rubygems-update-3.0.4
Done installing documentation for rubygems-update after 0 seconds
Parsing documentation for rubygems-update-3.0.4
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.0.4
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem

その5 再度 その4と同じコマンド

 ネットでエラー内容についていろいろ調べてみたらその4で実行したコマンドでうまく出来たと言う記事をいくつかあったので試しに、再度同じコマンドを実行してみたら、結果が以下の通り変わりました:open_mouth:

% sudo gem update --system -n /usr/local/bin
Password:
Latest version already installed. Done.

何故か知らないが、インストールされていると結果が変わりました:laughing:
(あまり関係なさそうですが、この時はパスワード入力要求があったのでログインアカウントのパスワードを入力してみました。)

もしやと思い、そのあとCocoapodsのインストールを試みてみました。

Cocoapodsのインストール

 実行してみたら、どこかでみたようなエラーになりました:persevere:

% sudo gem install cocoapods
Fetching thread_safe-0.3.6.gem
Fetching concurrent-ruby-1.1.5.gem
   : (省略)
Fetching gh_inspector-1.1.3.gem
Fetching escape-0.0.4.gem
Successfully installed thread_safe-0.3.6
Successfully installed tzinfo-1.2.5
Successfully installed concurrent-ruby-1.1.5
Successfully installed i18n-0.9.5
Successfully installed activesupport-4.2.11.1
Successfully installed nap-1.1.0
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

試したこと

パスを指定する。

 gemのアップデートでパスを指定すると何故かうまくいったので同じようにパスを指定してみました。根拠はなくただのカンですが、、、:sweat:

% sudo gem install cocoapods -n /usr/local/bin
Successfully installed fuzzy_match-2.0.4
  : (省略)
Parsing documentation for cocoapods-1.7.5
Installing ri documentation for cocoapods-1.7.5
Done installing documentation for fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 8 seconds
22 gems installed

エラーという文字がないので出来たっぽい結果になりました:laughing:

セットアップ実行

 セットアップを実行しました。

% pod setup
Setting up CocoaPods master repo
  $ /usr/local/bin/git clone https://github.com/CocoaPods/Specs.git --progress
  -- master
  Cloning into 'master'...
  remote: Enumerating objects: 327, done.        
  remote: Counting objects: 100% (327/327), done.        
  remote: Compressing objects: 100% (310/310), done.        
  remote: Total 3371567 (delta 109), reused 3 (delta 3), pack-reused 3371240        
  Receiving objects: 100% (3371567/3371567), 672.62 MiB | 1.47 MiB/s, done.
  Resolving deltas: 100% (2035048/2035048), done.
  Checking out files: 100% (350474/350474), done.

CocoaPods 1.8.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.8.0.beta.1

Setup completed

コンプリートという文字が出たのでインストールできたみたいです。

最後に

 gemのアップデートでハマったのですが、もしかすると最初のコマンド実行でのエラーを無視しして進めたら苦労なく出来ていたのではないかと思うところです。。。

以上

17
14
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
17
14