2
2

More than 3 years have passed since last update.

MacでBundle installでエラーが表示される

Last updated at Posted at 2021-03-19

実行環境

macOS Big Sur
ruby 2.6.5

やりたいこと

アプリの依存関係をローカルにインストールすること

エラーの経緯

rubyアプリをHerokuにデプロイしたかったので、Herokuの公式チュートリアルで指示通り進めていたときに、このエラーが発生しました。
該当箇所は「アプリの依存関係を宣言する」。 ここまでで、git cloneで公式の用意したサンプルアプリをローカルにインストールした上しています。
postgresqlの存在をしっかりローカルで確認した上で、今回の元凶 bundle install様が降臨されました。

実際のエラー文

takayamatoranosuke@ttmbp ~ % bundle install
Could not locate Gemfile
takayamatoranosuke@ttmbp ~ % cd dev
takayamatoranosuke@ttmbp dev % cd ruby-getting-started
takayamatoranosuke@ttmbp ruby-getting-started % bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.3
Using concurrent-ruby 1.1.8
Using i18n 1.8.9
Using minitest 5.14.4
Using thread_safe 0.3.6
Using tzinfo 1.2.9
Using activesupport 5.2.4.5
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.5.0
Using racc 1.5.2
Using nokogiri 1.11.2 (x86_64-darwin)
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.9.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.2.4.5
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 5.2.4.5
Fetching nio4r 2.5.7
Installing nio4r 2.5.7 with native extensions
Errno::EACCES: Permission denied @ rb_sysopen -
/Users/takayamatoranosuke/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/nio4r-2.5.7/.github/workflows/workflow.yml
An error occurred while installing nio4r (2.5.7), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.5.7' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 5.2.4.5, which depends on
    actioncable was resolved to 5.2.4.5, which depends on
      nio4r

このエラー文を見て「nio4rのエラーか!」と思いいろいろ調べたのですが、どうやら問題の本質は違うところにあったようです。

どうやって解決したのか?

以下のコマンドを入力+gemfile.lockの削除をしたところ、解決しました

$ ruby -v
$ rbenv uninstall 2.6.5(既にインストールされていた実行環境のバージョン)
$ rbenv install 2.6.5(再インストール)
$ ruby -v(インストールの確認)

$ which ruby
/Users/takayamatoranosuke/.rbenv/shims/ruby
$ which bundle(rubyとbundleが同じ場所にいることを確認)
/Users/takayamatoranosuke/.rbenv/shims/bundle

$ cd ~/my_app
$ rbenv exec gem install bundler
$ rbenv rehash
$ bundle install --path vendor/bundle
~~
Bundle complete! 13 Gemfile dependencies, 65 gems now installed.
Bundled gems are installed into `./vendor/bundle`

エラーの考察

おそらく、whichで確認したrubyとbundleの場所が違ったから起きた問題なのではないか、と考えています。
これはつまり、ローカル環境で自分が既にインストールしていたrubyと、サンプルアプリのrubyが違い、なおかつbundleが使っていたrubyは自分が既にインストールしていた方だった、ということがエラーを起こしていたものと考えられます。

2
2
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
2
2