Ruby cannot load any gem that I install (Ubuntu server) - ruby

I've got a simple script that uses sinatra. Should be simple, right? Apparently not.
The code:
require 'rubygems'
require 'sinatra'
That's all there is. And it fails, saying:
tekknolagi#eos ~/indexer $ ruby torrent.rb
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- torrent-ruby (LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from torrent.rb:2
I gem installed it several times over, just to make sure I wasn't going crazy. What could be going wrong and how can I fix it?
Oh, and here's my list of installed gems:
tekknolagi#eos ~/indexer $ gem list
*** LOCAL GEMS ***
rack (1.4.1)
rack-protection (1.2.0)
rake (0.9.2.2)
sinatra (1.3.2)
sqlite3 (1.3.6)
tilt (1.3.3)
torrent-ruby (0.1.4)

I believe you have done everything right. Many times this custom require error appears when the gem is not installed in the proper path. Try not using the explicit require. Use this instead..:
require_relative 'sinatra'

Related

Where gem path supervisor see?

I want to exec sinatra app from supervisord. sinatra gem is installed in /home/lastcat(<-my username)/.rbenv/shims/gem.
I wrote following sinatra.conf.
[program:sinatra]
user=lastcat
environment=PATH="/home/lastcat/.rbenv/shims:/home/lastcat/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"/home/lastcat/Documents/tmp/app.rb
command=ruby /home/lastcat/Documents/tmp/app.rb
redirect_stderr=true
stdout_logfile=/var/log/supervisor/sinatra.log
but, when I exec sudo supervisorctl start sinatra, this error happen.
from /home/lastcat/Documents/tmp/app.rb:1:in `<main>'
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- sinatra (LoadError)
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I suspected supervisor cannot see gem path for some reason. I change command to which ruby and which gem, and confirm their result.But they are /home/lastcat/.rbenv/shims/rubyand/home/lastcat/.rbenv/shims/gem.
next, I change command to gem list.Then, output is,
bigdecimal (1.2.4)
bundler (1.10.6)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.5)
rake (10.1.0)
rdoc (4.1.0)
test-unit (2.1.2.0)
It is unexpected result.Result of gem list by user:lastcat,
bigdecimal (1.2.0)
bundler (1.10.6)
~
sinatra (1.4.6)
~
ofcourse, result of which gemandwhich ruby by normaly execed by lastcat, equal to previous them.
In other words, supervisor see another path when which gem and when gem list I don't understand this phenomenon.
post sctripts: result of sudo gem list is equal to gem list by supervisor.It exec command in root enviroment……?
You need to set GEM_PATH in environment:
environment=GEM_PATH="YOUR_GEM_PATH"
And print ENV in IRB to find your GEM_PATH.

Why cant I load sys-proctable?

I have installed the sys-proctable gem on a fresh Ubuntu image (running via Vagrant)
with Ruby 1.8.7.
vagrant#precise64:~$ gem list
*** LOCAL GEMS ***
bunny (0.7.9)
chef (10.14.2)
...many, many gems more
sys-proctable (0.9.3 universal-linux)
systemu (2.5.2)
treetop (1.4.10)
uuidtools (2.1.3)
yajl-ruby (1.1.0)
now I want to load it into irb
vagrant#precise64:~$ irb
irb(main):001:0> require 'sys/proctable'
LoadError: no such file to load -- sys/proctable
from (irb):1:in `require'
from (irb):1
from :0
so what is the issue here?
You may need to require rubygems first. I think then it will work.
Also: are you sure you need to use a / and not a -?
Obviously you managed to load it...
Just wanted to make sure everything is written.
It's definitely a / that's required.
This should work :
require 'rubygems'
require 'sys/proctable'
....

Trying to update to gem 3.0.20 and install a DevKit

Heroku advised updating to this gem because of a security patch but it has caused me all kinds of headaches and now my local environment isn't working correctly. They suggested doing this as a security precaution. They suggested going into my app, changing the gemfile version and simply running 'bundle update rails'. Here was the output:
$ bundle update rails
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.20)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.20)
Using erubis (2.6.6)
Using rack (1.2.8)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.37)
Using actionpack (3.0.20)
Using mime-types (1.21)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.2.19)
Using actionmailer (3.0.20)
Using arel (2.0.10)
Using activerecord (3.0.20)
Using activeresource (3.0.20)
Using bundler (1.0.22)
Installing json (1.7.7) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
c:/Ruby192/bin/ruby.exe extconf.rb
creating Makefile
make
'make' is not recognized as an internal or external command,
operable program or batch file.
Gem files will remain installed in c:/Ruby192/lib/ruby/gems/1.9.1/gems/json-1.7.7 for inspection.
Results logged to c:/Ruby192/lib/ruby/gems/1.9.1/gems/json-1.7.7/ext/json/ext/generator/gem_make.out
An error occured while installing json (1.7.7), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.7'` succeeds before bundling
Then they pointed to a thread on here of someone having a similar problem. It involved downloading a Devkit etc. I tried following the instructions but now everything is just broke. I'm familiar working with Ruby on Rails but never had to install it (was already set up on my work computer) and I find it hard to believe that updating it is this difficult when the whole philosophy behind ruby on rails is simplicity. I've got to be missing something or not using the proper resource.
The current version of ruby on my machine is ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
$rails --version
Rails 3.0.3
And the DevKit I downloaded is
DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe
from http://rubyinstaller.org/downloads
I then tried to walk through the installation steps on this site https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
It always comes back to a 'make' error or 'json' error.
Maybe I have different versions conflicting??
Now I get the following error when I just try to start WEBrick to run my app:
$ rails s
c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/rubygems_integrat
ion.rb:183:in `stub_source_index170': uninitialized constant Gem::SourceIndex (N
ameError)
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/ruby
gems_integration.rb:303:in `stub_rubygems'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/ruby
gems_integration.rb:246:in `replace_entrypoints'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runt
ime.rb:14:in `setup'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler.rb:1
10:in `setup'
from c:/rails/thumb/costrecovery/config/boot.rb:8:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from script/rails:5:in `<main>'
Any advice is greatly appreciated.

Load Error rack/test

I am getting following error when running a test file.
$ruby test/test_gothonweb.rb
/Users/sony/.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 -- rack/test (LoadError)
from /Users/sony/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test/test_gothonweb.rb:3:in `<main>'
Snippet of the test file:
require_relative '../lib/gothonweb.rb'
require 'test/unit'
require 'rack/test'
ENV['RACK_ENV'] = 'test'
class GothonwebTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
end
I think the gem is installed and should be available:
gem list
*** LOCAL GEMS ***
bundler (1.1.3)
rack (1.4.1)
rack-protection (1.2.0)
rake (0.9.2.2)
rubygems-bundler (0.9.0)
rvm (1.11.3.3)
sinatra (1.3.2)
tilt (1.3.3)
Why the error you think?
rack-test is a separate gem. Include that in your Gem file.
Had similar issue here, and by gem uninstall rack-test and then bundle install solved the issue.
https://github.com/brynary/rack-test/issues/123

ruby datamapper will not load

I was trying to learn about the Sinatra ruby framework by following this tutorial:
http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra-the-recall-app-2/
however, after running the gem install and writing a simple sinatra server in test.rb like so:
require 'sinatra'
require 'datamapper'
get '/' do
"Hello, World!"
end
but when I run the command ruby test.rb, I get the following error:
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from datamapper_test.rb:2:in `<main>'
glenn#ubuntu:~/Dropbox/Repositories/sandbox/sinatra$ ruby datamapper_test.rb
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test.rb:3:in `<main>'
it seems as though it cannot find the datamapper gem. how can I fix this?
EDIT: using ruby 1.9.2
EDIT (again): (parital) output from gem list:
data_mapper (1.2.0)
data_objects (0.10.8)
datamapper (1.2.0)
devise (1.4.5)
directory_watcher (1.4.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-serializer (1.2.1)
dm-sqlite-adapter (1.2.0)
d m-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.1)
dm-validations (1.2.0)
do_sqlite3 (0.10.8)
sinatra (1.3.2, 1.2.6)
sqlite3 (1.3.5, 1.3.4)
sqlite3-ruby (1.3.3)
You need to require 'data_mapper', not datamapper.
Note there is a datamapper gem as well as a data_mapper gem, but they are the same thing, just different names. You need use data_mapper as the library name in both of them.
As far as I can tell datamapper is a straight copy of data_mapper:
$ diff -r data_mapper-1.2.0/ datamapper-1.2.0/
diff -r data_mapper-1.2.0/Rakefile datamapper-1.2.0/Rakefile
21c21
< GEM_NAME = 'data_mapper'
---
> GEM_NAME = 'datamapper'
gem install datamapper in your terminal might help :)
But you will also need a database and an adapter and you will want to use the gem somehow. Good luck and have fun with dm + sinatra!

Resources