I'm trying to run an script that calls the ansi gem with the following line:
require 'ansi/code'
However, when I try running it, I get the following error:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ansi/code (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from ./taoup:4:in `<main>'
I tried to make sure I run Ruby v2.6.5 and reinstalled the dependencies afterward.
→ rbenv versions
system
2.1.3
2.2.1
* 2.6.5 (set by /Users/ricky/.rbenv/version)
→ gem install ansi
Successfully installed ansi-1.5.0
Parsing documentation for ansi-1.5.0
Done installing documentation for ansi after 0 seconds
1 gem installed
For reference, it seems that rubygems is running at v.2.6.5.
→ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.5 (2019-10-01 patchlevel 114) [x86_64-darwin18]
- INSTALLATION DIRECTORY: /Users/ricky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0
- USER INSTALLATION DIRECTORY: /Users/ricky/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /Users/ricky/.rbenv/versions/2.6.5/bin/ruby
- GIT EXECUTABLE: /usr/local/bin/git
- EXECUTABLE DIRECTORY: /Users/ricky/.rbenv/versions/2.6.5/bin
- SPEC CACHE DIRECTORY: /Users/ricky/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/ricky/.rbenv/versions/2.6.5/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /Users/ricky/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0
- /Users/ricky/.gem/ruby/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "install" => "--no-rdoc --no-ri"
- "update" => "--no-rdoc --no-ri"
- REMOTE SOURCES:
- https://rubygems.org/
I think I need to direct the execution environment to use my intended version of Ruby.
Okay, looks like the script was pointing to a specific installation of Ruby, as specified here:
#!/usr/bin/ruby
This version of ruby was not the one I intended to run on. It is a different version afterall:
→ /usr/bin/ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
So I made a quick and dirty fix on the script by rewriting the Shebang declaration like this:
#!/Users/ricky/.rbenv/versions/2.6.5/bin/ruby
If anyone knows a version-agnostic way to fix this dependency, please let me know!
Related
When I run, bundle I see the following:
Your Ruby version is 2.5.0, but your Gemfile specified
2.4.0.pre.dev
my Gemfile looks like:
source 'https://rubygems.org'
ruby '2.4.0-dev'
gem 'sinatra', :github => 'sinatra/sinatra'
This is my gem env:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.12
- RUBY VERSION: 2.5.0 (2017-07-31 patchlevel -1) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.5.0
- USER INSTALLATION DIRECTORY: /Users/johndoe/.gem/ruby/2.5.0
- RUBY EXECUTABLE: /Users/johndoe/.rbenv/versions/2.4.0-dev/bin/ruby
- EXECUTABLE DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/bin
- SPEC CACHE DIRECTORY: /Users/johndoe/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/johndoe/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.5.0
- /Users/johndoe/.gem/ruby/2.5.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "-n/usr/local/bin"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/johndoe/.rbenv/versions/2.4.0-dev/bin
- /Users/johndoe/.rbenv/libexec
- /Users/johndoe/.nvm/versions/node/v8.1.4/bin
- /usr/local/sbin
- /Library/Frameworks/Python.framework/Versions/3.4/bin
- /Users/johndoe/.rbenv/shims
- /Users/johndoe/google-cloud-sdk/bin
- /Users/johndoe/Library/Python/2.7/bin
- /Users/johndoe/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
When I type rbenv verions this is what I see:
system
2.0.0-p247
2.3.1
* 2.4.0-dev (set by /Users/johndoe/code/projects/blog-server/.ruby-version)
With Rbenv I am specifying the ruby version I want, and I am matching this in my project's Gemfile. However, whenever I run bundle or bundle exec gem uninstall sinatra I see the above error message about my ruby version and my gemfile ruby version not matching. I also see that my Ruby version is 2.5.0, and I have no idea how that got set. Can someone help me resolve this error?
Your Ruby version is 2.5.0, but your Gemfile specified
2.4.0.pre.dev
In my bash profile, I have:
export PATH=$HOME/.rbenv/bin:$PATH
....
eval "$(rbenv init -)"
In short, I just want the shell that runs my ruby process for my blog project to use ruby version 2.4.0-dev, and I am struggling to see understand what's blocking me and how to resolve it.
UPDATE:
I also noticed something odd. My bundler version continues to point to ruby 2.5.0p-1.
## Environment
Bundler 1.15.3
Rubygems 2.6.12
Ruby 2.5.0p-1 (2017-07-31 revision 59454) [x86_64-darwin16]
Git 2.11.0
Platform x86_64-darwin-16
OpenSSL OpenSSL 1.0.2k 26 Jan 2017
```
## Gemfile
### Gemfile
```ruby
source 'https://rubygems.org'
ruby '2.4.0-dev'
gem 'sinatra', '2.0.0'
```
### Gemfile.lock
```
<No /Users/johndoe/code/projects/blog-server/Gemfile.lock found>
In a project folder run:
rbenv local 2.4.0-dev
It should do the trick. You just need to specify local ruby version for this particular project. And your global version is set to 2.5.0
The best option here, I think, is to install Ruby Version Manager (rvm).
RVM helps every ruby developer by doing exactly what you need; manage ruby version automatically as you need.
Here's the link, hope it helps;
https://rvm.io/
Cheers
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
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.
I just migrated to a new Mac with OS X Lion. For some reson I can't install new Ruby gems anymore. Or rather: I can install them, but not find them.
This is my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.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-11
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/Jens/.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
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Running the gem crack in irb works fine:
>> require 'rubygems'
=> false
>> require 'crack'
=> true
But when I try to do the same in my text editor (Textwrangler) I run into this:
custom_require.rb:31: in `gem_original_require': no such file to load -- crack (LoadError)
Any suggestions?
Maybe a pointer in the right direction: I've had problems on Lion with different ruby versions being installed. Problem was that some programs calling ruby (in my case git for a pre-commit hook) had their $PATH variable different; as a result another version of ruby was found first (and that version didn't have the gems installed).
So to debug, try printing out the version of both rubys (rubies?), and the PATH variable (something like print RUBY_VERSION and print ENV["PATH"]; maybe also print ENV["GEM_HOME"]. See if that leads to anything.
FYI: for me the solution in the end was to upgrade from git 1.7.3 to 1.7.7; it wasn't clear to my why things didn't work in 1.7.3 (why the PATH was different), but who cares; it works again :))
I'm working on my local machine. If I use a Sinatra app I have no problem adding this line to myapp.rb
require 'sinatra'
When I go to the console and I run
irb -r myapp.rb
I get this error
gem_original_require': no such file to load -- sinatra (LoadError)
I understand that either my IRB or Ruby path is not looking right. I am using (Simple Ruby Version Management: rbenv) to manage the Ruby environment not too sure if this affects things? I ran the gem env and I got this.
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.0.1]
- INSTALLATION DIRECTORY: /Users/Air/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /Users/Air/.rbenv/versions/1.9.2-p290/bin/ruby
- EXECUTABLE DIRECTORY: /Users/Air/.rbenv/versions/1.9.2-p290/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Users/Air/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
- /Users/Air/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Try:
irb -r ./myapp.rb
If you're using a config.ru file, that path should be reflected there as well.
In my case I was using rvm. Even though I configured and .rvmrc file and assured I was using a proper gemset with sinatra installed, I kept having the same error.
Then I tried installing sinatra in my native ruby version:
gem install sinatra
I had to install the sqlite adapter as well for the sinatra app I was trying to run:
gem install sqlite3
Finally I got to run the scanty blog (https://github.com/rodrigomes/scanty) with:
ruby main.rb
It worked but I don't think it is the best solution.