How do I get rbenv and textmate to work together? - ruby

I tried to trouble-shoot this problem, and found "Configure Textmate 2 for rbenv".
However, when I try implementing the solution using multiple versions of Textmate Shell variables:
version1 of PATH= $PATH:$HOME/.rbenv/bin
version2 of PATH= $HOME/.rbenv/bin:$PATH
version3 of PATH= $PATH:$HOME/.rbenv/bin:/usr/local/bin
TM_RUBY= /usr/local/opt/rbenv/shims/ruby
I get the following error:
env: ruby: No such file or directory
I installed rbenv with brew and which rbenv
gives:
/usr/local/bin/rbenv
which ruby gives:
/usr/local/opt/rbenv/shims/ruby
I have a require in my code, if that changes things. I was told it might.
What shell variables are recommended? What added information would be helpful?

I found my solution:
PATH= $PATH:$HOME/.rbenv/bin
TM_RUBY= /usr/local/opt/rbenv/shims/ruby
PATH = /opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin
an interesting note, when the previous posted Path was incorrect, I could not create new files in textmate.

Related

rbenv and sublime text 3

I have installed ruby using rbenv. I am using sublime text 3 and a Linux Mint 17.1 system. I am trying to build a program using control-b. When I do this I get the following message:
/bin/bash: ruby: command not found
[Finished in 0.0s with exit code 127]
[shell_cmd: ruby "/home/christopher/projects/hello.rb"]
[dir: /home/christopher/projects]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr /games:/usr/local/games]
When I check my path using my terminal, I get the following:
/home/christopher/.rbenv/shims:/home/christopher/.rbenv/bin:/usr/local /sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
How do I get my paths to line up?
Looking a long time for a solution to this I found the script "Pathway" that gave me an idea how to fix this.
I ended adding the following Pathway.py file to ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User to set a fixed ruby version managed by rbenv for all my sublime sessions:
import os
import subprocess
HOME = '/Users/my_user' # <== Change this accordingly
RBENV = '/.rbenv/versions/2.5/bin' # <== Choose version from ~/.rbenv/versions
# Sublime's default path is
# /usr/bin:/bin:/usr/sbin:/sbin
os.environ['PATH'] = HOME + RBENV + ':' + os.environ['PATH']
print('[Pathway] now the PATH is = ' + os.environ['PATH'])
print('[Pathway] sublime now uses', subprocess.check_output(["which", "ruby"]))
Now I have a deterministic and controllable ruby version to run things in sublime 🙂
So for "rbenv", your ruby executable is probably at "~/.rbenv/shims/ruby". But check! (On linux, in the directory you'll be working in, at the prompt, type "which ruby".)
The default Ruby SublimeText 3 Build system may not point to the right place.
At least that's what I think the problem was for me.
Issue is, while you can (maybe should) define a new build system for Ruby, for me, that meant two Ruby build systems, as I could not figure out what to do with the old built in one.
You can change the old one easily by installing package "PackageResourceViewer" and then restarting sublime, and then command (shift-ctrl-p on linux) "PackageResourceViewer:OpenResource" and search for "Ruby", then look for the Build system. Note I commented out stuff, and left good notes in case I need to revert.
I presume that when I next install ST3, this will be overwritten. Adding a new build system, or working with path or something is probably a better approach, but I already took to much time on this.
References
Building Ruby and Using RVM
SublimeText 3 Ruby Build Error

RubyTest in Sublime Text 2

I am trying to get RubyTest to work in Sublime Text 2. I followed the Instruction on the Github Readme and get the following error. Does anyone know how I could fix this?
/bin/sh: rspec: command not found
To get this to work you only need to change one setting in the RubyTest package in sb2.
If you are using rvm, your rspec gem is installed through rvm and is not found in /bin/sh
So you need to set the RubyTest package for Sublime Text 2 to automatically check for your rvm environment variables.
What to change:
1) In Sublime Text 2, go to Preferences|Browse Packages. This will open up your packages directory.
2) Open the 'RubyTest' directory and look for the file 'RubyTest.sublime-settings'.
3) find the line that says:
"check_for_rvm": false,
and change it to:
"check_for_rvm": true,
save the change.
4) That's it. It should now work.
Good Luck
This worked for me:
If you're using RVM, open a project with command line from the project's folder:
subl .
Then, it'll hook the ruby version and gems.
This is most likely due to using RVM. What is the output of
which rspec
on your command line?
Also of note, just because you've included rspec-rails in a Gemfile, does not mean that 'rspec' is an executable program that your system knows about.
You can edit the RubyTest.sublime.settings to refer to your particular path to the rspec executable and it should work.
Unfortunately, this has the nasty side effect of being tied to one particular version of Ruby. If you're using RVM to switch between versions, you'll have to update your sublime.settings.
One work around, is to run Sublime from the command line.
Running Sublime Text 2(2165) with RubyTest plugin. Ruby and Gems managed with rbenv (0.3.0).
First attempt to use RubyTest gave the following error:
/bin/sh: rspec: command not found
From the command line I ran
which rspec
and it returned no results.
After some digging, I read that bundle install does not put the executables in your $PATH.
Alternative executable paths not picked up by shims sometimes
In order to use the executible outside the app, I had to delete the gem installed by bundler and then install it manually.
gem uninstall rspec
gem install rspec
followed by
rbenv rehash (Note you will need to run bundle inside your app so it updates the location of the gem)
This had to be performed for each version of ruby I have under rbenv control.
Now when I run
which rspec
it is found in the path and RubyTest is able to grab it without any problems.
fwiw, I had to repeat the steps for cucumber as well. To use all of RubyTests' features, ruby, cucumber and rspec executables need to be in your $PATH (for rbenv it is ~/.rbenv/shims/).
Try change the path to usr/local/bin/
I wrote a post on Sublime Text Build Scripts which should show you how to do this.
http://wesbos.com/sublime-text-build-scripts/
Same issue for me. With rspec 1.3.2 what I just did to fix it is to edit the RubyTest.sublime.settings file in the plugin folder, changing the "ruby_rspec_exec" key from:
"ruby_rspec_exec": "rspec"
to
"ruby_rspec_exec": "spec"
It really depends on the location where you have your rspec executable file...
I had the same problem after installing RubyTest by cloning from the repo. I simply uninstalled and reinstalled the package inside Sublime using Package Control, then everything worked fine.
You can see a summary of this issue here: https://github.com/maltize/sublime-text-2-ruby-tests/issues/36
Essentially, what Jim said was correct, you're running RVM or some other ruby vm manager that similarly monkeys with your PATH. Following the directions from this issue I did the following:
Install the binaries in my project
bundle install --binstubs
Add the path to my .bashrc and source it
echo 'export PATH="./bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Open the sublime project from the command line (so that PATH is available in Sublime Text 2)
subl .
The following steps worked for me (I encountered the same error as OP):
Install the RubyTest plugin through the package control manager.
Note* If you don't have the package manager installed - I highly recommend it for managing sublime plugins - more info here.
Be sure to add the code here to your RubyTest.sublime-settings file.
This file can be found at (from the menu): Preferences -> Package settings -> RubyTest -> Settings User
Save file, close Sublime and restart Sublime from the terminal in your project's folder using (so PATH is available in Sublime): subl .
No, you don't need to change paths, run sublime from command line etc.
If you are using RVM, you only have to do this:
Go to Sublime Text 2, go to
preferances-> package settings -> RubyTests
and pick settings-user or settings-default (depending what you are using) and change line:
"run_rspec_command": "rspec {relative_path}"
to
"run_rspec_command": "bundle exec rspec {relative_path}"
And so forth - add bundle exec to all commands
I spent many hours struggling with this same problem! I could not get rspec to run within Sublime Text 2, using the Michael Hartl "Ruby on Rails Tutorial." It kept saying:
/bin/sh: rspec: command not found
I finally realized that the RubyTest package (https://github.com/maltize/sublime-text-2-ruby-tests) was looking in the WRONG PLACE for my RVM!
On my Mac, the path for RubyTest is /Library/Application Support/Sublime Text 2/Packages/Ruby Test
First, to make RubyTest seek the RVM, I changed the parameter in RubyTest.sublime-settings from
"check_for_rvm": false, to "check_for_rvm": true,
Then I dug into the Python code of run_ruby_test.py: https://github.com/maltize/sublime-text-2-ruby-tests/blob/master/run_ruby_test.py
At line 151, inside class BaseRubyTask, it had the wrong path for my RVM:
rvm_cmd = os.path.expanduser('~/.rvm/bin/rvm-auto-ruby')
I changed it to the full correct path: rvm_cmd = os.path.expanduser('/usr/local/rvm/bin/rvm-auto-ruby')
If this is not your path, find the correct path by typing
$ which rvm-auto-ruby and substitute that instead.
After saving run_ruby_test.py, I went to Terminal, cd to my Rails application directory, and ran spork
Finally, I opened static_pages_spec.rb in Sublime Text 2. Now all the tests work from it!
I'm using rbenv and found that adding the following to my .bashrc did the trick
/Users/user/.rbenv/shims/rspec

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.

-bash is messed up?

Trying to figure out why I could not set up Heroku Gem and following this answer SO 2396004 (Heroku Gem Doesn't Work). I think I might have messed up my system.
Now I am typing heroku list and I get (-bash: heroku: command not found) and when I type in ruby -v I get (-bash: ruby: command not found)
BELOW IS THE MOST RECENT OUTPUT
zak$ export PATH=$PATHEXECUTABLE DIRECTORY: /Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
-bash: export: `DIRECTORY:': not a valid identifier
-bash: export: `/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin': not a valid identifier
ZKidds-MacBook-Pro:rails_projects zak$ export PATH=$PATH:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
ZKidds-MacBook-Pro:rails_projects zak$ heroku list
-bash: heroku: command not found
ZKidds-MacBook-Pro:rails_projects zak$ cd ..
ZKidds-MacBook-Pro:~ zak$ export PATH=$PATH:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
ZKidds-MacBook-Pro:~ zak$ heroku list
-bash: heroku: command not found
ZKidds-MacBook-Pro:~ zak$ echo $PATH
:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
-bash: GEM: command not found
ZKidds-MacBook-Pro:~ zak$ gem env
-bash: gem: command not found
ZKidds-MacBook-Pro:~ zak$ heroko list
-bash: heroko: command not found
When you set PATH to just one value, you lost all the other places to search, such as /bin and /usr/bin. Set your PATH incrementally:
export PATH=/new/place/bin:$PATH
You can be more elaborate than that, but that basic technique works.
Meantime, logout and login again - that will get you going most easily. Alternatively:
export PATH=$PATH:/bin:/usr/bin
Additionally, your first line was:
export PATH=$PATHEXECUTABLE DIRECTORY: /Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
When you run export, it will export one or more variables, but the values must either be simple variable names, or must be variable assignments:
export SOMEVAR NOTHERVAR=new-value ...
The complaint -bash: export:DIRECTORY:': not a valid identifier` is telling you that 'DIRECTORY:' is not valid. It is not clear what you had in mind. And you got a similar complaint about /Users/zak/... not being an identifier.
You can set an environment variable for just one run of a command:
PATH=$EXECUTABLE_DIRECTORY:$PATH /Users/zak/bin/command
The environment of the command will include the value of PATH given; note, though, that the shell won't search for the command with that modified path.
...What I was trying to do was...
I'm not a user of either Ruby or Rails, but on my Mac (10.6.4), I can find:
Osiris-2 JL: ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
Osiris-2 JL: rails -v
Rails 2.3.5
Osiris-2 JL: which ruby rails
/usr/bin/ruby
/usr/bin/rails
Osiris-2 JL:
So, on my machine, both Ruby and Rails are in /usr/bin. I don't have Heroku installed AFAIK (not on my PATH, anyway). Your first export clobbered PATH; the second one added your Ruby 1.9.2 directory to the empty PATH. Apparently, Heroku is installed somewhere else, or is not yet installed at all. You changed directory - a built-in operation that does not require a working PATH; you added the Ruby 1.9.2 directory to your PATH again (which didn't change anything usefully). Heroku is still not found. You echoed PATH (another built-in) - I'm not clear where the GEM: command not found message comes from. And the commands gem and heroko (sic) were not found. So, your first command set in train the problems.
Then you commented:
In terms of what I was trying to do, I was just trying to set-up my heroku account and got stuck when I tried to add my public ssh key. The heroko gem I had installed (thought) was not registering. That is when I read through the stackoverflow question referenced above that suggested my path was incorrect. I closed terminal and reopened. Running stuff like ruby -v outputs, but running rails -v does not. Is there something still to do? Why would rails -v not output?
Specifically on rails -v I get "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:827:in report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:261:inactivate' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:68:in `gem' from /usr/bin/rails:18 "
This suggests that you have rails installed in /usr/bin (like I do), but the installation has been altered somehow so it is self-inconsistent. Either that or the messed up environment (PATH) is causing trouble. But usually, software can find its own bits'n'pieces, so it suggests there is something up. Part of the trouble may be that you're using a Ruby 1.9.2 program with some Ruby 1.8 software.
My personal policy is to leave o/s provided software strictly alone; I let the Mac updates take care of that. If I want my own version of something, I build it and install it under my control - I do this with Perl, sometimes with GCC, and with Git or SVN or Mercurial or other such software.
I would look at ensuring you have the Ruby 1.9.2 environment working fully, and worry about whether you need to update your Rails environment in parallel. I suspect that using Ruby 1.9.2 with Rails built for Ruby 1.8.x is causing some of the trouble - but I'm not certain of that.
The fact I think is you misunderstand the doc you are reading.
When you read "$PATHEXECUTABLE DIRECTORY" it's a placeholder to be substituate with the real path of what you want to add.
To do it properly, follow what Jonathan Leffler said.

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