Vscode-ruby: Ryby User Path

Created on 27 Jun 2017  路  4Comments  路  Source: rubyide/vscode-ruby

VSCode Version: Code 1.13.1
OS Version: Linux x64 4.9.34-1-MANJARO

Steps to Reproduce:

/usr/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- telegram/bot (LoadError) from /usr/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:inrequire'

$ env

MY_RUBY_HOME=/home/user/.rvm/rubies/ruby-2.4.1
GEM_PATH=/home/user/.rvm/gems/ruby-2.4.1:/home/user/.rvm/gems/ruby-2.4.1@global
GEM_HOME=/home/user/.rvm/gems/ruby-2.4.1

Visual Studio Code how to configure to use this path?

need-more-info

Most helpful comment

I have found a tricks.

a) Open Terminal.app and cd (change directory) to your project. This will setup the right rvm environment (according the ruby version in the Gemfile). Once everything in in place

b) Code .

The last command will launch Visual Code Studio with all the PATH, GEM_PATH etc. set by rvm.

All 4 comments

I have the same problem using Mac OS X and RVM. The GEM_PATH is boggus in the VS Code environment.

Using Terminal.app:

Using 'gem env':

  • GEM PATHS:

    • /Users/ycrepeau/.rvm/gems/ruby-2.3.1

    • /Users/ycrepeau/.rvm/gems/ruby-2.3.1@global

Using 'echo $GEM_PATH:
/Users/ycrepeau/.rvm/gems/ruby-2.3.1:/Users/ycrepeau/.rvm/gems/ruby-2.3.1@global

When I start the Ruby debugger in Visual Studio, it fails immediately. By forcing my way using:
"useBundler": true,
"pathToBundler": "/Users/ycrepeau/.rvm/gems/ruby-2.3.1/bin/bundler",

the debuger starts and stops almost immediately:

/Users/ycrepeau/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in to_specs': Could not find 'bundler' (>= 0.a) among 16 total gem(s) (Gem::LoadError) Checked in 'GEM_PATH=/Users/ycrepeau/.rvm/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0', executegem envfor more information from /Users/ycrepeau/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:into_spec'
from /Users/ycrepeau/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in gem' from /Users/ycrepeau/.rvm/gems/ruby-2.3.1/bin/bundler:22:in

'

As you can see, the Checked in 'GEM_PATH=' in the error is DIFFERENT from the one used in the terminal.

My hypothesis is that all that stuff is related to RVM (Ruby Version Manager). When I use a command in the Terminal, the proper PATHs (including GEM_PATH) are set by rvm using the Ruby version given in the Gemfile. So, if I have many projects using different versions of ruby, the different PATHs are reset each time I switch from one project directory to another.

This is this part that is not set properly when using vscode-ruby in Visual Studio Code.

@webmastak @ycrepeau can you check whether https://github.com/rubyide/vscode-ruby/issues/62#issuecomment-301198259 helps, by setting envs to launch.json?

I have found a tricks.

a) Open Terminal.app and cd (change directory) to your project. This will setup the right rvm environment (according the ruby version in the Gemfile). Once everything in in place

b) Code .

The last command will launch Visual Code Studio with all the PATH, GEM_PATH etc. set by rvm.

Closing for issue cleanup. Apologies if this is still an issue. We are working to improve the core extension experience.

Was this page helpful?
0 / 5 - 0 ratings