WSLで、bundle install 時のErrno::EPERM: Operation not permittedを解決したのでメモ

環境

  • wsl2
  • windows10 pro
  • ruby 3.0.2
  • Bundler version 2.3.5

状況

Gemfileを作成後、Bundle installしようとするとエラーになる。 Gemfile.lockも作成されない。

解決方法

Errno::EPERM: Operation not permitted @ apply2files - /mnt/c/Users/memoma/vendor/bundle/ruby/3.0.0/gems/tilt-2.0.10/COPYING

このエラーメッセージの文章から、どうやらGemfileへの書き込み権限が無いために、書き込み出来なくてエラーになっていると推測。

けれども、Windowsファイルシステム(/mnt/c以下など)のファイルに対してはchmodchownは効かない(mountコマンドを使えばできるかも)

そこで、$ touch /etc/wsl.confでファイルを作成して、以下の設定を書き込み、windowsを再起動したところ、 bundle installできた。

$ cat /etc/wsl.conf
[automount]
options = "metadata,umask=022"
  • umaskはすべてのファイルに適用

  • 022はデータを書き込むのは自分だけだが、だれでもデータを読み取ることができる許可

資料

Gemfileの中身

$ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

# gem "rails"

gem "webrick"
gem "sinatra"

エラーメッセージ

kkk@DESKTOP-HNNRMPU:/mnt/c/Users/memoma$ bundle i
Fetching gem metadata from https://rubygems.org/....
Resolving dependencies...
Using bundler 2.3.6
Fetching rack 2.2.3
Fetching webrick 1.7.0
Fetching ruby2_keywords 0.0.5
Fetching tilt 2.0.10
Installing ruby2_keywords 0.0.5
Installing tilt 2.0.10
Installing rack 2.2.3
Installing webrick 1.7.0
--- ERROR REPORT TEMPLATE -------------------------------------------------------

``
Errno::EPERM: Operation not permitted @ apply2files - /mnt/c/Users/memoma/vendor/bundle/ruby/3.0.0/gems/tilt-2.0.10/COPYING
  /home/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1346:in `chmod'
  /home/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1346:in `chmod'
  
()

### Gemfile.lock

``
<No /mnt/c/Users/memoma/Gemfile.lock found>
``

--- TEMPLATE END ----------------------------------------------------------------

Unfortunately, an unexpected error occurred, and Bundler cannot continue.

First, try this link to see if there are any existing issue reports for this error:
https://github.com/rubygems/rubygems/search?q=Operation+not+permitted+%40+apply2files+-+%2Fmnt%2Fc%2FUsers%2Fkei-c%2Fmemoma%2Fvendor%2Fbundle%2Fruby%2F3.0.0%2Fgems%2Ftilt-2.0.10%2FCOPYING&type=Issues

If there aren't any reports for this error yet, please fill in the new issue form located at https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md, and copy and paste the report template above in there.

参考にしたサイト