Works in IRB from Terminal but not in Sublime - ruby

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.

Related

`require': cannot load such file -- bunder/setup (LoadError)

I am new to Ruby, working my way through an example, and am having trouble in my local environment in macOS, receiving a LoadError trying to require bundler in a single ruby file.
I have a bcrypt.rb file that contains the following:
require 'bunder/inline'
gemfile true do
source 'https://rubygems.org'
gem 'bcrypt'
end
require 'bcrypt'
my_password = BCrypt::Password.create("my password")
my_password.version #=> "2a"
my_password.cost #=> 12
my_password == "my password" #=> true
my_password == "not my password" #=> false
I expect the file to successfully require bundler and bcrypt and run the code, producing no output. When I try to run the bcrypt.rb file I get the following error:
Traceback (most recent call last):
2: from bcrypt.rb:1:in `<main>'
1: from /Users/rturner/.rvm/rubies/ruby-2.6.4/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/rturner/.rvm/rubies/ruby-2.6.4/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- bunder/setup (LoadError)
I noticed my GEM_HOME environment variable was set to /Users/rturner/.rvm/gems/ruby-2.6.4 which does not seem to contain gem files. I added a line after the rvm script loads in my .bash_profile file:
export GEM_HOME="/Users/rturner/.rvm/gems/default/gems"
This changed the GEM_HOME variable to a directory that contains gems but did not fix the problem. I am using rvm in my local setup, installed with brew and I have installed bundler with brew, run brew update and brew upgrade as well as trying general troubleshooting methods listed on the bundler page. Can anyone help? Thanks!
Looks like you have mistype here:
require 'bunder/inline'
it should be:
require 'bundler/inline'

Ruby files running from terminal but not from Sublime text

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.

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.

I cant load Ruby Gems

i am getting this error whenever i try to load a ruby gem
/home/hilarl/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- twit
ter (LoadError)
from /home/hilarl/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from sample.rb:2:in `<main>'
can you please help?
You missed to use a ruby, in normal console first run:
rvm use 1.9.3
If it's in a script then instead use following path to ruby:
$rvm_path/wrappers/ruby-1.9.3-p194/ruby
You should get also the minimal basics of using RVM:
screencast: http://screencasts.org/episodes/how-to-use-rvm
cheatsheet: http://cheat.errtheblog.com/s/rvm/
rvm site: https://rvm.io/

I see gem in "gem list" but have "no such file to load"

I am on Ubuntu10
sudo apt-get install ruby1.9.1-full
then download sources of rubygem 1.3.7 and install it
sudo ruby setup.rb
then, for example, install sinatra
sudo gem install sinatra
Finally open irb and type
require "rubygems"
require "sinatra"
and get error
LoadError: no such file to load -- sinatra
from (irb):2:in `require'
from (irb):2
from /usr/bin/irb:12:in `<main>'
I had exactly this problem. The problem is that gem and ruby disagree about where the gems live. Compare these:
ruby -e "puts Gem.path"
gem env
gem which sinatra
If you're like my setup, you'll notice that there's an entry in gem env's paths that isn't in Gem.path, and that's exactly where sinatra will claim to be. In my case, I had to add
export GEM_HOME=/usr/lib/ruby/gems/1.9.1
to my .profile. Then everyone was happy.
Execute
sudo gem install sinatra --verbose
and note the path where the gem is getting installed.
Then try this in irb
puts $LOAD_PATH
and make sure that gem is installed in one of the directories in $LOAD_PATH
And ideally just start using http://rvm.beginrescueend.com/
I usually hit this error when I forget:
require 'rubygems'
It'd be helpful if you provided the actual code sample, though, what gem you want to require, and what Ruby version you're using if this doesn't solve the problem.
This was before here on SO quite a few times. Problem is that you probably have two versions of ruby. The one is installing the gem and the other one is trying to use it. Do this in terminal:
$ which -a ruby
Or this:
$ which -a gem
to see if you have more than one version of ruby/gem installed. If so - remove one version (via $ rm or package manager of your system).
I use ruby gems 1.8.7 for a project. I was getting the same error. Use the line require 'rubygems'. It must always be the first require statement, otherwise you can get an error. In my code, I had
require 'watir'
require 'rubygems'
# more code
I got the error - in `require': no such file to load -- watir (LoadError).
When I put rubygems first, the error went away and everything worked. I don't know
why this happens.
Btw, I tried user24359 answer and it did not help me.
C:\code>ruby -e "puts Gem.path"
-e:1: uninitialized constant Gem (NameError)

Resources