How to find the single gem installed when only specifying a Ruby version in a Gemfile - ruby

I'm running Ruby 2.7.0, Bundler 2.1.4 and macOS 10.15.3.
I have a Gemfile in an otherwise empty folder which is only specifying the Ruby version:
ruby '2.7.0'
When I run bundle, or bundle install, I get:
% bundle install
The Gemfile specifies no dependencies
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
However, bundle list gives me:
% bundle list
No gems in the Gemfile
What is the one installed gem? Where would I find it?

It looks like Bundler itself.
These are the links to the code for the output from the bundle install command:
https://github.com/rubygems/bundler/blob/v2.1.4/lib/bundler/cli/install.rb#L69
https://github.com/rubygems/bundler/blob/v2.1.4/lib/bundler/cli/install.rb#L119-L122
https://github.com/rubygems/bundler/blob/v2.1.4/lib/bundler/definition.rb#L180-L183
The important part is the last part where specs["bundler"] is empty then it assigns bundler spec to specs["bundler"] so specs.count returns at least 1.

You can try with:
bundle show
bundle show name_of_gem

Related

Bundler install custom path issue

gem env shows
GEM PATHS:
/usr/local/share/gems
I would like to use bundle install --deployment --path=/usr/local/share/gems to install my bundled gems.
The problem is that the bundle install creates a folder ruby and puts the gems folder inside the ruby folder.
When this happens my ruby code is unable to find the gems in its default path.
Looks like I am missing some configuration parameter. Help please.
Maurício Linhares comments in the question has resolved the issue.
When using bundler to install gems use bundle exec ruby. When the bundle install --deployment happens the path information goes into .bundle/config
bundle exec ruby path-to-ruby-script.rb
The above execution Will find the gems installed by the bundle command.
Alternatively, if you want to force installation to the system gem location, I believe bundle install --deployment --system will do what you want.

Bundler installing gem that's already installed

I believe I'm misunderstanding the way bundler works, but from the bundle install documentation it seems to indicate bundler will use locally installed system gems.
...
--system: Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application
...
The --system option is the default. Pass it to switch back after using the --path option as described below.
I'm not using rbenv/rvm or any other Ruby version manager. I'm using ChefDK as my primary development environment, which ships with Ruby and a bunch of preinstalled gems.
The full contents of the Gemfile, there is no Gemfile.lock yet.
source 'https://rubygems.org'
gem 'nokogiri', '1.6.3.1'
Local nokogiri installed
$ gem list --local | grep nokogiri
nokogiri (1.6.6.2, 1.6.3.1, 1.5.5)
System Gem location has nokogiri 1.6.3.1 installed
$ echo $GEM_HOME
/Users/arthur/.chefdk/gem/ruby/2.1.0
$ find /Users/arthur/.chefdk/gem/ruby/2.1.0 | grep nokogiri | grep 1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/cache/nokogiri-1.6.3.1.gem
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1/mkmf.log
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.autotest
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.editorconfig
...
However, when I run a bundle install, it tries to install and compile libxml2 for nokogiri.
$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using mini_portile 0.6.0
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT! Nokogiri builds and uses a packaged version of libxml2.
...
What am I missing? How can I force bundler to use the already installed nokogiri 1.6.3.1 (that ships with ChefDK)? I'm trying to avoid having nokogiri compile libxml2 because that fails consistently on many different developer/operations workstations and has caused no end of grief. Thanks.
Edit
Thanks to Tim Moore, using bundle env I noticed in the output that bundler had shared gems disabled.
$ bundle env
Bundler 1.7.12
Ruby 2.1.4 (2014-10-27 patchlevel 265) [x86_64-darwin12.0]
Rubygems 2.4.4
GEM_HOME /Users/arthur/.chefdk/gem/ruby/2.1.0
GEM_PATH /Users/arthur/.chefdk/gem/ruby/2.1.0:/opt/chefdk/embedded/lib/ruby/gems/2.1.0
Bundler settings
disable_shared_gems
Set for the current user (/Users/arthur/.bundle/config): "1"
Gemfile
source 'https://rubygems.org'
...
Looking at the ~/.bundle/config, sure enough the global config was set.
---
BUNDLE_DISABLE_SHARED_GEMS: '1'
Once removed, Bundler resolves nokogiri 1.6.3.1 correctly and doesn't try reinstalling it. This setting should not be there by default, by default bundler installs with --system. I must have set this setting many months back and forgot I did.
Try running bundle env to verify that the install location is what you expect.
If not, check whether there is a .bundle/config or ~/.bundle/config file overriding the install path. The output of bundle env will tell you what configuration it is using and how it was determined (i.e., which file it was in or whether it was picked up from an environment variable).
Try removing all contents of gemfile.lock file. Save the file. Run bundle install again.
There are a couple of methods. In gemfile you can specify the path which will force bundle to use from there.
gem "my_gem", :path => "path to gem"
As i see the issue is with the default paths here. Try doing this.
ChefDK doesn't install gems globally, it installs them under /opt/chefdk so they won't interfere with "your" global gems. I suggest you leave ChefDK gems isolated as they should be.
You need to use the proper bundler and gem. If you're using ChefDK, then it includes its own bundler and gem executables. They should be inside the /opt/chefdk directory, I believe under /opt/chefdk/embedded (I don't use chefdk, so I can be 100% sure of that).
To work 100% inside that ruby install, you need to ensure that the chefdk binaries are in your path before the other ruby related binaries. You can verify that with which ruby which gem and which bundle.
All that said, you really SHOULDN'T be messing with the ruby install for chefdk. It's embedded for a reason, so that you don't accidentally mess it up. I'd suggest you stick with the system ruby for your own work, and let Chef handle its ruby.
From Bundler docs:
--path: Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on
this machine
Your bundler may have cached a --path specified install command.
Try:
bundle install --system
This will tell bundler to use the system installed gems as opposed to downloading new gem copies to a folder specific gem collection.

Adding a customized version of bundler as a dependency in a Gemfile

How can I make a typical gem setup (as generated by bundle gem) run a customize version of bundler?
I've added:
#group :development do
gem "bundler", github: 'pjump/bundler'
#end
to my Gemfile (with or without the the hash symbols), and bundle install works, but bundle exec keeps telling me that the bundler repo is not yet checked out. The only way I can make it work for now is by installing the customized version with gem istall and not specifying a bundler dependency in the package at all.
Bundler isn't able to bootstrap itself from a Gemfile, so adding a customized version to your Gemfile will not do what you want. Installing it with gem install is the correct solution (or running rake install from the forked Bundler repo directory, which builds and installs the gem in one step).

bundle doesn't know what ruby is?

So, not too long ago, this command worked on my computer, however, I don't remember if I changed something, but now after removing all my Ruby installs, and just having ChefDK 0.4.0 installed and in my path with the .chefdk/gem, and C:\opscode\chefdk\bin;C:\opscode\chefdk\embedded\bin in my path, I get the following result.
C:\Users\Phillip\Desktop\password_vault
λ bundle exec ruby bin\password_vault
bundler: command not found: ruby
Install missing gem executables with `bundle install`
C:\Users\Phillip\Desktop\password_vault
λ bundle install
Resolving dependencies...
Using rake 10.4.2
Using bundler 1.8.5
Using rack 1.6.0
Using rack-protection 1.5.3
Using tilt 1.4.1
Using sinatra 1.4.5
Using password_vault 0.0.1 from source at .
Bundle complete! 3 Gemfile dependencies, 7 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
C:\Users\Phillip\Desktop\password_vault
λ bundle exec ruby bin\password_vault
bundler: command not found: ruby
Install missing gem executables with `bundle install`
C:\Users\Phillip\Desktop\password_vault
I'm not sure what all else I could be doing wrong.
You have Ruby installed, because bundler is using it.
Somehow your bundle path doesn't have Ruby, or has lost track of it.
To solve this, use bundle --path, such as:
bundle --path "C:\foo\goo\hoo\ruby\bin"
The path is wherever you put Ruby on your system, plus any other path items that you want be available to bundler, such as bin directories of other software.
Bundler will remember the path for future installs on this machine.

'bundle exec' complains about gem not being installed, even after 'bundle install'

I have a website using Jekyll with Github Pages. After previously messing about with versions and RVM on another computer, on this one I opted to stick with just one version of Ruby and per-project environments using bundler.
I have a pretty simple Gemfile:
[$]> cat Gemfile
source 'https://rubygems.org'
gem 'github-pages'
and bundler config:
[$]> cat .bundle/config
---
BUNDLE_PATH: env
BUNDLE_DISABLE_SHARED_GEMS: '1'
When I run any command (jekyll, gem, irb) through bundle exec, I get a dependency error:
[$]> bundle exec jekyll
Could not find RedCloth-4.2.9 in any of the sources
Run `bundle install` to install missing gems.
However, the bundle is already installed:
[$]> bundle install
Using RedCloth 4.2.9
Using i18n 0.6.11
Using json 1.8.1
[snip]
Using github-pages 29
Using bundler 1.7.7
Your bundle is complete!
It was installed into ./env
I'm at a bit of a loss as to how bundler can think the gems are installed when using one subcommand, but think they're missing when using another.
[$]> which ruby
/usr/local/bin/ruby
[$]> which bundler
/usr/local/bin/bundler
[$]> ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
[$]> bundler --version
Bundler version 1.7.7
After deleting the env directory and reinstalling, I noticed it created subdirectories for two Ruby versions - 2.1.0 and 2.2.0. The latter was my current version of Ruby, but the directory was empty (all the gems were installed into the env/ruby/2.1.0/gems directory). This, combined with Oliver's answer about rbenv, got me thinking about mismatched versions.
I reinstalled bundler with a simple gem install bundler, reran bundle install, and all is good.
It seems in general the answer is to sort out issues with bundler installing for a different version of Ruby than you're actually using. It seems strange to me it would use one thing for bundle install and another for bundle exec, but *shrug* whatever.
I had exactly the same problem after installing rbenv as my Ruby manager. In the end I solved the problem with:
rbenv rehash
(additionally you may need to restart terminal, as per #joel-glovier's comment)
That fact it's complaining about Redcloth 4.2.9 is actually a red herring. Bundler probably can't find any of the gems but Redcloth is the first one it looks for and so it exits imediately with that error.
Basically I'd installed rbenv and ruby 2.2.2 and changed to that version with rbenv global 2.2.2 but I'd forgotten to run rbenv rehash. So I'm guessing when running bundle install it was looking at my previously used version of ruby (system ruby) to see what gems were installed but when running bundle exec jekyll serve it was looking at my new ruby version and not finding any of the gems.
I had to open ./.bundle/config and set
BUNDLE_DISABLE_SHARED_GEMS to true for bundle the gems to be properly locally stored.
I had defined BUNDLE_GEMFILE = /home/app/current/Gemfile in .bashrc file. That broke the bundle exec while deploying a new version to the server. Check with env that you don't have the BUNDLE_GEMFILE defined in your environment variables.
I added the BUNDLE_GEMFILE into the .bashrc file to ease with monit commands. Now I just define the variable in the beginning of the monit command.

Resources