Bundle not working with rbenv and cannot gem install bundler
However I did find a very manual solution to this.
I noticed how rbenv whence bundle
specified that bundle was active in some ruby versions, but not others. I tracked down the portion of rbenv whence command to find out where it was looking and saw that it looked under the following path for each ruby version installed under rbenv: ~/.rbenv/versions/$VERSION/bin/
If you look under the path for the gem without bundler (for me this was ~/.rbenv/versions/2.5.1/bin/) you will notice that it is not there. However under other versions that whence can recognise you will see the executable is there (for me it was there under ~/.rbenv/versions/2.3.1/bin/bundle
and ~/.rbenv/versions/2.3.1/bin/bundle
).
So I copied the executable over from the working ruby version to the one that was broken. Then at the top of the file you will notice sha-bang is set to the other ruby version (for me this was #!/Users/myuser/.rbenv/versions/2.3.1/bin/ruby
). Change the version path to the ruby version you want to fix and then it will all magically start working.
Bundle not working with rbenv
Your installation is caught in a loop.
Change to a directory that is not your app, and that doesn't have a Gemfile.
Then do the usual gem install bundle
(and use sudo
if you need it)
Then change to your app directory, and do the usual bundle install
.
Does that solve your issue?
If you need more help, can run these commands then paste the results in your question?
$ command -v ruby
$ command -v bundle
$ ruby -v
$ bundle -v
Look for any mismatch between the results and what you expect. This will help you track down what's happening. You may need to update your Gemfile Ruby version.
(Also, you may want to consider changing from rbenv
to chruby
because it's better IMHO with these kinds of path issues)
rbenv — 'find_spec_for_exe': can't find gem bundler ( = 0.a) with executable bundle (Gem::GemNotFoundException)
This is how I finally solved this problem:
$ cd /path/to/my/project/
$ gem install bundler -v 1.17.3
$ bundle install
Problem installing bundler, Says it installs, but then doesn't actually install
rbenv works by inserting a directory of shims at the front of your PATH:
~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
Through a process called rehashing, rbenv maintains shims in that directory to match every Ruby command across every installed version of Ruby—irb, gem, rake, rails, ruby, and so on.
Shims are lightweight executables that simply pass your command along to rbenv. So with rbenv installed, when you run, say, rake, your operating system will do the following:
- Search your
PATH
for an executable file named rake- Find the rbenv shim named rake at the beginning of your
PATH
- Run the shim named
rake
, which in turn passes the command along to rbenv
You messed up your rbenv
installation.
1) Remove ruby installation outside rbenv
2) rvm implode
3) Clean up your $PATH
env variable from ~/.bash_profile
or ~/.bashrc
Remove any $PATH
reference pointing to ruby
, irb
, gem
or any folder including those bin executable. Consider commenting any $PATH
statement from your bash_profile
# export PATH="$HOME/etc/bin:$PATH"
# leave the statement below
# export PATH="$HOME/.rbenv/bin:$PATH
The $PATH
variable includes a list of folders:
echo $PATH
home/fabrizio/.rbenv/shims:/opt/android-studio/bin:~/.scripts/bin
if you run gem
in your terminal
any .bin
executable file included in home/fabrizio/.rbenv/shims
or /opt/android-studio/bin
is executable from any location in the terminal. When you run gem
, the ruby
gem command is executed instead of being intercepted from rbenv, because you installed ruby outside of rbenv.
UPDATE BASED ON YOUR FEEDBACK
You must have followed this step when installing ruby 2.5.0 without rbenv so remove from your ~/.bash_profile
or ~/.bashrc
the following line
PATH="$PATH:$(ruby -e 'puts Gem.user_dir')/bin"
or any other line which is adding /Users/brianp/.gem/ruby/2.5.0/bin
to your $PATH
, then uninstall ruby with apt.
Read the following information, additionally always check the location where gems are being installed with gem env:
$ gem env home
# => ~/.rbenv/versions/<ruby-version>/lib/ruby/gems/...
if the location from anywhere in the terminal is not under ~/.rbenv/
then you are installing the gems in the wrong locations.
LAST RESORT
Delete the gem folder with rm -rf ~/.gem
, a similar approach to this post if you can not remove /Users/brianp/.gem/ruby/2.5.0/bin
from your $PATH
SOLUTION FOR YOUR LAST ERROR
This error is caused from installing bundler 2.0
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
you need to remove bundler 2.0
and install 1.9.0
Bundler can't find a gem even though gem install works
I had a look at the Gemfile
of some github projects using the same gem.
Try to add the engine
and engine_version
after the ruby version as follows:
# Gemfile
ruby '2.3.1', engine: 'jruby', engine_version: '9.1.8.0'
source 'https://rubygems.org'
gem 'jrubyfx', '~> 1.2'
According to bundler documentation:
Both
:engine
and:engine_version
are optional. When these options are
omitted, this means the app is compatible with a particular Ruby ABI
but the engine is irrelevant. When :engine is used, :engine_version
must also be specified. Using the platform command with the --ruby
flag, you can see what ruby directive is specified in the Gemfile.
Gem list doesn't show bundler after Successfully installed bundler
The PATH
of the root user is likely not the same as the PATH
of your current user. Therefore the gem
command that root loads will not be the same as the gem
command you load as a normal user. This makes sudo gem install
save the gems into a different location (the location of the Ruby installation found in the PATH
of the root user).
To fix this issue, the most straightforward solution is to force root to use the same gem command by giving it the full path:
sudo `which gem` install ...
Note the use of backticks. Using backticks this way, the command will essentially expand to something like:
sudo /some/path/to/the/user/ruby/installation/bin/gem install ...
To figure out if the gem
command of root is different from your default gem
command, you can do this:
# As normal user check output of this command
which gem
# ..and compare it to the output of this command
sudo which gem
Related Topics
Class ≪≪ Self VS Self.Method With Ruby: What's Better
When Do I Need to Restart Server in Rails
Why Not Use Shared Activerecord Connections For Rspec + Selenium
Devise Custom Routes and Login Pages
How to Stub Things in Minitest
How to Create a Sha1 Hash in Ruby
What Does Class_Eval ≪≪-"End_Eval", _File_, _Line_ Mean in Ruby
Why Are Methods in Ruby Documentation Preceded by a Hash Sign
How to Use Define_Method to Create Class Methods
Nokogiri Gem Installation Error
How to Convert a String to a Constant in Ruby
Why Does Adding "Sleep 1" in an After Hook Cause This Rspec/Capybara Test to Pass
Unresolved Specs During Gem::Specification.Reset: