在 Linux 的 Windows 子系统上安装带有本机扩展的 Ruby gem 时,是否有可靠的方法来避免权限被拒绝的错误?

Is there a reliable way to avoid permission denied errors when installing Ruby gems with native extensions on Windows Subsystem for Linux?

我希望 WSL2 能解决这些问题并在接下来的 6 个月左右让这个问题过时,但与此同时,我对 运行ning bleeding edge 或其他预览版本感到不舒服Windows 在我的主要笔记本电脑上。

有时,当我在 WSL 中安装 Ruby gems(bundle installbundle install --path=vendor/bundle)时,我会在安装时遇到 Permission denied 错误gem 带有本机扩展名。

此错误的最新版本是:

Permission denied @ rb_file_s_rename - (./.gem.20191006-12131-11th7ub/byebug, /home/thomasowens/project/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/byebug-11.0.1/byebug)

为了解决它,我简单地删除了 /home/thomasowens/project/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/byebug-11.0.1/byebug,重新运行 bundle 命令,它成功了。有时,我需要多次执行此操作,但它通常有效。

最后,我可以正确安装所有 gem,但是在设置新项目时很难,并且有许多 gem 具有本机扩展。当我引入新的 gem 或更新导致需要更新本机依赖项的 gem 时也是如此。

我对这个问题了解不多,但我想知道是否可以做些什么来减轻需要 运行 bundle install 多次才能获得在 WSL 下设置和 运行ning 项目。

我遇到的问题可能与Visual Studio代码的文件监视有关。它反映在针对 WSL 的两个 GitHub 问题中 - 1956 and 3395. Visual Studio Code has remote.WSL.fileWatcher.polling, which can be enabled which works around this issue. However, the documentation states that there is a performance impact for large workspaces 并且可能还需要调整 remote.WSL.fileWatcher.pollingInterval 设置。 WSL2 将解决这些问题。

自启用此标志以来,我在使用 VS Code 时没有看到错误 运行。


现在 WSL2 已经出来了,我可以禁用这个标志并且问题没有再次出现。看来,如果您可以升级到 WSL2,那可能是首选解决方案。但是,对于尚未升级或无法升级的任何人,切换 remote.WSL.fileWatcher.pollingremote.WSL.fileWatcher.pollingInterval 应该是好的。