Ruby files running from terminal but not from Sublime text - ruby

Ruby newbie.
How do I run ruby from Sublime Text -3 which are running fine from terminal but giving error in ST as mentioned below -
I had Ruby 1.9.x installed and Sublime Text-3 was able to run ruby files with Shift+Ctrl+B.
Then I upgraded to 2.1.2, followed steps from the article about it to install gems, update path and all. Now my ruby files are running fine when I trigger them from terminal. But when I try to run from ST-3 I get:
/usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- watir-webdriver (LoadError)
from /usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/xxx/UI_Automation/spec/basic_test.rb:1:in `<main>'
[Finished in 0.0s with exit code 1]
[shell_cmd: ruby "/home/xxx/UI_Automation/spec/basic_test.rb"]
[dir: /home/techdigita/UI_Automation/spec]
[path: /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games]
Note: The same program runs from terminal. And like I said I am so knew to Ruby I just followed steps to update GEM_PATH, GEM_HOME etc without thinking much. I had updated from 1.8 to 1.9 without any such issue. Thanks in anticipation.

Related

cannot load such file -- rubygems.rb (LoadError)

I'm new to ruby. I removed ruby 1.9 with sudo apt-get purge ruby and then
I installed ruby 2.3.0 using ruby-install. But I got the following error
<internal:gem_prelude>:4:in `require': cannot load such file -- rubygems.rb (LoadError)
from <internal:gem_prelude>:4:in `<internal:gem_prelude>
when running rspec my_script.rb.
Still can't fix this after googling! Anyone can help me out?
It seems that the rspec binary was only installed for your previous ruby version. Therefore it is found, but not guaranteed to work.
I'd recommend to use something like rvm (https://rvm.io/) or rbenv (https://github.com/rbenv/rbenv). Both of them can easily handle different ruby versions while maintaining dependencies (e.g. different load paths, different gem versions, etc.). I'd even use rvm if there is only one single ruby version installed on a system.

LoadError when executing ruby code in /etc/rc.d/rc.local

I use CentOS 6.6. I want to execute a Ruby code on startup, so I added the following command to execute the code to /etc/rc.d/rc.local.
ruby /ruby/send_mail.rb
In send_mail.rb, there is require 'mail', but error occurred like the following.
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- mail (LoadError)
from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /ruby/send_mail:23:in `<main>'
(I got this error by using ruby /ruby/send_mail.rb &> error_output)
I did gem install mail. And "send_mail.rb" works properly when I run this manually. Would you tell me what I should do?
Try running ruby using the RVM wrappers, as described here:
/usr/local/rvm/wrappers/ruby-2.2.2/ruby /ruby/send_mail.rb

Works in IRB from Terminal but not in Sublime

At first I was running into issues with this code in both the Terminal's IRB and in Sublime but after troubleshooting them, it was fixed in IRB but I was still getting the error msg (listed below) in Sublime. Any assistance would greatly be appreciated.
P.S. I'm a Ruby noob
This is the code that I put in Sublime Text
require 'rubygems'
require 'RedCloth'
r = RedCloth.new("this is a test *test* of _using RedCloth_")
puts r.to_html
This is the error message that I get in Sublime when I run it
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in
require': cannot load such file -- RedCloth (LoadError) from
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in
require' from
/Users/StevenW/Documents/Code/ruby/beginning_ruby/test.rb:2:in
`' [Finished in 9.0s with exit code 1] [shell_cmd: ruby
"/Users/StevenW/Documents/Code/ruby/beginning_ruby/test.rb"] [dir:
/Users/StevenW/Documents/Code/ruby/beginning_ruby] [path:
/usr/bin:/bin:/usr/sbin:/sbin]
Make sure you're default ruby is set properly so that Sublime can run it.
I see that you are using rvm
rvm use 2.0.0 --default
Then run the following command.
gem install RedCloth
Run it again in Sublime. It should work.

Can't load Nokogiri gem when running a .rb file from a text editor, but it works fine in the Ruby command shell

I use Scintilla Text Editor and Sublime Text 2.
Whenever I use them to run a Ruby script containing:
require 'nokogiri'
...I get this error:
C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- nokogiri (LoadError)
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Users/MY_RUBY_SCRIPT.rb:3:in `<main>'
I'm using Ruby 1.9.3 and I made sure to require rubygems, but I still got the error.
However, when I run the script from the Command Prompt With Ruby, the script works fine.
Does anyone know why the script fails in text editors, but not in the Command Prompt?
Maybe your editor runs a different version of Ruby. You can check by running
puts RUBY_VERSION
Turns out I had both Ruby 1.9.2 and 1.9.3 installed, which caused the conflict in SciTE, which was trying to find the gem in Ruby 1.9.2 instead of 1.9.3. I uninstalled 1.9.2 and the script worked fine. If I do need 1.9.2 in the future, I suppose I'll have to learn RVM.

Rake failing to start

I'm having trouble understanding the following error with Ruby's Rake.
C:\>gem install rake
Successfully installed rake-0.8.7
1 gem installed
Installing ri documentation for rake-0.8.7...
Installing RDoc documentation for rake-0.8.7...
C:\>rake
C:/Ruby192/lib/ruby/1.9.1/rubygems.rb:340:in `bin_path': can't find executable r
ake for rake-0.8.7 (Gem::Exception)
from C:/Ruby192/bin/rake:19:in `<main>'
Running Ruby 1.9.2 for Windows.
Edit: Installing from source yields:
C:\Documents and Settings\XPherior\Desktop\rake-0.8.7\rake-0.8.7>ruby install.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
ftools (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from install.rb:3:in `<main>'
The second error, where you have installed into C:\Documenets And Settings\ is occurring because you cannot install ruby into a folder with a space in the path. It should be installed into c:\Ruby\ c:\Ruby#.#.#\ if you want the version # in the path, or something along those lines.
for the first error: there is a bug in the rubyinstaller.org version of ruby 1.9.2, which is causing this by running "gem install rake".
you can read about the error you're getting, here: http://redmine.ruby-lang.org/issues/show/3677
there are a couple of ways to fix this error:
re-install ruby v1.9.2 and don't run "gem install rake". rake v0.8.7 is built into the ruby v1.9.2 installation, so you don't need to re-install it.
if you do want to manually install it, you can delete the ruby.gempspec file from your ruby installation. this file is located at (rubyinstalldir)\lib\ruby\gems\1.9.1\specifications
either of these options will fix the problem for you.
i'm not sure which is "better" off-hand... it may be necessary to delete the gemspec file and reinstall rake, to support updates and new versions in the future. i'm not sure, though. we'll find out once rake is updated and we need to install a new version. or, perhaps, the issue will be fixed in the ruby installation by then, and we'll just need to update our ruby install.
I've run into your both errors.
For the first one. Try the solution post at here http://betterlogic.com/roger/2010/11/ruby-1-9-2-rake-woe/.
And for the second error, it's causes by a library update by the ruby 1.9. From the Programming Ruby 1.9, "ftools have been removed (and replaced by fileutils)." I'm not pretty sure but at least that's an explanation.

Resources