win32console installed, doesn't 'require' as expected - ruby

Win32Console did install:
Fetching: win32console-1.3.0-x86-mingw32.gem (100%)
Successfully installed win32console-1.3.0-x86-mingw32
1 gem installed
Installing ri documentation for win32console-1.3.0-x86-mingw32...
Installing RDoc documentation for win32console-1.3.0-x86-mingw32...
but it doesn't want to work with require. I see this everywhere:
require 'Win32/Console/ANSI'
But everytime I try it a LoadError is raised.
Is there something I'm missing here? Do I need to configure it somehow?
P.S.:
The error message:
LoadError: no such file to load -- Win32/Console/ANSI
from path/custom_require.rb:36:in `require'
from path/custom_require.rb:36:in `require'
from (irb):23
from path/irb:12:in `<main>'
gem list win32console gives:
*** LOCAL GEMS ***
win32console (1.3.0 x86-mingw32)
gem environment gives:
RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i386-mingw32]
- INSTALLATION DIRECTORY: rubypath/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: rubypath/bin/ruby.exe
- EXECUTABLE DIRECTORY: rubypath/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- rubypath/lib/ruby/gems/1.9.1
- userpath/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
(paths truncated because they are long)
Finally: ruby -v:
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]

Hey I was having this same issue. I am also the one that put the bounty up. I finally got passed this error. this is what i did.
As you correctly did, I installed the gem.
gem install win32console
then I went into my gemfile and also added this gem to the bottom.
Seems to work! How do I get my bounty back!!

According to example from here: https://github.com/luislavena/win32console you should:
require 'rubygems'
require 'win32console'
include Win32::Console::ANSI
include Term::ANSIColor
In the same README you can read that
Win32::Console has been deprecated in favor of an external tool named ANSICON:
http://blog.mmediasys.com/2010/11/24/we-all-love-colors/
https://github.com/adoxa/ansicon
ANSICON is universal tool and you use it in ruby with gem: https://github.com/flori/term-ansicolor

See this thread: http://www.ruby-forum.com/topic/133808
Hi everybody,
I figured out, what the problem was:
Just renamed the path in the gems dir:
win32console-1.0.8-x86-mswin32
to
win32console-1.0.8-i386-mswin32
then it works for me.

Related

Ruby gem fails to load

I've installed a gem from command line:
sudo gem install jalalidate
gem says it's installed:
$ gem list jalalidate
*** LOCAL GEMS ***
jalalidate (0.3.2)
And it can be loaded:
ruby -rubygems -e 'require "jalalidate"' # output is empty, (success?)
Though when I try to include this gem in a Rakefile, rake fails:
# Rakefile:
require "rubygems"
require "bundler/setup"
require "stringex"
require "jalalidate"
# Terminal:
$ rake new_post["title"]
rake aborted!
cannot load such file -- jalalidate
(See full trace by running task with --trace)
Note:
I'm using octopress blogging system, and I'm trying to convert dates generated by Time.now.strftime('%Y-%m-%d %H:%M') to Jalali calender system, (JalaliDate.new(Date.today).strftime('%Y-%m-%d')).
I'm not familiar with Ruby
Update:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/soroush/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Your Rakefile has require "bundler/setup" before you try to require jalalidate which means you are using Bundler and so you have a Gemfile, which is restricting the gems (and versions) available.
In order to use the gem in your project, add the line
gem "jalalidate"
to the Gemfile.
See this question about why using sudo with gem commands is mostly a bad idea.
I recommend trying to install the gem without sudo: gem install jalalidate

New to Ruby and am having trouble with LOAD_PATH

I recently installed Ruby 2.0.0 on OS X 10.8.3 by compiling from source code. I checked the version with
$ ruby --version
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
And I checked my gem version with
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-12
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/ehartsuyker/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :benchmark => false
- :sources => ["http://rubygems.org/", "http://gemcutter.org"]
- REMOTE SOURCES:
- http://rubygems.org/
- http://gemcutter.org
I noticed that the reported version of Ruby here does not match the version I installed. I don't know if this matters or not.
I have a simple piece of code called encrypy.rb that I'm running. After installing the 'rsa' gem with gem install rsa.
require 'rubygems'
require 'rsa'
key = RSA::KeyPair.generate(128)
ciphertext = key.encrypt("message")
puts(ciphertext)
When I run it, it gives an error saying it can't find the gem.
$ ruby encrypt.rb -Idirectory '/Library/Ruby/Gems/1.8'
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- rsa (LoadError)
from /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from encrypt.rb:2:in `<main>'
So the question is, why isn't Ruby finding the gem despite seeming to know where it is? And how can I fix it?
Ruby 1.8.7 is shipped with OS X. It seems that gem is seeing that version instead of your manually installed 2.0.0. As others already suggested, using RVM or rbenv (which one depends on personal preference) makes handling different ruby environments much easier. You can find those tools and descriptions for them in the following places:
RVM: https://rvm.io/
rbenv: https://github.com/sstephenson/rbenv

Fail to install racc with ruby 1.9.x

I really have some problems with gem. I'm trying to install racc for ruby so that it can compiler some *.y files. I'm working with my own laptop with Ubuntu.
The path of my ruby is
$ which ruby
/usr/bin/ruby
I'm a freshman of ruby. I have tried to install racc with sudo apt-get install racc. But it doesn't work. By the way, what's the difference between apt-get and gem?
$ sudo gem install racc
Building native extensions. This could take a while...
ERROR: Error installing racc:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:3:in `<main>'
Gem files will remain installed in /home/jianqing/RubyGems/gems/racc-1.4.9 for inspection.
Results logged to /home/jianqing/RubyGems/gems/racc-1.4.9/ext/racc/gem_make.out
Here is some information about my system.
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.23
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [i686-linux]
- INSTALLATION DIRECTORY: /home/jianqing/RubyGems
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /home/jianqing/RubyGems/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/jianqing/RubyGems
- /home/jianqing/.gem/ruby/1.9.1
- /var/lib/gems/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Any help is appreciated. I almost crazy for it.
I have already solved that. It turns out to be I need to install a full ruby with sudo apt-get install ruby-dev

ruby and IRB find installed gems, but eclipse cannot

I am a beginner with Ruby development, so apologies this is a face palm question.
On mac OSX I installed ruby 1.9.3, and then installed a gem via command 'gem install selenium-webdriver', I then installed eclipse as IDE.
I then wrote a simple class requiring the 'selenium-webdriver' gem.
class Cheese
require 'rubygems'
require 'selenium-webdriver'
... rest of code class.
I can run cheese.rb without issue from the command line using irb or ruby (i.e. ruby ./path to file/cheese.rb)', but when running the script via the eclipse GUI i get an error:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- selenium-webdriver (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /Users/bryan/Documents/workspace/New Se Project/Cheese.rb:3
This would indicate a config issue with Eclipse. Note the installed default ruby version is 1.9.3 from rvm - list, but Eclipse is still 'bound' to 1.8. Googling indicates this is probably a PATH issue, but i'm not familiar with environment variables on Mac OSx.
*How can i reconfigure Eclipse (or Aptana) to 'see' the installed gems? *
Further info:
Bryans-MacBook-Air:Library bryan$ which ruby
/Users/bryan/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
Bryans-MacBook-Air:Library bryan$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin11.4.0]
- INSTALLATION DIRECTORY: /Users/bryan/.rvm/gems/ruby-1.9.3-p194
- RUBY EXECUTABLE: /Users/bryan/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
- EXECUTABLE DIRECTORY: /Users/bryan/.rvm/gems/ruby-1.9.3-p194/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Users/bryan/.rvm/gems/ruby-1.9.3-p194
- /Users/bryan/.rvm/gems/ruby-1.9.3-p194#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Bryans-MacBook-Air:Library bryan$ echo $PATH
/Users/bryan/.rvm/gems/ruby-1.9.3-p194/bin:/Users/bryan/.rvm/gems/ruby-1.9.3-p194#global/bin:/Users/bryan/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/bryan/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin
I was having the same problem. I first tried this tutorial: http://net.tutsplus.com/tutorials/ruby/how-to-install-ruby-on-a-mac/
This did not help.
Then I saw this entry in superuser: https://superuser.com/questions/154292/ruby-rubygems-why-do-i-always-get-error-messages-when-trying-to-install-gems and running gem install using sudo helped me.

Rubygems on Debian: Gems won't load (LoadError)

I've installed the development version of Crunchbang, a linux distro based off Debian. I got Ruby and Rubygems installed, but I can't get the gems I've installed to load. Here is a command-line session:
$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i486-linux]
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [i486-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby1.9.1/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby1.9.1/gems/1.9.1
- /home/corey/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
$ echo $PATH
/home/corey/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/home/corey/.gem/ruby/1.9.1:/usr/lib/ruby1.9.1/gems/1.9.1
$ gem list -d nokogiri
`*** LOCAL GEMS ***`
nokogiri (1.4.1)
Authors: Aaron Patterson, Mike Dalessio
Rubyforge: http://rubyforge.org/projects/nokogiri
Homepage: http://nokogiri.org
Installed at: /usr/lib/ruby1.9.1/gems/1.9.1
Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser
$ ruby -r rubygems -e "require 'nokogiri'"
-e:1:in `require': no such file to load -- nokogiri (LoadError)
from -e:1:in `'
I've encountered similar problems on Ubuntu before, but they were easy to fix. I can't figure out what's wrong in this particular case, and Google didn't seem to know either. Any help would be greatly appreciated!
By the way... this is my first submission to stackoverflow. I hope this question is relevant. :)
Debian does not load RubyGems by default. You can solve this by adding require 'rubygems' to your code or better still, have RubyGems loaded each time Ruby is run. I also run #! and achieved this by editing my ~/.profile adding export RUBYOPT=rubygems and finally reloading my profile with . ~/.profile.
For more information on this matter see: http://docs.rubygems.org/read/chapter/3
Is nokogiri in any of the directories in GEM PATHS?
I've had problems before with installing rubygems from the Debian repos and then installing in manually. Debian puts all gems in /var/ somewhere in the distribution package.

Resources