rails sudo + <any command> will throw an error of different ruby versions (installed vs. Gemfile)

99 views Asked by At

Every time a command is executes with sudo (for instance: sudo rake db:seed or sudo bundle) an error is thrown: Your Ruby version is 1.9.3, but your Gemfile specified 2.2.1. When I hit ruby -v it's ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] so I guess it's not the problem. In addition I use rvm to manage the versions and when I list them with rvm list the output is:

rvm rubies

=* ruby-2.2.1 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

So what causes this error to be thrown? It has something to do with the root user configuration?

2

There are 2 answers

1
hedgesky On

You can try command rvmsudo (more information here).

3
aaron-coding On

You can use sudo bundle exec rake db:seed, sudo bundle exec bundle.

Using bundle exec makes everything standardized according to your current Gemfile. See: What does bundle exec rake mean?