概要
- 以下の開発環境で開発を進めており、ジェムの
rails-i18n
を導入しようとした- Windows11
- Ubuntsu
- docker
- Rails7.2.1
- docker
- Ubuntsu
- Windows11
bundle install
でエラーになる
確認したエラー
rails@XXXXXXXXXXX:/myapp$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Fetching rails-i18n 7.0.9
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/bundle/cache/rails-i18n-7.0.9.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/bundle/cache/rails-i18n-7.0.9.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/bundle/cache/rails-i18n-7.0.9.gem`. It is likely that you need to grant write permissions for that path.
Bundler::PermissionError: There was an error while trying to write to
`/usr/local/bundle/cache/rails-i18n-7.0.9.gem`. It is likely that you need to grant write permissions
for that path.
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/shared_helpers.rb:107:in `rescue in
filesystem_access'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/shared_helpers.rb:104:in `filesystem_access'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/rubygems_integration.rb:445:in `block in
download_gem'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/retry.rb:40:in `run'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/retry.rb:30:in `attempt'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/rubygems_integration.rb:437:in `download_gem'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/source/rubygems.rb:482:in `download_gem'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/source/rubygems.rb:439:in `fetch_gem'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/source/rubygems.rb:423:in `fetch_gem_if_possible'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/source/rubygems.rb:162:in `install'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/installer/gem_installer.rb:55:in `install'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/installer/gem_installer.rb:17:in
`install_from_spec'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/installer/parallel_installer.rb:133:in `do_install'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/installer/parallel_installer.rb:124:in `block in
worker_pool'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/worker.rb:62:in `apply_func'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/worker.rb:57:in `block in process_queue'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/worker.rb:54:in `loop'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/worker.rb:54:in `process_queue'
/usr/local/bundle/gems/bundler-2.5.19/lib/bundler/worker.rb:90:in `block (2 levels) in
create_threads'
An error occurred while installing rails-i18n (7.0.9), and Bundler cannot continue.
In Gemfile:
rails-i18n
エラー文にあたりをつける
- とりあえずは原因らしき文言を見つけて解決を目指すこととした
- 以下の文言より「書き込みの権限が無い」という旨であることを把握したのでさらに調査を進めた
原因らしき文言
Bundler::PermissionError: There was an error while trying to write to
`/usr/local/bundle/cache/rails-i18n-7.0.9.gem`. It is likely that you need to grant write permissions
for that path.
シンプルに管理者権限では無かっただけだった
エラー文にもあった /usr/local/bundle/cache/
までのフォルダーおよびファイルの所有者や権限を調べていて root
であることに気づいた
- 以下のように
root
ユーザーで実行していなかったからではと考えた (rails
ユーザーだったの原因)
rails@XXXXXXXXXXX:/myapp$ bundle install
root
ユーザーで実行
- コンテナにアクセスする際
root
ユーザーでアクセスするようにコマンドを見直した
今まで
docker compose exec web bash
root ユーザーとして
docker compose exec -it -u root web bash
実行結果
- 結果として問題なく導入することが出来た
実行結果
root@XXXXXXXXXXX:/myapp# bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Fetching rails-i18n 7.0.9
Installing rails-i18n 7.0.9
Bundle complete! 22 Gemfile dependencies, 110 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
参考資料・参考記事