Search code examples
ruby-on-railsrubyrubygemsrubocop

Can't seem to install rubocop gem using Rails 4


I tried installing rubocop by adding the suggested line to my Rails project's Gemfile:

gem 'rubocop', require: false

After running bundle, it installs and is visible in my Gemfile.lock.

However when running $ rubocop from my application's root I receive this error:

-bash: rubocop: command not found

I tried running $ which rubocop, and nothing comes up.

I've also tried running $ gem install rubocop, with no difference in behavior.

Here is the excerpt from my Gemfile.lock:

rubocop (0.27.0)
  astrolabe (~> 1.3)
  parser (>= 2.2.0.pre.6, < 3.0)
  powerpack (~> 0.0.6)
  rainbow (>= 1.99.1, < 3.0)
  ruby-progressbar (~> 1.4)

Solution

  • You have to run this command:

    source ~/.bashrc
    

    As right after running $ bundle command the gem was installed and its environment was set in your ~/.bashrc, but since you continued to use the old bash session you didn't get rubocop available as a command in your bash. Hence, either re-login in your bash(close and then open the terminal again) or run the command stated above.