Each time I open a terminal my Ruby version is wrong. I am obliged to execute by hand the following command:
source /usr/local/rvm/scripts/rvm
I read that RVM doesn't modify .bashrc or .bash_profile but I note that my .bashrc has at the end:
PATH=$PATH:$HOME/.rvm/bin
Not only I didn't insert this myself but the path to rvm is wrong ! I changed by:
PATH=$PATH:/usr/local/rvm/bin
I reopened a terminal but the Ruby version is always wrong !
RVM should handle this automatically but this code is wrong.
RVM's path should be first. Your bash is acting as you wish actually. It uses the 'system wide' ruby first because you tell your shell to do so. Change this to:
then
source ~/.bashrc
and it will work as you wish, callingrvm
ruby when you login.Depending on your setup it could not be loading for several reasons.
For instance, when you open a shell (depending on the OS distribution) bash files are read in various orders, although here is what the standard looks like: ( I believe Ubuntu is slightly different so you might want to check if thats your distro).
What happens when you directly source your .bashrc? Does it then find rvm? If so, then its just a matter of making sure your .bash_profile sources .bashrc aka:
If this isn't the cause you could dive into the rvm documentation or switch to rbenv which IMHO is a much simpler solution.
rvm does modify your .bash_profile / .bashrc -- that's one of its weaknesses. In particular, it adds (is supposed to add) this line to load rvm as a shell function:
I had a similar issue with the wrong ruby version running even after I changed the global default in rvm--ensuring this line was at the end of my .bash_profile fixed it. In any case, that line's supposed to be there for rvm to work properly.
You can make an
.rvmrc
file in the root directory of your application.It runs whatever is inside on opening the root direct, so I think you can just copy this
and things should be good. You'll get a warning, but it's safe to ignore (or has been in my experience). I think you might be better off going with this, which I've found helpful to keep rubies/gemsets straight across applications.
Why gemsets/rubies get switched/reset in the first place, I really don't know and it is annoying, but this seems to fix it.
read more here