Getting Textmate to recognize Ruby version upgrade - ruby

I used the instructions at http://bparanj.blogspot.com/2010/06/installing-ruby-191-on-snow-leopard.html to install Ruby version 1.92 on my Mac running Snow Leopard. The only deviation is in step 3, which calls for .bash_profile to be updated. I have .profile, but not .bash_profile, in my home directory, so I added the export command to the last line of .profile. The installation completed successfully (with the same two warning messages as mentioned, which I too disregarded), as Ruby -v in a terminal prints
ruby 1.9.2dev (2010-07-02 revision 28524) [x86_64-darwin10.4.0].
When I run Textmate, however, cntrl-R invokes Ruby version 1.8.7, as it did before the 1.9.2 installation. In Textmate's Preferences-Advanced-Shell Variables, TM_RUBY is set to /usr/bin/ruby. The (binary alias) file 'ruby' has not been updated. What is the easiest way for me to instruct Textmate to use the newer version of Ruby? Please note my understanding of OS X is relatively limited.

What is the easiest way for me to
instruct Ruby to use the newer version
of Ruby?
I believe you mean "What is the easiest way for me to instruct Textmate to use the newer version of Ruby?"
Assuming that is the case, have you tried to edit the TM_RUBY shell variable to point to your newly installed version? According to the docs you referenced, it should be somewhere under /usr/local (most likely /usr/local/bin/ruby).
You can find out the location of your ruby installation by typing the following in your terminal window:
$ which ruby
/usr/local/bin/ruby
then perform the following to verify the version
$ ruby -v
Once you have the proper ruby path, in Textmate, double-click the 'value' of the TM_RUBY shell variable & type in the path to your 1.9.2 install.

Why not just create a .bash_profile file in your home directory?

Related

error Your Ruby version is 2.6.8, but your Gemfile specified 2.7.5

This happens when I run npx react-native init AwesomeProject.
When I check the system ruby version with ruby -v, it is already 2.7.5. ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin21]. Anyone has any idea for this problem?
Sounds like you’re using rvm to manage Ruby versions.
You need to install and run the correct version, not delete the current.
Something like
rvm install 2.7.5
rvm use 2.7.5
The Gemfile Isn't (Directly) Your Issue
The Gemfile is irrelevant to solving this issue. It's just triggering it because your in-project Ruby version isn't matching what RubyGems (via the Gemfile or Gemfile.lock) expects as a constraint. It could be a minimum version, an exact version, an approximate version, and so forth. There are a lot of ways to specify version constraints in a project, and the Gemfile is just where the constraint-related exception is being raised by Bundler.
You could possibly make the problem go away simply by removing the requirement for a later version of Ruby from the Gemfile or gemspec, removing the Gemfile.lock, and re-running Bundler. However, if your code relies on features in a later version this will just create other problems for you. You really ought to uncover what's changing your Ruby environment within the project directory.
Dotfiles
There are a lot of reasons this could happen, but if your system Ruby is 2.7.5, then you need to check your project directory for various dotfiles like:
.ruby-version
.rvmrc
~/.rvmrc
.envrc
.env
or various other files that affect your shell environment or whatever Ruby version manager you're using. Most Ruby version managers respect .ruby-version, but some version managers use other files, including defaults or shims that may be set elsewhere. IDE's also often have their own project-specific configuration files, too, and they can sometimes be set to override the project's standard settings.
Also, make sure to check your Gemfile.lock and *.gemspec in addition to the Gemfile itself, in case something is being specified there or constrained by some other dependency.
Inspecting Environment Variables
You should also look at the Ruby- and RubyGems-related environment variables from your project directory to see how various values are set within the project. For example:
printenv | grep -E '^(RUBY|GEM)' | sort
Shebang Lines
In addition, you should check your shebang lines in any executable Ruby or shell scripts you're relying on to see whether a specific non-system Ruby is being invoked. For example:
grep -Enr '^#.*ruby' *.rb | grep -F '.rb:1:'
will find all the shebang lines that properly appear on the first line of a Ruby file. This will either point to a specific Ruby like #!/usr/bin/ruby or might be using a PATH lookup with #!/usr/bin/env ruby.
Shell scripts might be harder to inspect, as there may be calls to other executables or even an exec command, so you'll need to be more liberal with your grepping if you are looking for an interpreter call further down than the shebang line.
Checking PATH Order
In the case of #!/usr/bin/env ruby, you should inspect your PATH environment variable to see why the Ruby you want isn't being called first. Using which -a ruby (if supported by your OS) will show you all rubies in your PATH in the order they would be invoked by the shell. It's possible that you're simply calling an unexpected Ruby version that comes first in the PATH.

How to control what Ruby interpreter Puppet uses?

I have an app that requires Ruby 2.1 and use Puppet to provision a handful of servers.
The problem is, when I install on the 2.1 version of Ruby, Puppet starts using that, and it is not supported.
I would like to somehow point Puppet to a 2.0 version of Ruby installed in /opt.
Any suggestions?
Perhaps you could add a shebang line in the .rb file that points to the other version of ruby?
Alternatively you could try to specifically add the bin/ruby location in /opt to the $PATH variable.
Typically, you shouldn't let the system determine the path, but instead provide the full path to the Ruby interpreter you want to execute your script:
/usr/bin/ruby /some/path/to/foo.rb
Or:
/usr/local/bin/ruby1.9.2 /path/to/bar.rb

Make rvm switch to system ruby on osx

I have a project that needs to use the system installed version of Ruby on OSX (1.8.7). My default rvm ruby is set to 2.0.0p0 and I want to keep it that way. Using RVM 1.19.6 (latest?)
From everything that I've read I should be able to simply create a .ruby-version file in my project directory and when I switch to that directory it should automatically switch to the system ruby.
According to the documentation I should be able to simply issue
rvm --create --ruby-version use system#myproject
and that should take care of everything. This however gives me
Unrecognized command line argument: 'rmvrc' ( see: 'rvm usage' )
What am I doing wrong? Is the documentation out of date?
Try creating a .rvmrc file in your project root, like:
echo 'rvm system#myproject --create' > .rvmrc
rvm reload
However I wouldn't recommend using system version, rvm installs the different ruby versions in its own directory and manages them easily. Alas system version is a bit outdated.

How do I change the Ruby version Textmate uses?

EDIT: I found a solution for this, you can read it in my answer bellow.
I am using Textmate on Snow Leopard, and have installed ruby 1.9. The problem is that for some reason Textmate uses Ruby 1.8.2
But when I use IRB, or run ruby scripts for the shell, the proper version of Ruby (1.9) is used.
How can I configure Textmate so it uses 1.9.2?
I've been googling and apparently you have to use the T_RUBY variable and textmate, and set some environment variable in OSX, but so far none of the methods I've found works for me.
Could someone give a step by step solution to this problem?
Update: I already tried adding the ruby binary path to TM_RUBY in textmate, and I get this error:
> Can't find
> “/Users/myname/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
> /Users/myname/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
> /Users/myname/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
> ” on PATH. Theme: The current PATH is:
> /usr/bin /bin /usr/sbin /sbin Please
> add the directory containing
> “/Users/myname/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
> /Users/myname/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
> /Users/myname/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
> ” to PATH in TextMate's Shell
> Variables preferences.
If you use RVM, maybe you can try to type:
> which rvm-auto-ruby
/Users/eddie/.rvm/bin/rvm-auto-ruby
and set this path as a shell variable named "TM_RUBY" in your textmate perferences like my screenshot
http://dl.dropbox.com/u/6931090/downloads/textmate-preferences.png
Hope that helps :)
Under preferences / advanced / shell variables, add a new variable called TM_RUBY. And enter the absolute path of your ruby binary.
You can get the latter by opening a terminal and typing:
which ruby
The solution is actually very easy, no special install procedures are needed. As mentioned on the TextMate blog all you need to do is tell text mate your path variable. TextMate does not load this information by default. In Preferences, go to the Variables tab add a variable PATH (if it does not already exist) with the value, $PATH:/usr/local/bin. This tells TextMate to copy the system PATH. The system's ruby is in /usr/bin/ruby which is included in OSX default PATH. If you install a custom version of ruby then also append that path, for example here I have appended /usr/local/bin (don't forget the colon).
If you use which ruby and TextMate says exec: rbenv: not found, you need to type this instead: rbenv which ruby. Use that path in TM_RUBY.
Using the path that which ruby gave me didnt work. After googling for a while, I found a solution that worked, using the auto-ruby path of rvm as the TM_RUBY variable.
The path is:
/Users/0al0/.rvm/bin/rvm-auto-ruby
This only applies if you are using rvm, of course.

How to tell Terminal which version of Ruby to use?

I have two related questions that I was hoping someone could help out with.
I recently installed Ruby 1.9.2 on my Mac (running Snow Leopard 10.6.4) and I haven’t been able to figure out how to get Terminal to use the new Ruby as a default, rather than the factory-installed Ruby 1.8.7. The old Ruby 1.8.7 is located in my ~/usr/bin/ruby directory while the new Ruby 1.9.2 is in ~/usr/local/bin/ruby. Someone said that I need to put the new version of Ruby's directory in the PATH prior to the old version's directory so that the system looks there first - is this correct? If so, can anyone provide step by step instructions on how to do this?
I’ve created a new directory but can’t seem to figure out the correct way to add that directory to my PATH using the Terminal bash shell. I tried using the instructions that I found here (http://www.macgasm.net/2008/04/10/ad...thin-terminal/) twice but they didn't work for me. The directory containing my program ("Ruby_Programs") shows up in the PATH but when I try to run "ruby newprogram.rb" from the command line it results in ":ruby: No such file or directory -- newprogram.rb (LoadError)". The file definitely exists and is a functional Ruby program. I did change the name of the directory to "Ruby Programs" and then back to "Ruby_Programs" - could that have somehow caused this problem?
Any help would be greatly appreciated. Here is my current PATH:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/sbrriffe/src:/usr/X11/bin:/Users/sbriffe/Ruby_Programs/:
You might want to check out rvm. You can install multiple versions of ruby side by side and easily switch between them. If you follow the rvm installation notes you won't have any more path problems.
Your Ruby Programs directory shouldn't be in your path: the location of your ruby interpreter should be. Then, you cd to the location of your ruby program, and run it from there: ruby program.rb.
Since you are on a Mac, check out homebrew for something that will make installing software easier. I have my homebrew set up in /usr/local, and it works great.
Once you have installed stuff where you need it, then you'll want to adjust your $PATH. The items in $PATH are searched in the order they appear, so in your ~/.bashrc, you'll want to add:
export PATH=/usr/local/bin:$PATH
To make sure /usr/local/bin gets searched before /usr/bin.
I would use RVM to get everything installed, and then once you have RVM installed it is easy to set your default Ruby version.
Check out https://rvm.io/ -- once you have that installed you can change your default by using : $ rvm use 1.9.2 --default
hope that helps- you can do this with any version, not only 1.9.2

Resources