1

I am setting up a new system. I'm using rbenv instead of rvm because rvm changes the definition of 'cd' and that's just evil.

I've got the required version of ruby and rails (I think) installed, but bundler is causing problems:

turlingdrome$ gem install bundler
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ rb_sysopen - /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/CHANGELOG.md

turlingdrome$ sudo gem install bundler
/usr/local/Cellar/rbenv/1.1.2/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:6: warning: Insecure world writable dir /Users/brianp/work in PATH, mode 040777
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Done installing documentation for bundler after 3 seconds
1 gem installed

turlingdrome$ sudo gem uninstall bundler
Gem 'bundler' is not installed

turlingdrome$ bundler install
Traceback (most recent call last):
    2: from /Users/brianp/.rbenv/versions/2.5.3/bin/bundler:23:in `<main>'
    1: from /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)

So, I tried using sudo once, and now I think that the permissions are super user... so I'm using sudo. no big deal.

Installing appears to work.

When I try to uninstall, it says it's not installed.

When I try to run it, it finds an executable, but then says it can't find an executable.

I'm using ruby 2.5.3 and rails (I think) 5.2.3.

Rails crashes with:

turlingdrome$ rails -v
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /Users/brianp/work in PATH, mode 040777
Traceback (most recent call last):
    4: from bin/rails:3:in `<main>'
    3: from bin/rails:3:in `require_relative'
    2: from /Users/brianp/work/online-reporting/config/boot.rb:6:in `<top (required)>'
    1: from /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)

which I assume is the same issue.

In case this matters, I'm on a mac.

Brian Postow
  • 10,227
  • 14
  • 69
  • 113
  • 1
    after reinstalling bundler you need to run `rbenv rehash` [and follow all this steps](https://stackoverflow.com/questions/9602806/bundler-not-working-with-rbenv-could-not-find-gem#11146496) – Fabrizio Bertoglio May 03 '19 at 15:13
  • while the bundler error [`find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle`](https://stackoverflow.com/a/54038218/7295772) is because you upgraded to bundler 2.0. You need to use bundler 1.9.0 – Fabrizio Bertoglio May 03 '19 at 15:17
  • 1
    Do not edit the question to [invalidate existing answers](https://meta.stackoverflow.com/a/290704/3956566). –  May 03 '19 at 22:07

6 Answers6

2

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

Fabrizio Bertoglio
  • 5,555
  • 3
  • 13
  • 47
  • I agree that I shouldn't sudo. But I think I'm clean on that now. $PATH is /Users/brianp/.rbenv/shims:/Users/brianp/bin/linux:.:/Users/brianp/.rbenv/shims:/Users/brianp/.gem/ruby/2.5.0/bin: Not sure why I have two copies of shims, but that is irrelevant. 'which gem' and 'which ruby' etc all point to the correct place. even which bundle... – Brian Postow May 03 '19 at 13:37
  • oh, and I don't have rvm installed at all. I learned my lessen on a previous computer... – Brian Postow May 03 '19 at 13:39
  • @BrianPostow bundler is being installed under `/Users/brianp/.gem/ruby/2.5.0/bin` and not `~/.rbenv/...` so `rbenv` can not use the `bundler` gem. You installed ruby through some other software or repository and now you have in your `$PATH` the binaries from `/Users/brianp/.gem/ruby/2.5.0/bin` . This means that when you run `gem install bundler`, the `gem` executable `/Users/brianp/.gem/ruby/2.5.0/bin/gem` is being used, not the one `~/.rbenv/.../gem` and this causes your error, because `.rbenv` did not install the bundler gem under `~/.rbenv` – Fabrizio Bertoglio May 03 '19 at 14:13
  • @BrianPostow **Delete the gem folder with `rm -rf ~/.gem`**, [a similar approach to this post](https://stackoverflow.com/a/11536137/7295772). – Fabrizio Bertoglio May 03 '19 at 14:14
  • I don't see any other ruby... I'm on a mac, so brew instead of apt, but there is a /usr/bin/ruby... When I delete the ~/.gem folder, and install bundler, it comes back. All other gems appear to be in .rbenv, which is weird... – Brian Postow May 03 '19 at 14:18
  • gem env gives: - USER INSTALLATION DIRECTORY: /Users/brianp/.gem/ruby/2.5.0 – Brian Postow May 03 '19 at 14:20
  • @BrianPostow you are right, mac comes by default installed with ruby. Stupid question, did you try `rbenv rehash` ? – Fabrizio Bertoglio May 03 '19 at 14:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/192785/discussion-between-fabrizio-bertoglio-and-brian-postow). – Fabrizio Bertoglio May 03 '19 at 14:31
  • @BrianPostow your last error is caused from installing `bundler 2.0` . You need to downgrade to `bundler 1.9.0`. – Fabrizio Bertoglio May 03 '19 at 15:11
  • after reinstalling bundler you need to run `rbenv rehash` [and follow all this steps](https://stackoverflow.com/questions/9602806/bundler-not-working-with-rbenv-could-not-find-gem#11146496) – Fabrizio Bertoglio May 03 '19 at 15:13
  • @BrianPostow Thanks a lot. Please ping me and lets talk again in chat to solve your issues until you have rbenv working. – Fabrizio Bertoglio May 07 '19 at 14:39
0

Usage of rbenv is a good choice to manage ruby installation on Mac, but it seems that you finished up in a complete mess of broken rbenv/gem/rails/bundler installation and permissions. It it is not worth of fixing it, so I suggest to just get rid of rbenv, remove ~/.rbenv directory and install rbenv with brew again using this guide.

Other ways to check:

  1. Run rbenv-doctor

    curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

  2. Remove ~/.rbenv directory, run rbenv init again and install required version of Ruby

  3. Check that which ruby and which gem points to appropriate location inside ~/.rbenv directory

Things to note:

  1. rbenv and brew, as well as gem do not require sudo, so you should never use it with them
  2. Do not forget to add eval "$(rbenv init -)" in your shell init script, e.g. echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
ololobus
  • 2,459
  • 2
  • 16
  • 21
0

Can you try that?

gem install bundler --user-install
0

Seems to be a permission issue on a folder.

permission denied @ rb_sysopen -
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/CHANGELOG.md

I'd try to change permissions on the mentioned file / folder using chmod 755 /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/

There are several posts which handle a similar topic, e.g. this.

Christian
  • 2,293
  • 2
  • 16
  • 30
0

warning: Insecure world writable dir /Users/brianp/work in PATH, mode 040777

Looks like problem with access rights. Try this:

sudo chmod 755 /Users/brianp/work
mechnicov
  • 3,922
  • 2
  • 14
  • 32
  • That's just a security warning. I'm the only person on my machine, so it's not relevant... But I did it anyway, and it didn]'t help – Brian Postow May 03 '19 at 13:34
0

Try to delete Gemfile.lockand try to install and use bundler again - I have just found that on Github:

Bundler 2 introduced a new feature that will automatically switch between Bundler v1 and v2 based on the lockfile [...] If you do, it can be fixed by installing the version of Bundler that is declared in the lockfile. This bug was fixed in RubyGems 3.0.0 but backports are now being prepared for previous major versions of RubyGems. We’ll let you know when they become available.

Christian
  • 2,293
  • 2
  • 16
  • 30