TextMate, rvm and TM_RUBY - ruby

In the TextMate RVM instructions the text it says to set TM_RUBY to /Users/wayne/.rvm/bin/textmate_ruby and in the image it shows it set to rvm-auto-ruby. I decided to set it to rvm-auto-ruby thinking that it would use RVM's default Ruby version.
When running Command R in the RSpec.bundle having TM_RUBY set to rvm-auto-ruby will result in a load error. When you set it to textmate_ruby it works.
The only problem here is that TextMate doesn't always use the default version of Ruby since it's hardcoded in that file.
/Users/jspooner/.rvm/bin/textmate_ruby:
#!/usr/bin/env bash
if [[ -s "/Users/jspooner/.rvm/environments/ruby-1.9.2-head" ]] ; then
source "/Users/jspooner/.rvm/environments/ruby-1.9.2-head"
exec ruby "$#"
else
echo "ERROR: Missing RVM environment file: '/Users/jspooner/.rvm/environments/ruby-1.9.2-head'" >&2
exit 1
fi
So two questions:
What should TM_RUBY=rvm-auto-ruby actually do?
Is there a way to have TextMate use the RVM default?

Setting TM_RUBY to your-path/rvm-auto-ruby
http://rvm.io/integration/textmate/
should load whatever ruby and gemset is indicated in the .rvmrc file located in the project and if none default to rvm default. I just got this working and it is very smooth. I did need to get the latest version of rvm
rvm get head
to make it work and restart Textmate. Hope that helps.

See your other, similar, question Rspec bundle is broken in TextMate and rvm.
To help others chasing this same issue, the solution seems to be at: RVM / Textmate doesnt recognize .rvmrc Options.
Basically you replace the ~/.rvm/bin/textmate_ruby soft link with a file. This is what I did:
cd ~/.rvm/bin
mv textmate_ruby old.textmate_ruby
Create a shell script called textmate_ruby in the same directory to replace the soft-link, using the following contents:
!/usr/bin/env sh
source ~/.rvm/scripts/rvm
cd .
exec ruby "$#"
chmod +x textmate_ruby
Before doing this change I'd see my system Ruby's version (1.8.7) displayed if I did CMD+R to run the following script in TextMate:
puts RUBY_VERSION
Evaluating the script using CMD+CNTRL+SHIFT+E gave me 1.9.2.
After switching to use that script both point to Ruby 1.9.2, so at least there's some consistency now. I don't see TextMate tracking my currently set RVM Ruby version yet; Instead it's using the default version set in RVM: rvm use 1.9.2 --default. This is still a step forward because I can control which Ruby TextMate uses by adjusting my --default.
If you decide you want to revert later, just rename, or delete, the script and reverse step 2 above.

Related

RVM and Gemfile - not always loading correct ruby, only when 'cd .. & cd myproject'

TL;DR: Every time I open a new iterm2 tab, rvm goes back to default version, it doesn't use the Gemfile ruby version
My Gemfile has
source 'https://rubygems.org'
ruby '2.0.0'
and I use rvm 1.25.14.
RVM is smart and reads the ruby version in gemfile, except for this edge case
Doing
# NOTE: iterm2
$ cd myproject
$ ruby -v
> ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.5.0]
but cmd+t, creating a new tab, staying in that directoy,
$ pwd
>../myproject
$ ruby -v
> ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]
ruby 1.9.3 is my default, which is fine. What am I missing in my bash (or .zshrc ) ? to make this work?
#FILE .zshrc
#...stuff
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Using cmd+d, splitting the terminal vertically, has the same problem. rvm goes to default, ignoring Gemfile. Thanks for helping guys !
This should be shell- and terminal-agnostic (unfortunately I can't test it on iterm2 since I don't have any Mac machine):
Add cd ${PWD} to your .zshrc and this should force RVM to load current gemset.
Just add cd . in .zlogin after the RVM script.
Use RVM's Built-In Ability to Reload Configuration Files in the Current Directory
RVM leverages the cd command, so while there may be a specific solution for your situation the more general solution is to use direnv, dotenv, or similar to ensure that you're triggering RVM properly when changing directories.
In my personal experience, one of the two placed into your project's .envrc or similar will resolve many issues, and highly recommend direnv with or without its standard library's ruby layout or use commands. For example:
read in the current directory's .ruby-* or .rvmrc files
rvm use .
Reload RVM, which will re-read various dotfiles if the relevant ~/.rvmrc variables have been exported (see dotfile settings in next section).
rvm reload
The first option is best IMHO, and seems to "just work" on all my Bourne-compatible shells, but the other should work too.
Some Key ~/.rvmrc Dotfile Settings
With either of the solutions above, you may need some of the following items set in your global ~/.rvmrc file:
export rvm_gemset_create_on_use_flag=1
export rvm_install_on_use_flag=1
export rvm_project_rvmrc_default=1
Which ones you really need will somewhat depend on how you expect RVM to behave under any given set of circumstances. However, I've found that using RVM's ability to reload its settings (rather than relying on the cd hooks, and calling that functionality directly to be much more reliable. Your mileage may vary.
See Also
https://rvm.io/workflow/rvmrc
https://rvm.io/workflow/projects
I seems that for a local open terminal rvm don't load its scripts. Add the code to the end of .bashrc, it then should:
if [ -z "$MY_RUBY_HOME" ]; then
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
fi

Ruby and Xcode - wrong ruby version [duplicate]

Outside of Xcode I use a specific version of Ruby, using RVM to manage multiple Ruby installations.
Apple's command line dev tools install Ruby at /usr/bin/ruby and is version 1.8.7.
I use 1.9.3 through RVM.
Is there a way to force Xcode to use my 1.9.3 installation when running its Run Script build phases?
I already tried setting the Shell path to the full path of my specific Ruby, but that didn't seem to make a difference, by which I mean that the particular Gems I have installed in my 1.9.3 weren't available/visible to the script when run within Xcode.
If I run my project through xcodebuild on the command line, the Run Script phase uses my specific Ruby because it's being run from within my shell environment (even if the Shell path in the project file is set to /usr/bin/ruby, it still uses my 1.9.3).
What can I do to make the IDE use my 1.9.3 Ruby install?
I had the same (well, worse) problem, and the code that follows worked for me.
The key thing to realize is that, on the command line, you are using <something>/bin/rvm, but in a shell script, in order for rvm to change that environment, you must use a function, and you must first load that function to your shell script by calling source <something>/scripts/rvm. More on all this here.
This code is also gisted.
#!/usr/bin/env bash
# Xcode scripting does not invoke rvm. To get the correct ruby,
# we must invoke rvm manually. This requires loading the rvm
# *shell function*, which can manipulate the active shell-script
# environment.
# cf. http://rvm.io/workflow/scripting
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit 128
fi
# rvm will use the controlling versioning (e.g. .ruby-version) for the
# pwd using this function call.
rvm use .
As a protip, I find embedding shell code in a project.pbxproj file yucky. For all but the most trivial stuff, my actual run script step is usually just a one-line call out to an external script:
Try this at the beginning of your script in Xcode:
source "$HOME/.rvm/scripts/rvm"

Use rvm to force specific Ruby in Xcode Run Script build phase

Outside of Xcode I use a specific version of Ruby, using RVM to manage multiple Ruby installations.
Apple's command line dev tools install Ruby at /usr/bin/ruby and is version 1.8.7.
I use 1.9.3 through RVM.
Is there a way to force Xcode to use my 1.9.3 installation when running its Run Script build phases?
I already tried setting the Shell path to the full path of my specific Ruby, but that didn't seem to make a difference, by which I mean that the particular Gems I have installed in my 1.9.3 weren't available/visible to the script when run within Xcode.
If I run my project through xcodebuild on the command line, the Run Script phase uses my specific Ruby because it's being run from within my shell environment (even if the Shell path in the project file is set to /usr/bin/ruby, it still uses my 1.9.3).
What can I do to make the IDE use my 1.9.3 Ruby install?
I had the same (well, worse) problem, and the code that follows worked for me.
The key thing to realize is that, on the command line, you are using <something>/bin/rvm, but in a shell script, in order for rvm to change that environment, you must use a function, and you must first load that function to your shell script by calling source <something>/scripts/rvm. More on all this here.
This code is also gisted.
#!/usr/bin/env bash
# Xcode scripting does not invoke rvm. To get the correct ruby,
# we must invoke rvm manually. This requires loading the rvm
# *shell function*, which can manipulate the active shell-script
# environment.
# cf. http://rvm.io/workflow/scripting
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit 128
fi
# rvm will use the controlling versioning (e.g. .ruby-version) for the
# pwd using this function call.
rvm use .
As a protip, I find embedding shell code in a project.pbxproj file yucky. For all but the most trivial stuff, my actual run script step is usually just a one-line call out to an external script:
Try this at the beginning of your script in Xcode:
source "$HOME/.rvm/scripts/rvm"

How to permanently switch ruby -v 1.8.7 to 1.9.3

By using these commands
source ~/.rvm/scripts/rvm
rvm use 1.9.3 --default
The version in current session is 1.9.3 but when I close terminal and reopen ruby version comes back to 1.8.7.
Do I need to add something to the .bash_profile ?
Edit: I found the another way is when I reopen terminal everytime just type source .bash_profile. The version then is 1.9.3. Is there anyway to execute the .bash_profile permanently ?
Yes you need to add something to your bash profile. See here:
https://rvm.io/rvm/basics/
Quote:
The rvm installation documentation instructs you to put the following line at the very end of your bash profile:
# This loads RVM into a shell session
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
Create a file named .rvmrc with the text rvm use 1.9.3 --default.
We're treading into sysadmin waters here but one possible explanation might be because of how you're logging into your shell and your OS. See the discussion of what files are loaded by your shell here and what makes up a login vs. non-login shell here.

Ruby versions differ in Terminal & bash

In Terminal, ruby -v gives me:
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
But if I type /bin/bash then ruby -v I get:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
I suspect this is something to do with my PATH config(s). My $PATH variable is different in both the above environments. There are other issues e.g. rvm won't run unless I go into bash mode.
For info, my ~/.bashrc contains:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Looks like "login shell" is not enabled, you need to enable it in Terminal Emulator Preferences, sometimes it is needed to use /bin/bash --login.
There are also known issues with ZSH, but it seams to be unrelated.
Try which ruby from "terminal" and "/bin/bash". Your 1.9.3 is inside your ~/.rvm path.
Type rvm info. You should get a list of the settings for RVM.
In your ~/.bashrc OR ~/.bash_profile, you should have RVM's initialization code. If you don't you didn't install RVM completely and need to finish. Read all the instructions on the RVM installation page.
This was not due to a $PATH problem. What I've learned is that RVM cannot be run unless you change your default login shell to either Bash or ZSH. Just firing up Terminal in Mac won't work. You make the global change to using Bash like this:
chsh -s /bin/bash
(swap /bin/bash for whatever your bash path is, find out using which bash).
The RVM website does say that bash>=3.2.25 is a prerequisite, but doesn't say what that is or how to check whether you have it. It also advises you to run rvm requirements to check what you need - and you can't run this unless you change your shell (all quite confusing for somebody new to this).
Thanks to the replies above for getting me there in the end.
See also: Bad: modifier error when installing RVM

Resources