'rubocop on VScode not working.Error "rubocop is not executable"
Recently I installed rubocop on vscode. However, it doesn't work.Error message is below.
rubocop is not excutable
execute path is empty! please check ruby.rubocop.executePath
How should I fix it? I searched some articles, never solved...
cf. vscode-ruby-rubocop https://github.com/misogi/vscode-ruby-rubocop
Solution 1:[1]
tl;dr
Make sure you installed Rubocop in the first place.
VS Code Rubocop Tutorial
Install Rubocop
gem install rubocop
You can check that it works properly like this:
rubocop -v
Install VS Code extension
Search for ruby-rubocop in the marketplace and install it.
Configure Rubocop for your project
Add a .rubocop.yml file to your project's root. You can see all the configuration options and how such a file should look like in the default config file. Be aware that if there are outdated or wrong rules in the file, you will get an error and Rubocop won't work. VS Code will alert you about this:
Solution 2:[2]
The accepted answer didn't work for me. However, I did find a comment by jdarnok on this GitHub issue that worked for me.
First, to get the user's path of the program file, I ran:
rbenv which rubocop
which gave me this result:
/Users/<your username>/.rbenv/versions/2.6.2/gemsets/Rails4.2_EnergyLink/bin/rubocop
Then I ran:
which rubocop
which gave me this result:
/Users/<your username>/.rbenv/shims/rubocop
SOLUTION
In the settings of VS Code under Ruby > Rubocop: Execute Path I pasted:
/Users/<your username>/.rbenv/shims/
Other potential solutions
This Stackoverflow post refers to a few other potential solutions, such as:
- Replace
binin the PATH withwrappers - Refresh
executable hooks - Update bundler
- Update gems
Solution 3:[3]
Take a look to the configuration docs.
{
// If not specified searches for 'rubocop' executable available on PATH (default and recommended)
"ruby.rubocop.executePath": "",
...
}
So, by default executePath won't be setted, because it's expecting you to have the rubocop executable within your PATH.
In a simply way, there are two things you can do, add the rubocop executable path to your PATH, or add it within the package options.
You can check for the rubocop executable directory with which rubocop (then copy and paste).
Solution 4:[4]
Short answer: Try starting VSCode a different way.
Explanation: A process inherits all the environment configuration it was started from. If rubocop is installed in your global environment, then, great no matter how you start VSCode rubocop will be available to the plug-in. On the downside, rubocop is now available to everything, most of which will never need it, and all the things that do use it need to require the same version of rubocop.
If rubocop was installed in a gemset using a ruby manager, or you have something like a dot-file manager that manipulates your environment, rubocop might not be in the PATH when you start VSCode.
I start VSCode from the terminal, always. I open a terminal and cd into my project folder. My ruby manager (rvm) and dot-file manager (direnv) automatically add and change some variables in the environment. Then I run code . to start VSCode with my project. This ensures VSCode is running in the same environment configuration as my app will run.
Solution 5:[5]
When I ran into this issue, it was because the version my bundle wanted and the version that rubocop in vscode wanted were different.
In the vscode rubocop settings, checking `execute rubocop using bundler (ie 'bundle exec rubocop') and eliminating the execute path worked for me. Ruby > Rubocop: Use Bundler checkbox
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | |
| Solution 3 | de-russification |
| Solution 4 | IAmNaN |
| Solution 5 | atlash |


