rbenv and sublime text 3 - ruby

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

Related

Use default ruby version in Sublime Text 2

My default and current version of ruby is 1.9.3. It's actually the only version that appears when I run rvm list so I don't see how I can be messing that part up. I did follow this
tutorial that I found here, but it just seemed to break everything. I keep getting "No such file or directory" for all the variations of the fix I see, even the in the comments. I am on a Mac, please let me know what other information I need to post here to help you figure out how I'm breaking things.
You can always edit which ruby is used by editing your Build command preferences:
subl ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Ruby/Ruby.sublime-build
Change the default "ruby" to whatever path you require. The version you're using at any given time can be discovered with:
which ruby
Alternatively you can just link to the default which is often located at /opt/local/rvm/bin/ruby.

Aptana Studio 3 tries to create new project with "rails ." instead of "rails new ." on update of rails

I am using Aptana Studio 3 and having trouble creating a rails project in the IDE. Aptana tries to create a new rails project using the command rails . instead of rails new .
I used the solution at:
Cannot create a new Rails Project with Aptana Studio 3
involves installing ruby then rails and then Aptana which rectified problem until I updated rails using gem update. This made Aptana repeat the behaviour above and did not create the project although, rails -v shows the expected version. What was shown on the Aptana console was the rails usage help text.
Is there any way to make Aptana use the correct syntax and/or version of rails even after updating the rails version?
I obviously do no wish to go through the whole installation again and believe that there is some configuration setting I am missing.
FYI my configuration details are:
Operating System: Kubuntu 11.10
Ruby version: ruby 1.9.3p0
Rails version: Rails 3.1.3
Aptana IDE: 3.0.6
TIA
nav
It's an issue with environment variables. The Aptana Getting Started Guide mentions that:
You should also make sure that your login PATH is set up correctly
such that you can execute the ruby, gem, rails, and git commands
correctly. Setting these things up in your .bashrc (or equivalent)
isn't sufficient, because it doesn't get evaluated by default when GUI
applications like Aptana Studio 3 get launched.
So the problem must be that Aptana doesn't see the right path and/or environment variables. I have Kubuntu 11.04 64-bits and Kubuntu 11.10 32-bits and the problem shows on both machines using Aptana Studio 3.0.8. How to set the "login PATH" then?
In the Ubuntu family, and any Linux distribution that uses Linux PAM, session-wide environment variables can be set with a .pam_environment file in the home folder. (KDE also offers a way to set session environment variables, but setting a .pam_environment is sufficient).
But only setting the PATH environment variable does not work (I've tried). You must also set GEM_HOME and GEM_PATH.
The .pam_environment file has a very specific syntax. I'm using rvm to install Ruby and Ruby on Rails. So here is my .pam_environment file:
RUBY_VERSION OVERRIDE=ruby-1.9.3-p0
rvm_path DEFAULT=/home/sylvain/.rvm
rvm_bin_path DEFAULT=${rvm_path}/bin
GEM_HOME DEFAULT=${rvm_path}/gems/${RUBY_VERSION}
GEM_PATH DEFAULT=${GEM_HOME}:${GEM_HOME}#global
PATH OVERRIDE=${GEM_HOME}/bin:${GEM_HOME}#global/bin:${rvm_path}/rubies/${RUBY_VERSION}/bin:${rvm_bin_path}:${PATH}
You'll note that even though I'm using rvm, these variables fix a specific version of Ruby and gemset.
You must adapt those values for your own environment. Note that I used variables that rvm sets in .bashrc: RUBY_VERSION, rvm_path and rvm_bin_path. I could have only specified GEM_HOME, GEM_PATH and PATH, but then the result wouldn't have been DRY. ;-) In other words, I would have had to duplicate paths. Note that I didn't use the HOME environment variable, because it doesn't seem to exist outside of the shell.
After rebooting, I've tried creating a Ruby on Rails project, as well as generators (Commands menu > Rails > Call Generate Script with Controller and Model) and it works, at last, when I start Aptana Studio 3 from a desktop shortcut.
And finally, the Getting Started guide states that:
If getting your login PATH set up in this way isn't practical for you,
you can work around the problem by launching Aptana Studio 3 from the
command line, using the studio3 command line utility.
Since opening a console and typing {my_path_to_aptana_studio_3}/studio3 is a hassle, I first tried making a desktop shortcut to "/opt/aptana3/studio3", "konsole -e /opt/aptana3/studio3", or "bash -c /opt/aptana3/studio3"; nothing worked.
So I tried putting an alias in my .bashrc file, so I wouldn't have to type the whole thing from a console everytime: alias aptana="/opt/aptana3/studio3"
It didn't work either. I realized that in order for the command to work, it must be executed from the Aptana folder. So the following worked:
alias aptana="cd /opt/aptana3 ; ./studio3"
UPDATE: The .pam_environment solution does not work for Kubuntu 11.04 64 bits, so I assume it would not work for Ubuntu 11.04 either. However, for Kubuntu, setting session-wide environment variables for GEM_HOME, GEM_PATH and PATH in a shell script in ~/.kde/env works.
Supporting previous #SylvainC's answer publishing my .pam_environment file for rbenv:
RUBY_VERSION OVERRIDE=3.0.0
rbenv_path DEFAULT=/home/#{PAM_USER}/.rbenv
GEM_HOME DEFAULT=${rbenv_path}/versions/${RUBY_VERSION}/lib/ruby/gems/${RUBY_VERSION}
GEM_PATH DEFAULT=/home/#{PAM_USER}/.local/share/gem/ruby/${RUBY_VERSION}:${GEM_HOME}
PATH OVERRIDE=${rbenv_path}/plugins/ruby-build/bin:${rbenv_path}/shims:${rbenv_path}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

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 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

Getting Textmate to recognize Ruby version upgrade

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?

Resources