Code Monkey home page Code Monkey logo

Comments (17)

postmodern avatar postmodern commented on July 17, 2024

You might want to set the default ruby in ~/.zprofile, so it only get's ran for login-shells. This would prevent it setting the default ruby when other sub-shells are spawned.

from chgems.

kgrz avatar kgrz commented on July 17, 2024

That did work. However, when I run chgems, the ruby version gets changed to 1.8.7 and when I run chruby after that, it gets changed to ruby 2.0 but the gem env also changes (first image in the first comment)

from chgems.

garybernhardt avatar garybernhardt commented on July 17, 2024

I'm seeing the same behavior:

failbowl% ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
failbowl% chruby 2.1.0
failbowl% ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin11.0]
failbowl% chgems .
Entering /Users/grb/proj/investment with gems in .gem/ruby/2.1.0/ ...
failbowl% ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]

My .zshrc contains two lines: one to add Homebrew to $PATH, and the chruby.sh line; no auto.sh or anything else. If I chgems, it resets the Ruby version to system. If I chruby, it resets the gem environment.

I thought that it might be related to zsh version (I was running 4.3.11, which ships with OS X Lion). I upgraded to 5.0.5 and got the same result. I also get the same result with bash 4.2.42, again with a minimal .bashrc.

from chgems.

postmodern avatar postmodern commented on July 17, 2024

Could you paste your .zshrc, $PATH and which ruby?

from chgems.

postmodern avatar postmodern commented on July 17, 2024

@garybernhardt This is just wild speculation, but I suspect somewhere in your zsh configuration $PATH is being reset or the homebrew path is being prepended, thus overriding chruby's changes.

from chgems.

garybernhardt avatar garybernhardt commented on July 17, 2024

Shell session with all of that stuff (hopefully exhaustively):

failbowl% cat ~/.zshrc
export PATH=/usr/local/sbin:/usr/local/bin:${PATH}
source /usr/local/share/chruby/chruby.sh
failbowl% cd proj/investment
failbowl% echo $PATH; which ruby; ruby -v
/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin
/usr/bin/ruby
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
failbowl% chruby 2.1.0
failbowl% echo $PATH; which ruby; ruby -v
/Users/grb/.gem/ruby/2.1.0/bin:/Users/grb/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/bin:/Users/grb/.rubies/ruby-2.1.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin
/Users/grb/.rubies/ruby-2.1.0/bin/ruby
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin11.0]
failbowl% chgems .
Entering /Users/grb/proj/investment with gems in .gem/ruby/2.1.0/ ...
failbowl% echo $PATH; which ruby; ruby -v
/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:/Users/grb/proj/investment/.gem/ruby/2.1.0/bin:/Users/grb/.gem/ruby/2.1.0/bin:/Users/grb/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/bin:/Users/grb/.rubies/ruby-2.1.0/bin:/usr/local/sbin
/usr/bin/ruby
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]```

from chgems.

postmodern avatar postmodern commented on July 17, 2024

@garybernhardt just as I suspected, when chgems spawns the sub-shell, the zsh configuration prepends all directories onto the path, overriding /Users/grb/proj/investment/.gem/ruby/2.1.0/bin:/Users/grb/.gem/ruby/2.1.0/bin:/Users/grb/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/bin:/Users/grb/.rubies/ruby-2.1.0/bin.

Also, it appears /usr/local/bin is already in your $PATH, but is after /usr/bin. Normally /usr/local/bin is supposed to take precedence over over /usr/bin. I wonder if this is an artifact of zsh's built-in configuration.

from chgems.

garybernhardt avatar garybernhardt commented on July 17, 2024

/usr/local/bin is actually in there twice: once from someone's (zsh's?) default configuration, and again from my .zshrc explicitly putting it at the front, so I think that part's OK, although it's weird.

I'm not sure why zsh is prepending all of the directories, though. That's very strange. What shell are you using, @postmodern? Bash?

from chgems.

postmodern avatar postmodern commented on July 17, 2024

@garybernhardt bash 4 on Fedora. In bash's system configuration, it actually checks if PATH is already set and skips populating it. Not sure if that behavior was added by Fedora or from upstream.

from chgems.

postmodern avatar postmodern commented on July 17, 2024

@garybernhardt I cannot reproduce this on Fedora 19 with bash 4.2 or zsh 5.0:

bash

$ which ruby
/usr/bin/ruby
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
$ chruby 1.9
$ which ruby
/opt/rubies/ruby-1.9.3-p484/bin/ruby
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
$ chgems project/
Entering /home/hal/project with gems in .gem/ruby/1.9.3/ ...
$ which ruby
/opt/rubies/ruby-1.9.3-p484/bin/ruby
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

zsh

% which ruby 
/usr/bin/ruby
% ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
% chruby 1.9
% which ruby
/opt/rubies/ruby-1.9.3-p484/bin/ruby
% ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
% chgems project/
Entering /home/hal/project with gems in .gem/ruby/1.9.3/ ...
% which ruby
/opt/rubies/ruby-1.9.3-p484/bin/ruby
% ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

from chgems.

postmodern avatar postmodern commented on July 17, 2024

@havenwood and myself suspect this bug is caused by how path_helper is called in /etc/zshenv, which populates $PATH using /etc/paths and /etc/paths.d.

from chgems.

havenwood avatar havenwood commented on July 17, 2024

Both /etc/profile and /etc/zshenv eval path_finder which sets PATH to colon-separated /etc/paths file content followed by /etc/paths.d/* file contents then exports PATH.

from chgems.

havenwood avatar havenwood commented on July 17, 2024

path_finder source: http://www.opensource.apple.com/source/shell_cmds/shell_cmds-175/path_helper/path_helper.c

from chgems.

garybernhardt avatar garybernhardt commented on July 17, 2024

That does look tremendously suspicious. I actually glanced at zshenv before my first comment, but somehow didn't make the connection. I'll try to exorcise this badness tomorrow if no one beats me to it.

from chgems.

garybernhardt avatar garybernhardt commented on July 17, 2024

I confirm that it's path_finder, as invoked from zshenv. path_finder itself would be fine if it were invoked from zprofile. That's what Apple did for bash (it's invoked from /etc/profile, not /etc/bashrc). To make OS X behave correctly, it seems like the right thing is to sudo mv /etc/zshenv /etc/zprofile. I've done that with no ill effects so far.

So, what to do? Document the badness in the README? Try to find a hack to work around it? (I'm not sure what such a hack would possibly look like.)

from chgems.

garybernhardt avatar garybernhardt commented on July 17, 2024

I confirmed via Twitter followers that this is still a problem in OS X Mavericks.

from chgems.

postmodern avatar postmodern commented on July 17, 2024

Ah ha! I forgot about that known Mavericks bug. We probably should mention that Maverick's zsh is broken. However, since it's such a trivial mistake that affects much more than just chgems, we should report this to Apple.

from chgems.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.