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.
Related
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!
I am a new bee with sinatra and i am not an expert with ruby management tools like rvm and rbenv and i have the following issue: When i run a bundle install in my app, gems are installed and i have the following response "Bundled gems are installed into ./vendor/bundle." But when i try to run my sinatra app, it is displayed that i dont have sinatra installed and when i try this command line "gem list", i dont it found too.
I am using rbenv, and i dont have a clue how to resolve that. When i install gem by gem like "gem install sinatra" it works fine, but it's really painful, so my question is how to resolve that ?
PS: i tried to manage my ruby manager with rvm but i had issues so i moved to rbenv, maybe this is all about the path where gems are installed
This is a print of my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/laadhari/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/laadhari/.rbenv/versions/2.3.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/bin
- SPEC CACHE DIRECTORY: /Users/laadhari/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/laadhari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- /Users/laadhari/.gem/ruby/2.3.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/laadhari/.rbenv/versions/2.3.1/bin
- /usr/local/Cellar/rbenv/1.0.0/libexec
- /Users/laadhari/.rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
A print of my Gemfile
source 'https://rubygems.org'
gem 'sinatra', '~> 1.4.7'
gem "sinatra-activerecord"
gem 'mysql2'
gem 'rest-client'
gem 'thin'
gem 'rake'
when i run :
gem list
*** LOCAL GEMS ***
...
After successfully running bundle install, I dont find gems from Gemfile in the local gems...
One of the objectives of Bundler is to not pollute the global Gem list. This is achieved by NOT installing the bundled gems to the default location.
So to make sure your app finds the bundled gems, you have a few options:
Using bundle exec
When starting your application (ie. using rackup or ruby ./app.rb), prefix the command with bundle exec
bundle exec rackup
#=> Thin web server (v1.7.0 codename Dunder Mifflin)
#=> Maximum connections set to 1024
#=> Listening on localhost:9292, CTRL+C to stop
#=> ...
More Info: https://bundler.io/v1.12/man/bundle-exec.1.html
Using Bundler.setup
Before loading your dependencies (with require), load Bunder:
require 'rubygems'
require 'bundler/setup'
# require your gems as usual
require 'sinatra'
More info: https://bundler.io/v1.12/bundler_setup.html
Source & Further reading
I strongly suggest to read the excellent documentation at https://bundler.io/v1.12/#getting-started .
One more thing, to find out WHERE your bundled gems actually are installed, run the following command:
bundle config path
#=> Settings for `path` in order of priority. The top value will be used
#=> Set for your local app (/path/to/project/.bundle/config): ".bundle"
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 :))