Why does bundle install add a binstub of itself (bundle) which can't be executed? - bundler

I have a simple Gemfile:
source 'https://rubygems.org'
gem 'librarian-puppet'
gem 'onceover'
When I install this using bundle (through rbenv shim: bundle install --path=vendor/bundle) then binstubs are installed in vendor/bundle/ruby/2.7.0/bin. But I can't execute them directly, for all I get the same result:
$ vendor/bundle/ruby/2.7.0/bin/onceover
Traceback (most recent call last):
2: from vendor/bundle/ruby/2.7.0/bin/onceover:23:in `<main>'
1: from /opt/puppetlabs/pdk/private/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/rubygems.rb:296:in `activate_bin_path'
/opt/puppetlabs/pdk/private/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': can't find gem onceover (>= 0.a) with executable onceover (Gem::GemNotFoundException)
However, if I execute these binstubs using (rbenv shimmed) bundle exec then it works:
$ bundle exec onceover --help
...
So this is fine – although I'm not sure if it's expected, I'm a Ruby newbie.
But what confuses me is that one of the binstubs is bundle itself. Which would seems silly, since that only way to run it is bundle exec bundle which does work:
$ bundle exec bundle --version
Bundler version 2.1.4
However. This causes problems for me in IntelliJ IDEA, which when executing using bundle finds the binstubbed version and uses that. If I rm vendor/bundle/ruby/2.7.0/bin/bundle then it falls back to the rbenv shimmed version and is fine.
Finally, my question. Assuming this isn't wrong from the start, why does bundle install a binstub of itself? I have found other vendor directories where this did not seem to happen but I can't figure out the mechanism that causes the difference.

Related

`require': cannot load such file -- rack/handler (LoadError)

I'm not a Ruby person, so this may be a 101 question. I'm just trying to use a utility that happens to be written in Ruby.
I'm using tilemaker, a utility in the openstreetmap ecosystem. It creates tiles in the mbtiles format. The repository comes with a simple utility to serve the tiles on a browser to test the files you create. This utility is written in Ruby, and is what I'm having trouble with.
The repo's README has instructions for the server utility. The installation instructions read:
(If you don't already have them, you'll need to install Ruby and the required gems to run the demonstration server. On Ubuntu, for example, sudo apt install sqlite3 libsqlite3-dev ruby ruby-dev and then sudo gem install sqlite3 cgi glug rack.)
I'm on Debian 11 (on Qubes, so I don't mind running sudo gem install as they recommend). I hope this is close enough to Ubuntu but maybe this is related to the problem.
This is what I get:
$ ruby server.rb ~/countries-raster.mbtiles
Starting local server
Traceback (most recent call last):
3: from server.rb:22:in `<main>'
2: from server.rb:118:in `<class:MapServer>'
1: from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in `require'
/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- rack/handler (LoadError)
What am I missing here? Thanks.
It appears that the issue is that you are using a 3.X release of rack.
According to the CHANGELOG as of version 3.0 Rack::Handler was removed from rack and pulled out into its own gem (rackup).
To resolve the issue you will need to either use an older version of rack
gem 'rack', '~> 2.2'
Or you will need to add the rackup gem as a dependency:
gem 'rack'
gem 'rackup'
Either option will provide access to rack/handler:
rack (2.2.5) - Source
rackup (0.2.3) - Source
for a better setup under your user, this could be done:
ensure to have ruby running under your user by:
ruby -v # 2.7 or higher is better
then create a file besides your script server.rb called Gemfile:
# Gemfile
source "https://rubygems.org"
gem "rack"
gem "sqlite3"
gem "cgi"
gem "glug"
After that, ensure to have bundler installed (this is a gem to manage gem versioning), by:
gem install bundler
If you face a permission error, is because your ruby program is under root user. So you can use via sudo bundle install, but anything else must be run under sudo, or you can install and setup rvm which will install and configure ruby under your user.
After installing you can call:
bundle install
# will install all the gems needed and will lock the latest versions for you inside Gemfile.lock
run your server by:
bundle exec ruby server.rb
by running via bundle exec your telling to ruby to use the gems installed and versioned by the Gemfile.lock. This guarantees to your software to require the specific versions and avoid collisions or anything else.

Bundler 2.2.0 and Ruby 2.7.5 on Docker crashing

I installed Ruby 2.7.5, and within the Dockerfile, specified bundler (version 2.2.0) to be installed:
RUN gem install bundler -v 2.2.0 --no-document
the output of this is:
INFO[0093] RUN gem install bundler -v 2.2.0 --no-document
INFO[0093] cmd: /bin/sh
INFO[0093] args: [-c gem install bundler -v 2.2.0 --no-document]
INFO[0093] Running: [/bin/sh -c gem install bundler -v 2.2.0 --no-document]
Successfully installed bundler-2.2.0
All seemed to be fine in that install, and bundle works as gems specified in Gemfile are installed. However, when I try to open the console, I see this:
/usr/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': Could not find 'bundler' (2.2.0) required by your /app/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.0`
However, it is installed. as you can see from above. Also, when I output the version within the Dockerfile, I see:
Bundler version 2.2.0
It seemed to install fine, however, still see the error above, and it crashes immediately.
Is there something obvious I am doing wrong?
Building a Docker Image with an Updated Bundler Version
You're missing a couple of steps in your Dockerfile build for bundled gems. After you update Bundler, you also need to update your Gemfile.lock and possibly re-run bundle install. There are a lot of options involved, but here's my personal recommendation for your Dockerfile based on your post:
# Note: Don't lock your Bundler version unless you
# have a VERY good reason to do so. Update will
# install or update, as needed.
RUN gem update bundler --no-document \
&& gem clean bundler \
&& bundle update --bundler \
&& bundle install
The key here is that if you don't use bundle update --bundler then the Gemfile.lock will not contain the version of Bundler that you're expecting to call. Recent versions of Bundler will downgrade themselves to the version in the Gemfile.lock if necessary, so this is really the key to the whole thing.
In addition, if you continue to have problems after applying the recipe above, you may need to figure out where Bundler is actually being installed inside your container image. While Bundler (currently) doesn't run from inside your bundle, the required version still needs to be in GEM_HOME, GEM_ROOT, or GEM_PATH in order to be found when you invoke it.
As a final consideration, if you're building your gems locally or modifying your Gemfile.lock and then using an ADD or COPY command to place the Gemfile.lock or any vendored gems into your container image, you need to perform these activities outside of Docker rather than inside the Dockerfile. Based on your original post it doesn't look like you're doing that now, but it's another option to consider as you work on resolving this.

How can Bundler be inactive if it's appearing in my gem list?

Im trying to install this Rails project (https://github.com/mjohnson324/MockDoc/blob/master/docs/setup.md)
when running 'bundle install' I get the following error:
Traceback (most recent call last):
2: from /usr/bin/bundle:23:in `<main>'
1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.0.2) required by your /Users/michaelkoch/projects/MockDoc-master/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.2`
So I run 'gem install bundler:2.0.2' and the install seems to work. Here's the output:
Successfully installed bundler-2.0.2
Parsing documentation for bundler-2.0.2
Done installing documentation for bundler after 2 seconds
1 gem installed
If I run gem list I see the following line: bundler (2.1.4, 2.0.2)
If I run bundle install command again, I get the same orginal error, as if bundler is not installed.
I'm using rbenv to manage versions, as indicated by the Github project.
I kindly as for your help.
I encountered a similar issue on my MacBook M1 system while trying to use 2.1.4 for my project. I tried deleting the gemfile.lock and reinstalling by running gem install bundler:2.1.4 and then bundle install as suggested by #Giuseppe Schembri but that didn't solve my issue.
I navigated to the root directory, and tried to check the global version by running
bundler version
and got-
Bundler version 2.3.22 ([date] commit [commit_id])
I again navigated to my project directory, and ran bundler version again, and got -
Bundler version 2.1.4 ([date] commit [commit_id])
News flash: bundler 2.1.4 is installed for my project.
Then why does the error persist?
Aparently, I had a post-checkout file in my .git > hook which was trying to execute bundler exec pod install and failing.
Later I realized, it couldn't find the path for the bundler. so I get the path by running
type bundler
which returned
bundler is /Users/myUserName/.rbenv/shims/bundler
Then rather than bundler exec pod install, I used /Users/myUserName/.rbenv/shims/bundler exec pod install.
In the newer versions of OS on M1, this can happen.

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.

The "rake" command gets the error "no such file to load -- rspec/core/rake_task"

I'm using Ubuntu version 12.04.02, Ruby 1.8.7, Gems 1.8.15, trying to do TestFirst.org's Learn Ruby (http://testfirst.org/learn_ruby).
The folder where I store all the files for the course is located on my computer in /home/topher/ruby/learn_ruby-master.
I've followed the instructions to go into the folder labeled 00_hello within the larger folder and create an empty text document called "hello.rb" in the 00_hello folder. Then I go into the terminal, navigate to ~/ruby/learn_ruby-master/00_hello and type:
rake
First I got this error message:
(in /home/topher/ruby/learn_ruby-master)
rake aborted!
undefined method `gem' for main:Object
(See full trace by running task with --trace)
I did some searching and found a thread on Stack Overflow where someone recommended deleting the line in the rake file that said:
gem 'rspec', '~2'
I did so (or rather, commented it out to be on the safe side) and got a different error message on running "rake":
(in /home/topher/ruby/learn_ruby-master)
rake aborted!
no such file to load -- rspec/core/rake_task
(See full trace by running task with --trace)
How do I fix this?
That learning project requires bundler. You know this because at the project's root path there is a file called Gemfile
So in order to continue, first install bundler then run bundle install then rake:
$ gem install bundler rubygems-bundler --no-rdoc --no-ri
$ bundle install
$ rake
Prefer a newer Ruby version like 2.0.0 rather than 1.8.7. You can use rvm to get everything setup for you. As a bonus you won't need to install bunder nor rubygems since they are included since ruby 1.9
$ \curl -sSL https://get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/rvm
$ rvm requirements
$ rvm install 2.0.0
$ rvm use --default 2.0.0

Resources