-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The master branch of rbenv breaks inside of tmux. #369
Comments
I forgot to mention that everything works as expected on v0.4.0. |
Your problem is due to $PATH ordering. You could have shared your PATH with us, but you don't have to now because I know exactly what happened. Your PATH in your regular terminal session is something like:
By entering tmux, you spawned a nested interactive subshell. That means that your
The master branch of rbenv avoids adding shims to the PATH twice. So you finished with ruby from system paths ( The solution is to configure your shell initialization file (e.g. |
@mislav maybe I am missing it, but I cannot figure out quite where your checking the PATH for duplicates in that file you linked to. Could you add something to the README for ZSH and BASH users? |
It's handled by a command I call in the end of the above linked file |
I'm not able to get your solution working as it puts the rbenv shims and bin paths at the end of the PATH. At this point /usr/bin/ruby takes over. As you can see the shims get properly added in the non-tmux version, but adding the consolidation code moves them to the end anyway. rbenv.sh (bash_profile include)
output from tmux new tab
output from new iterm window
|
@jgeiger Strange; it looks like as though you have something in |
The default shell is bash but I checked the files you suggested. Right now my workaround is to just remove the check to see if shims has already been added. Once I do that, everything works file (with the issue of having rbenv shims,bin in the path twice) ~/.zshenv is empty box:etc $ cat zshenv # system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi box:etc $ /usr/libexec/path_helper -s
|
@jgeiger As I suspected, there is your problem: you have a
|
I tried this and it didn't seem to help. I'm running into an issue where the rbenv bin,shims always end up at the end up the path. The box I'm working on may be re-imaged in the near future so for now I'll just fix it in the rbenv init script by removing the check to see if shims already exists. Thanks. |
It seems like tmux will always call the profile for your shell, not just the rc (I'm using bash, and it's definitely calling /etc/profile, which also has a call to path_helper). What I'm doing to fix it is changing
instead of
|
tmux doesn't call the profile for any shell by itself. Your shell does, because with tmux, interactive shells get nested and that can lead to the above problems. Reopening this because it's getting people tripped up |
After a couple of hours of tinkering, the optimal way to solve this (without disabling --- /etc/zshenv.orig
+++ /etc/zshenv
@@ -1,4 +1,5 @@
# system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
+ PATH=""
eval `/usr/libexec/path_helper -s`
fi The underlying problem is that all your shell configuration files are loaded twice when you create a tmux session/window. So the following happens:
This patch ensures that your shell configuration is loaded starting from a blank path. This has two benefits:
|
@markprzepiora's solution worked for me |
I ran into the same problem with tmux & rbenv this morning, @tonyarkles solution worked for me as a bash user. |
@markprzepiora the problem with your solution (versus what @mislav recommends: moving /etc/zshenv to /etc/zprofile) is that any modifications to $PATH in ~/.zprofile will be wiped out when starting a sub-shell or running a script. |
I'm running tmux + bash in ITerm 2 (Mac OS X 10.9), and @tonyarkles solution worked for me. |
I'm running tmux + bash in ITerm 2 (Mac OS X 10.9) and @tonyarkles solution worked for me as well. But after a boot or shell rebooting. |
EDIT: Don't do this. It sorts alphabetically, which you probably don't want. Running tmux + bash on OS X 10.9 with this in my PATH=`echo $PATH | tr ':' '\n' | sort | uniq | tr '\n' ':'` via http://linuxg.net/oneliners-for-removing-the-duplicates-in-your-path/ |
@audionerd I would not advise using this method, since it uses |
@mislav Thanks, good point. I think I found a fix that works now. I'm running bash, and I wanted a solution that worked only for my current user (no messing with if [ -f /etc/profile ]; then
PATH=""
source /etc/profile
fi
. ~/.profile
. ~/.bashrc Now my |
Override path_helper by calling it again. The PATH is cleared first and then rebuilt. The result is far less duplication of directories. rbenv is also setup here. # Mac OS X uses path_helper to preload PATH, clear it out first
if [ -x /usr/libexec/path_helper ]; then
PATH=''
eval `/usr/libexec/path_helper -s`
fi
# if rbenv is present, configure it for use
if which rbenv &> /dev/null; then
# Put the rbenv entry at the front of the line
export PATH="$HOME/.rbenv/bin:$PATH"
# enable shims and auto-completion
eval "$(rbenv init -)"
fi |
@audionerd @serta Thanks for the explanations. I am using the example from @serta above with tmux and rbenv and things are working as expected. P.S. Hi Eric! :) |
- Fix bug with OS X zshenv: See rbenv/rbenv#369 (comment) and thread
see [This issue on rbenv](rbenv/rbenv#369) for more information
I'm really having problems with this. I can't use your Why does Rbenv not add the |
Your problem is not rbenv. Your problem is other parts of the system (that includes user scripts) reordering and duplicating PATH entries in a way it breaks your environment.
|
I already went with @markprzepiora's solution. But thanks for the info, I didn't know that I can run it anyways. Other parts of system don't reorder my PATH entries, they just duplicate them. But what is the bright side of rbenv not duplicating its shims? Why is it in the code base? |
rbenv doesn't duplicate the shims directory since it goes against the practice of duplicating PATH entries, in case shims is already in PATH. Crazy as it may sound, rbenv actually doesn't believe that the way to fight the duplication problem is with more duplication. |
Hi all. Ive had duplicate path entries for quite some time now. Running OSX 10.7, zsh, rbenv, tmux. I've tried solutions from some comments here and the only solution that worked for me was putting this inside
Whereas
|
See rbenv/rbenv#369 for more info
I too simply can't get this to work. I've tried @mislav's solution using his consolidate-path script and then having these two exports at the end of my export PATH
export PATH="$(consolidate-path)" which results in the terminal session freezing upon sourcing (I can force cancel whatever sourcing process is happening by sending Was anybody on linux using zsh able to solve this? tmux -V
tmux 1.8 tmux show environment -g
RBENV_DIR=/home/jottr
RBENV_HOOK_PATH=:/home/jottr/.rbenv/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks:/home/jottr/.rbenv/plugins/rbenv-binstubs/etc/rbenv.d:/home/jottr/.rbenv/plugins/rbenv-gem-rehash/etc/rbenv.d
RBENV_ROOT=/home/jottr/.rbenv
RBENV_SHELL=zsh
RBENV_VERSION=1.9.3-p484 |
running consolidate path got this error everytime was opening my terminal: /etc/zshenv:3: fork failed: resource temporarily unavailable maybe its a zsh config or something like that, but solved putting @mislav consolidate-path inline on my ~/.zshenv export PATH
typeset -a paths result
paths=($path)
while [[ ${#paths} -gt 0 ]]; do
p="${paths[1]}"
shift paths
[[ -z ${paths[(r)$p]} ]] && result+="$p"
done
export PATH=${(j+:+)result} if someone knows the fix for resource temporarily unavailable please tell, if someone has the same problem, this workaround worked thank you guys, thanks @mislav for the solution |
On Mac OS X, there is a bug where `/etc/zshenv`'s `path_helper` forces `/usr/bin` to the front of the `$PATH`: rbenv/rbenv#369 # system-wide environment settings for zsh(1) if [ -x /usr/libexec/path_helper ]; then eval `/usr/libexec/path_helper -s` fi This breaks rbenv by always using the system Ruby. We have fixed this in the past in our Laptop script by moving `/etc/zshenv` to `/etc/zprofile`: thoughtbot/laptop@c64806e And more recently, to `/etc/zshrc`: https://github.com/thoughtbot/laptop/blame/master/mac On Yosemite with the version of thoughtbot/dotfiles before this commit, with rbenv being initialized in `~/.zshenv`, the problem returned. Moving rbenv initialization back to `~/.zshrc` fixed the problem. The official documentation for rbenv also recommends initializing in `~/.zshrc`. https://github.com/sstephenson/rbenv#basic-github-checkout It also recommends: export PATH="$HOME/.rbenv/bin:$PATH"
On Mac OS X, there is a bug where `/etc/zshenv`'s `path_helper` forces `/usr/bin` to the front of the `$PATH`: rbenv/rbenv#369 # system-wide environment settings for zsh(1) if [ -x /usr/libexec/path_helper ]; then eval `/usr/libexec/path_helper -s` fi This breaks rbenv by always using the system Ruby. We have fixed this in the past in our Laptop script by moving `/etc/zshenv` to `/etc/zprofile`: thoughtbot/laptop@c64806e And more recently, to `/etc/zshrc`: https://github.com/thoughtbot/laptop/blame/master/mac On Yosemite with the version of thoughtbot/dotfiles before this commit, with rbenv being initialized in `~/.zshenv`, the problem returned. Moving rbenv initialization back to `~/.zshrc` fixed the problem. The official documentation for rbenv also recommends initializing in `~/.zshrc`. https://github.com/sstephenson/rbenv#basic-github-checkout It also recommends: export PATH="$HOME/.rbenv/bin:$PATH"
I noticed my `PATH` had duplicated entries in it. With help from a GitHub issue[1] and a comment[2] linking to another comment at StackOverflow[3] I understand the reason behind this duplication and it also provided me with a solution. [1]: rbenv/rbenv#369 [2]: rbenv/rbenv#369 (comment) [3]: https://superuser.com/questions/544989/does-tmux-sort-the-path-variable/583502#583502
When using the master branch version of rbenv, tmux no longer respects rbenv. For example I have global ruby setup to 2.0.0-p0 and when I run
rbenv version
it correctly reports 2.0.0-p0, it is also correctly reported when I run ruby --version. Now in the same session I start a new tmux session usingtmux new
. Now when I runrbenv version
it still correctly reports 2.0.0-p0, however when I runruby --version
it now reports 1.8.7. When I runwhich ruby
it shows me/usr/bin/ruby
instead of the ruby shim.The text was updated successfully, but these errors were encountered: