如何让非 root 用户再次使用捆绑器? (错误地与root一起使用后)

How to make bundler work again for non root users ? (after mistakenly using it with root)

我是 Rails 的新手,我 运行 捆绑器错误地作为 root 并且现在它无法正常工作。我尝试使用 gem uninstall bundler 然后 gem install bundler 但它仍然没有修复。 如何让非 root 用户再次使用 bundler(在 root 用户错误地使用它之后)?

注意: 我已经安装并使用了rbenv,但是在系统上直接安装了一些gem之后

发生的错误是 bundle doctor 显示正确的缺失 gems 但 sudo bundle doctor 没有显示如下

~/my_ruby_projects/myblog3$ bundle doctor
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
The following gems are missing
 * execjs (2.7.0)
 * coffee-script (2.4.1)
 * coffee-rails (4.2.2)
 * font-awesome-rails (4.7.0.2)
 * temple (0.8.0)

使用sudo ~/my_ruby_projects/myblog3$ 须藤捆绑医生 最新的捆绑器是 1.16.0.pre.1,但您当前使用的是 运行ning 1.15.4。 要更新,运行 gem install bundler --pre 满足 Gemfile 的依赖关系 已安装的捆绑包未发现任何问题

感谢您的帮助

更新: 我知道带 sudo 的 bundle 是正确的,因为它给出了真正的 gems rails 告诉我它们丢失了,如果我使用不带 sudo 的 bundle install 它会给出如下错误(即使将其更改为 chmod 777)

~/my_ruby_projects/myblog3$ bundle install
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
There was an error while trying to write to `/home/usrname/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/versions`. It is likely that you
need to grant write permissions for that path.

对于 sudo bundle install 它说所有都已安装但是 rails 抛出我需要安装 gems 的错误(which bundle doctor gave without sudo)

/my_ruby_projects/myblog3$ sudo bundle install
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Using rake 12.0.0
Using concurrent-ruby 1.0.5
# many other gems
Using redis-rails 5.0.2
Using rails_admin 1.2.0
Bundle complete! 30 Gemfile dependencies, 98 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

更新 2: rails s 给出 gem 文件丢失的错误 但是 **sudo** rails s 工作没有错误

您应该尝试更改所有者并为您的~/.bundle设置正确的权限。

尝试:

sudo chown -R <youruser> ~/.bundle

其次是:

sudo chmod -R 655 ~/.bundle