Skip to content
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

.ruby-version and .ruby-gemset are not used when TMux is started in project dir #3270

Open
e2 opened this issue Jan 18, 2015 · 14 comments
Open

Comments

@e2
Copy link
Contributor

e2 commented Jan 18, 2015

  1. I cd to a project with a .ruby-gemset file - gemset is correctly set to foo
  2. I run tmux in that directory - gemset is set to (default) [expected: should be set to foo!]
  3. Profit! I run cd . - and gemset is properly set to foo

Version: just checked on head - same problem

I've checked - .zlogin is loaded when new TMux window is opened and it contains rvm.

Is there anything I can do to debug this?

My .ruby-gemset has foo and my .ruby-version has ruby-2.1.5 and my ~/.rvmrc:

rvm_autoupdate_flag=2
rvm_gemset_create_on_use_flag=1
rvm_autoinstall_bundler_flag=1
@mpapis
Copy link
Member

mpapis commented Jan 18, 2015

  1. make sure you try it again with rvm get head
  2. can I see: rvm list
  3. add echo GEM_PATH:$GEM_PATH before and after sourcing RVM in .zlogin - show me the result of new tmux start

please use gist

@e2
Copy link
Contributor Author

e2 commented Jan 19, 2015

I worked it out: tmux reuses existing sessions, so I when I did tmux -L new_socket, it worked from there.

So I'm guessing upgrading rvm fixed it, but the existing tmux session was re-used (env variables?).

I closed all existing tmux sessions and now it works fine (after the update today).

Thanks so much!

@e2 e2 closed this as completed Jan 19, 2015
@e2 e2 changed the title .ruby-gemset not used when TMux is started in project dir .ruby-version and .ruby-gemset are not used when TMux is started in project dir Jan 19, 2015
@e2
Copy link
Contributor Author

e2 commented Jan 19, 2015

Oh, and .rvm-version was ignored too.

@e2
Copy link
Contributor Author

e2 commented Jan 19, 2015

The problem still occurrs.

It turns out I had a source ~/.rvm/scripts/rvm in an old script run inside tmux. (not the cause).

Here's how to reproduce the problem:

  1. close all TMux sessions
  2. tmux new
  3. detach that session # important!
  4. open new terminal with new session
  5. cd project # enter directory with .ruby-version and .ruby-gemset files
  6. tmux new
  7. rvm gemset list # shows (default) - probably because it reuses env from step 3

@e2 e2 reopened this Jan 19, 2015
@mpapis
Copy link
Member

mpapis commented Jan 19, 2015

can I see the GEM_HOMEs from step 3. here => #3270 (comment)

@e2
Copy link
Contributor Author

e2 commented Jan 19, 2015

Here it is: https://gist.github.com/e2/a5ebc69867273c305634

It is exactly the same as a plain shell session outside tmux (before entering the project directory)

So (given there's a detached tmux in the background somewhere):

  1. I open a new terminal - 2.1.5@global is as expected
  2. I go to the project dir - 2.1.1@foo is correctly set
  3. I run tmux new - 2.1.5@global is set (wrong - as in gist)
  4. I run cd . - 2.1.1@foo is correctly set

@e2
Copy link
Contributor Author

e2 commented Jan 19, 2015

I did an rvm implode, logged out reinstalled using MRI 2.2.0, and it still doesn't work.

Initial env vars

Here are my env vars right after login (no tmux sessions yet, no changing to project dir):
https://gist.github.com/anonymous/8e3f2ebc63cccb2a2c7d

This is the EXACT same config when I start my FIRST tmux session (the one I immediately detach).

This is ALSO the EXACT same environment rvm STARTS OUT with inside every NEXT tmux session.

And because it is the initial environment for RVM, this condition is never true: https://github.com/wayneeseguin/rvm/blob/master/scripts/rvm#L177-L180 so, project rvm rc reloading is skipped.

Correct env vars are never passed to new TMux sessions

And here is the env in the project directory before I start the tmux session:

https://gist.github.com/anonymous/b57a0ce1d577b0b96663

As you can see, this environment with project-gemset is never passed to new tmux sessions (which copy the env from the existing detached session).

Suggested solution

Tmux has an option to pass environment variables from the EXISTING environment:
update-environment, which defaults to things like SSH_AUTH_SOCK, etc.

And it works if I have in ~/.tmux.conf:

set-option -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY GEM_HOME GEM_PATH MY_RUBY_HOME PATH"

I don't know if all 4 are needed by RVM (GEM_HOME GEM_PATH MY_RUBY_HOME PATH), but I could add a PR for a TMux config section on the rvm-site page.

@e2
Copy link
Contributor Author

e2 commented Jan 19, 2015

As a side note: rvm gemset name is /home/czarek/.rvm/gems/ruby-2.2.0 without a default gemset. I don't know if this is by design or not.

@mpapis
Copy link
Member

mpapis commented Jan 19, 2015

the default gemset means - no extra name in some situations (default) is used to show anything

@ghost
Copy link

ghost commented Nov 23, 2016

I believe I'm having a related issue, or perhaps the same one. I'm on Ubuntu 16.04 LTS everything updated to latest and when I installed rvm in tmux, it seems to only work in a tmux session now! rvm will still happily run, insisting ruby-2.1.2 is selected, but ruby returns command not found, same with trying bundle. I ran tmux and suddenly it worked. Pretty funny bug

@crivotz
Copy link

crivotz commented Oct 6, 2017

Same problem for me using tmuxinator.
The first tmux window opened works perfectly instead the following windows, 'forked' from the first one, have the system ruby version and not the one passed by the .ruby-version file.

@goyalmunish
Copy link

I had the same issues. But adding following at the top of ~/.tmux.conf worked:

set-option -g default-shell /bin/zsh

My environment is:
OS: Mac 10.12.4
tmux 2.4
zsh 5.4.2 (x86_64-apple-darwin16.7.0)
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

@charlietag
Copy link

charlietag commented Sep 14, 2020

@e2

  • It's really hard to use RVM under TMUX.
  • I've the following to avoid the following RVM situations under TMUX
  1. conflicts of .ruby-version & .ruby-gemset between TMUX sessions
  2. PATH is not properly set up
    1. switch to rails project with files (.ruby-version & .ruby-gemset)
    2. tmux new
    3. change to folder with no files (.ruby-version & .ruby-gemset) , but ALL of $GEM_HOME, $GEM_PATH, rvm_prompt, remain the same...
  • I do nothing in .tmux.conf

  • Solution - my config (could just put them into .bashrc)

    I'm not sure this is the correct method to solve this issue

    It just works fine on my environment

  • My environment:
    OS: CentOS 8.2
    SHELL: bash (4.4.19)
    tmux: 3.1b
    rvm: 1.29.10

@AlexWFreitas
Copy link

AlexWFreitas commented Feb 1, 2021

Hello, I am having a similar problem but it isn't happening on tmux, instead it happens on the vs code terminal.

I am using vs code with rvm ( 1.29.12 ) installed on ubuntu, when I open a vs code terminal on a ruby project folder it uses the default version that is installed in the machine ( example 2.7.0 )

After using cd . on said terminal, it seems that rvm sets the correct version for the project ( example 2.7.2 )

I made a workaround by adding a cd . at the end of .bash_profile for my user ( I think ) so it loads versions correctly.

But I think this might be a problem with how rvm works when opening a new terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants