I'm having an issue with VSCode on Ubuntu. I have the ruby extension and the ruby-rubocop extensions installed but when I run the rubocop extension on save, I get 2 errors
My project is using ruby version 2.7.6 installed via rbenv. 2.5.1 is an old version of ruby I had installed which I since removed. I don't understand why VSCode is trying to use version 2.5.1. When I run rubocop via a bash shell, it runs as expected. rbenv local
and rbenv global
are all set to 2.7.6
and my project as a .ruby-version
file with 2.7.6 set.
When I run echo $RBENV_VERSION
in a bash shell, I get nothing returned, but if I run this in a terminal shell within VSCode, it returns 2.5.1.
How do I get VSCode to use the correct rbenv version?
Solution:
I found that the issue was that I had for some reason defined the RBENV version in my .bash_profile file
I've had this problem as well. Further symptoms: rbenv shell
asked me to perform rbenv init. This happend both inside and ouside VS Code. I was sure I'd done that in the past, but the init line no longer was in my shell init script.
The solution was to run rbenv init
and follow the instructions (i.e. adding the suggested line to .bashrc
, or the appropriate file for your shell).
This sets $RBENV_VERSION
to the correct version and thus fixes the problem. I am not aware of why thie problem appears only in VS Code but not in the regular terminal.