Search code examples
ruby-on-railsrubybundler

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


I am new to Rails , I ran bundler as root by mistake & now it is not working correctly. I tried to use gem uninstall bundler then gem install bundler but still it is not fixed. How to make bundler work again for non root users (after mistakenly using it with root)?

Note: I have installed and use rbenv, but after installing some gems on the system directly

The error that happens is that bundle doctor shows correct missing gems but sudo bundle doctor doesn't as shown below

~/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)

using sudo ~/my_ruby_projects/myblog3$ sudo 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 Gemfile's dependencies are satisfied No issues found with the installed bundle

Thanks for your help

update: I knew that bundle with sudo is correct since it gave the real gems that rails tells me they are missing , if I use bundle install without sudo it gives error as below (even if change it to 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.

for sudo bundle install it says all is installed but then rails throws error that I need to install 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.

Update 2: rails s was giving error that gem files are missing but **sudo** rails s worked without errors


Solution

  • You should try changing the owner and setting the correct permissions for your ~/.bundle.

    Try:

    sudo chown -R <youruser> ~/.bundle
    

    Followed by:

    sudo chmod -R 655 ~/.bundle