I use RVM to manage Ruby versions.
In my project I use Bundler to manage gems for the project.
RVM also have gemsets.
Gem in gemset don't have a connection with Bundler's gem. ← Is this correct?
I came to this conclusion because gem files stored in different locations:
RVM gemset: ~/.rvm/gems/ruby-2.0.0-p247@myApp
Bundler: [my_app_dir]/vendor/bundle/gems
So app uses Bundler gems, not RVM gemset gems.
But when I add gem to my Gemfile, RubyMine IDE shows me warning, that this gem is not in RVM gemset. So I add this gem to RVM gemset also (just to get rid of this warning).
So the questions are:
- Is there any good reason to add gems in both places (RVM Gemset and Gemfile)?
- If no, then why RubyMine warning me about this?
The gemset is incidental, the Gemfile is absolutely the place to declare your dependencies. Where you store those gems is up to you.
It sounds like Bundler is configured to store them in a project-local path, but you're expecting them to be in a gemset. Bundler got that configuration by running
bundle install --path vendor/bundle/gems
at some point. It stores that configuration in its project configuration file atproject_dir/.bundle/config
:I'm unfamiliar with Rubymine, but if you run the Rails server using Bundler (i.e.
bundle exec rails server
) you can ignore that warning. Bundler will correctly load the gems listed in the Gemfile.If you want to use a gemset instead of the Bundler cache, you can just remove that line from the Bundler configuration file and reinstall your gems with
bundle install
.My guess is that Rubymine is not reading the Bundler project configuration (in
project_path/.bundle/config
) and does not understand where the gems are installed.You (or if you are working in a team, somebody of your team) has once done a
bundle install
and specified a installation-folder. In your casevendor/bundle/gems
. Bundle remembers this setting and all next invocations of the bundle command will use the same path.There is a good reason to do it that way: your application-folder will contain all requirements and will be easier to redistribute (for instance).
Now if you want that bundle installs your gems in the normal locations, you can do the following:
bundle install --system
which will use the default location.bundle/config
and you can check that one as well. Normally it is not needed, sincebundle install --system
will set that correctly again.vendor/bundle/gems
folderSo this just took me 3 days, since nothing else I was finding here was helping. I also run multiple projects through RubyMine at the same time (and different versions) so setting my GEM_PATH and launching from command-line doesn't work for me. I use IntelliJ with RM plugin, this should work on RM standalone.
Bundler seems to install custom gems, or gems from custom repos, in a different directory than gems from rubygems, or github.
One thing I wasn't able to fix is in the GEMFILE, I have some custom git_sources, and rubymine highlights those and gives me the warning that it cannot find the gem in my bundle (you can ignore this warning; unless the gem doesn't install at all):
However Bundler installed it, and ruby is able to load it.
# TLDR: Steps to have RUBYMine find extra gems, and show up in external libs
Project Structure
dialog >Platform SDKs
> Choose the GEMSET you're working with/Users/YOURUSER/.rvm/environments/ruby-{version}\@yourgemset/bundler/gems
to your classpathProject Structure
Dialog >Project Settings
>Project
In the above instructions that when you run bundle install (from terminal or RM) it works successfully, and that you have RVM correctly setup, and gemset already created
I hope this helps! Let me know if I should clarify anything (happy NYE)
No, something's wrong, you shouldn't have anything under vendor/bundle, it should all be under ~/.rvm/gems/ruby-2.0.0-p247@myApp and perhaps ~/.rvm/gems/ruby-2.0.0-p247@global assuming your .rvmrc (or.ruby-version) is setup correctly.
What does "gem env" look like? Also "bundle env"?