How to reload .ruby-version/.ruby-gemset/.rvmrc without leaving current directory? - rvm

We are using RVM to manage rubies and gemsets for dozens of projects.
Sometimes I'll either edit the .ruby-version or .ruby-gemset file, or pull a newer version of those file(s) from our VCS, but of course RVM is unaware of these changes unless I tell it. And if the changes come from the VCS, even I may not be aware of them. So what's the best way to do this?
It would be nice to be able to automate the process, so that it is done automatically any time I fetch changes from the repository.
The only way I know of to get RVM to re-read these files is to cd to another directory, then return to the project directory. This is obviously simple, and easy, but it seems more than a little inelegant, and isn't self-documenting.
I'd expect there to be some command like rvm reload (which exists, but does something else) to re-read the project files, but I can't find anything of the sort.

I think I've found an answer, but as it is undocumented I don't know if it's really legit.
It seems that if you do:
$ rvm use .
It'll apparently (re)read the .ruby-version and .ruby-gemset files (not sure of .rvmrc files, since we don't use them). I discovered this by trying rvm use .ruby-version and rvm use .ruby-gemset, both of which seemed to cause RVM to read both 'dot' files.
This functionality is not currently (as of RVM 1.23.13) mentioned in the documentation (i.e. rvm help use).
Maybe it should be?

I use .rvmrc and I used to do
cd;cd -
but now I do
cd .
If I do
rvm use .
I get
Could not determine which Ruby to use; . should contain .rvmrc or .versions.conf or .ruby-version or .rbfu-version or .rbenv-version, or an appropriate line in Gemfile. ( see: 'rvm usage' )
which I don't really think is true (because I do have a .rvmrc file in .), or perhaps I just don't understand.
Edit:
I am using rvm 1.25.33
I didn't mean to come across as critical, just trying to add more info!

Related

RVM setting incorrect environment path

I was having trouble installing rvm on WebFaction, so I tried just copying over the .rvm directory with my rubies and gems. This has mostly worked. rvm works, it’s referencing the correct ruby, and the correct gem. The problem it seems, is rvm is looking for an environment file in the wrong place. It’s trying to use:
/Users/jezen/.rvm/environments/ruby-2.0.0-p247
Whereas it should be using:
/home/rekyl/.rvm/environments/ruby-2.0.0-p247
Where can I set the correct path?
check /Users/jezen/.rvm/wrappers/ruby-2.0.0-p247/ruby but also /home/rekyl/.rvm/environments/ruby-2.0.0-p247 is relevant, make sure all environment variables point to proper path:
env | grep rvm

How to get rid of RVM notice

Is there a way to get rid of the warning, when I traverse into a folder having a .rvmrc file.
====================================================================================
= NOTICE =
====================================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory =
= This is a shell script and therefore may contain any shell commands. =
= =
= Examine the contents of this file carefully to be sure the contents are =
= safe before trusting it! ( Choose v[iew] below to view the contents ) =
====================================================================================
Do you wish to trust this .rvmrc file? (/home/sam/myrailsapp/.rvmrc)
y[es], n[o], v[iew], c[ancel]> y
To switch from .rvmrc to .ruby-version + .ruby-gemset
rvm rvmrc to .ruby-version
There is a bug right now in RVM that keeps it asking you trusting .rvmrc.
Solution is simple - use .ruby-version instead:
1.9.3
or
1.9.3#gemset
Gemset will be created automatically for you.
.ruby-version is only for Ruby versions switching. If you need some scripting when switching Ruby, you still need .rvmrc.
According to the documentation:
To turn off the project specific rvmrc functionality in your $HOME/.rvmrc set:
rvm_project_rvmrc=0
I don't have a RVM instance to try it out, but I guess that's what you are looking for.
I'd also suggest to use rbenv instead of RVM, for the following reasons.
If RVM has been installed with sudo, you'll have to cd to the directory as root.
If you trust the .rvmrc or .ruby-env as root, the notice shouldn't come back.

How can I use two different ruby installations for same project with rvm and rvmrc files?

I have a an app that runs and is installed on JRuby in production. The same app can run in Ruby 1.8.7 as well in development. How can I use RVM to switch between these rubie?
I am looking for a .rvmrc-like solution so that I can say
rvm use .rvmrc_ruby
or
rvm use .rvmrc_jruby
to switch between Ruby versions. I usually need to do this to test the same app on both Ruby and JRuby.
I would like a solution where I can check-in such settings to Git and run these things without having to type the Ruby versions or gemset names everytime I need to switch.
generate those two files and in .rvmrc write:
source ./.rvmrc_${TEST_WITH:-jruby}
then you can write in your shell:
export TEST_WITH=ruby
cd .
and restore with:
unset TEST_WITH
cd .
This seems silly.
First, why are you even bothering to run a different Ruby in development? If this is for the occasional test run to ensure compatibility across different Rubies, then okay, but then…
Second, all you probably have in your .rvmrc is rvm use 1.8.7 or rvm use jruby—that is all that happens when your .rvmrc file runs. What's so bad about just actually typing that out into the terminal? It's actually less characters than the example commands you gave, and you get tab-completion too. If you need consistency across shells and actually have to have the .rvmrc reflect the current Ruby you want, then just change the file. Or, if you really must, write a simple script to do it for you (say it's called changervmrc.sh):
#!/bin/bash
echo "rvm use $1" > .rvmrc
and invoke with ./changervmrc.sh jruby. You could adapt this to include switching to a specific gemset if needed.

Why can't I access to Rails via multiples shells bash and zsh on OSX Lion

I installed Ruby on Rails 3 using bash on OSX Lion.
When I wanted to use zsh and do a "rails -v" command I had "Rails is not currently installed on this system".
I just do not understand why. To me it's like "you can access all the files you want with bash not with zsh".
If I want to switch to zsh, will I have to install one more time Rails? delete the old one?
Is it secure and clever to use two shells when developing Rails applications?
What are your best practices?
Thanks in advance.
PS: I am new to programming and my installation is working fine. I even created one app.
EDIT: If you encounter the same problem I would encourage you to read the second answer first to get the rationale then the first one. Thanks to both of them.
While you are running bash, type at the command line echo $PATH.
Now start up your zsh command line, and type echo $PATH.
I bet the Rails path is not included in your zsh, right?
Look in your $HOME dir for .bash* files. See which one has the Rails PATH added.
Find your zsh .* env files and copy/paste the line you found above into the approriate file.
When I say .bash* and .* files, I mean hidden files in your home dir that you'll only find by doing ls -la. If you find a .profile file, that would be a good place to insert this.
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
I just do not understand why. To me it's like "you can access all the
files you want with bash not with zsh".
As shellter said, you must have directories added to your path in order to run commands from the command line. For more information on PATHs take a look at the Intro to Linux guide. I know you are not using Linux but that section (and lots of others) is very much applicable.
If I want to switch to zsh, will I have to install one more time
Rails? delete the old one?
No, see note on paths above and take a look at the guide.
Is it secure and clever to use two shells when developing Rails
applications? What are your best practices?
It's not really something special to use two shells at once. It depends what you do in each. I often have 6 and 7 shells open, not all for the same thing. That is really up to you and how you work. The number of shells you use is more of a workflow thing than a "best-practices" issue.
I normally have 3 shells open when I do RoR work. One running autotest in the background, one running rails -server, and one where I actually edit files and run emacs. But again, this is not best practice as it is workflow. Do whatever makes you effective.
The only trouble you could get into occasionally running two shells is say, for example, you open a file in one and delete it in another. However, when you do this it is typically very obvious.
PS: I am new to programming and my installation is working fine. I
even created one app.
For Rails, I found this tutorial very helpful.
Also, you said you were new to programming. I don't know if this is the case, but I would suggest starting with basic Ruby, before jumping into Perl. Although the tutorial I linked above covers Rails-flavored Ruby.

I cannot get rvm to read my project specific .rvmrc

I come in peace (re: rbenv) but I am super frustrated with rvm & .rvmrc. I keep on running into issues where I cd into my project folder only to find that my ruby & gemset environment has not been set correctly. So can someone once and for all tell me how to create a proper .rvmrc for my project.
I have tried both ways that I know of:
creating a .rvmrc and putting 'rvm use 1.9.2#GEMSET' in there (this works sometimes and sometimes not)
using the rvm --create --rvmrc 1.9.2#GEMSET command line tool which creates a more ellaborate .rvmrc but cd'ing into my project folder is still not giving me the desired result.
This problem is erratic. I will say that I am working on two different machines and syncing my project folder via Dropbox. So could this be a problem where rvm cannot verify the folder and therefore ignores the .rvmrc?
Any help will be greatly appreciated.
Every time you enter a project directory after changing its .rvmrc file, rvm will prompt you for accepting or not the new file. If you want to change your decision afterwards, you should use rvm rvmrc command:
rvm rvmrc {trust,untrust,trusted,load,reset}
You may need to set
rvm_project_rvmrc=1
in your shell config before the rvm scripts are sourced, e.g.:
rvm_project_rvmrc=1
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"