rvm `require': no such file to load -- rubygems (LoadError) - ruby

run a ruby code got error "rvm `require': no such file to load -- rubygems (LoadError)"
bash-3.2$ rvm --default ruby-2.0.0-p451
-bash-3.2$ rvm list
rvm rubies
=* ruby-2.0.0-p451 [ x86_64 ]
-bash-3.2$ gem list --local
*** LOCAL GEMS ***
bigdecimal (1.2.0)
bundler (1.5.3)
bundler-unload (1.0.2)
executable-hooks (1.3.1)
gem-wrappers (1.2.4)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
net-ssh (2.9.1)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
rubygems-bundler (1.4.2)
rvm (1.11.3.9)
test-unit (2.0.0.0)
-bash-3.2$ gem list --local rubygems
*** LOCAL GEMS ***
rubygems-bundler (1.4.2)
to run the script:
ruby test.rb
`require': no such file to load -- rubygems (LoadError)
$ cat test.rb
require 'rubygems'
require 'net/ssh'
Net::SSH.start(.............
what's going on? please advice. thanks

Related

Calling "brew" in Ruby system call and bundler error

I'm trying to write a rubygem that does some stuff with homebrew. I'm calling on brew to do some stuff using system(). When I include certain gems in using bundler, I get some errors doing things inside system().
As an example, a basic Gemfile with rake:
~/tmp/foo cat Gemfile
source 'https://rubygems.org'
gem 'rake'
Inside irb after running a bundle install:
irb(main):001:0> system("brew", "info", "ack")
Could not find rake-12.0.0 in any of the sources
Run `bundle install` to install missing gems.
=> false
I can do a bundle install inside the call and receive the same results:
rb(main):007:0> system("bundle", "install")
Using rake 12.0.0
Using bundler 1.14.6
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Bundled gems are installed into /Users/laura/.bundle.
=> true
irb(main):008:0> system("brew", "version")
Could not find rake-12.0.0 in any of the sources
Run `bundle install` to install missing gems.
=> false
Without the rake gem included I do not receive any errors:
~/tmp/foo cat Gemfile
source 'https://rubygems.org'
gem 'git'
~/tmp/foo bundle install
Fetching gem metadata from https://rubygems.org/.
Fetching version metadata from https://rubygems.org/
Resolving dependencies...
Using git 1.3.0
Using bundler 1.14.6
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Bundled gems are installed into /Users/surminus/.bundle.
~/tmp/foo
~/tmp/foo irb
irb(main):002:0> system("brew", "info", "ack")
ack: stable 2.16, HEAD
Search tool like grep, but optimized for programmers
https://beyondgrep.com/
/usr/local/Cellar/ack/2.14 (4 files, 184.7KB)
Built from source on 2016-12-16 at 16:24:07
/usr/local/Cellar/ack/2.16 (4 files, 190.7KB) *
Built from source on 2017-03-17 at 20:25:45
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ack.rb
=> true
I know it's probably related to some conflict between homebrew, rake and bundler, but I can't for the life of me figure out what's going on. I only need to rake tasks for some development specific tasks so I can remove it, but I'm interested to find out why this occurs, or if indeed calling brew this way is $bad.
EDIT: I was asked for output of gem list --local in the bundle directory. Seems to be system gems. With bundle exec:
~/tmp/foo bundle exec gem list --local
*** LOCAL GEMS ***
bundler (1.14.6)
rake (12.0.0)
Without bundle exec:
~/tmp/foo gem list --local
*** LOCAL GEMS ***
activemodel (5.0.1)
activesupport (5.0.1)
addressable (2.5.0)
bigdecimal (1.2.8)
bundler (1.14.6, 1.14.5, 1.13.6)
CFPropertyList (2.2.8)
coderay (1.1.1)
commander (4.4.2)
concurrent-ruby (1.0.3)
did_you_mean (1.0.0)
diff-lcs (1.3, 1.2.5)
domain_name (0.5.20161129)
facter (2.4.6 ruby universal-darwin)
fileutils (0.7)
git (1.3.0)
hiera (1.3.4)
highline (1.7.8)
http-cookie (1.0.3)
i18n (0.7.0)
io-console (0.4.5)
json (2.0.2, 1.8.3)
json_pure (2.0.1, 1.8.3)
metaclass (0.0.4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (3.2016.0521)
minitest (5.10.1, 5.8.3)
mocha (1.2.1, 1.1.0)
myosx (0.2.2, 0.2.0, 0.1.0)
net-telnet (0.1.1)
netrc (0.11.0)
oauth (0.5.1)
power_assert (0.2.6)
pry (0.10.4)
psych (2.0.17)
public_suffix (2.0.4)
puppet (3.8.7)
puppet-lint (1.1.0)
puppet-syntax (2.3.0, 2.1.0)
puppetlabs_spec_helper (1.1.1)
rake (12.0.0, 11.1.2, 10.5.0, 10.4.2)
rdoc (4.2.1)
rest-client (2.0.0)
rmagick (2.16.0)
rspec (3.5.0, 3.4.0)
rspec-core (3.5.4, 3.4.4)
rspec-expectations (3.5.0, 3.4.0)
rspec-mocks (3.5.0, 3.4.1)
rspec-puppet (2.4.0)
rspec-support (3.5.0, 3.4.1)
ruby-trello (1.6.0)
slop (3.6.0)
test-unit (3.1.5)
thread_safe (0.3.5)
tzinfo (1.2.2)
unf (0.1.4)
unf_ext (0.0.7.2)

RVM works, Ruby gems installed, but not accessible with require

Here’s my problem:
➜ ~ rvm current
ruby-2.2.1
➜ ~ rvm list
rvm rubies
ruby-2.0.0-p643 [ x86_64 ]
ruby-2.1.1 [ x86_64 ]
=* ruby-2.2.1 [ x86_64 ]
# => - current
# =* - current && default
# * - default
➜ ~ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
➜ ~ gem list
*** LOCAL GEMS ***
bigdecimal (1.2.6)
bundler (1.10.6)
coderay (1.1.0)
domain_name (0.5.24)
http-cookie (1.0.2)
io-console (0.4.3)
json (1.8.1)
method_source (0.8.2)
mime-types (2.6.1)
netrc (0.10.3)
plaid-ruby (0.1.2)
plist (3.1.0)
pry (0.10.1)
psych (2.0.8)
rake (10.4.2)
rdoc (4.2.0)
rest-client (1.8.0)
slop (3.6.0)
unf (0.1.4)
unf_ext (0.0.7.1)
➜ ~ irb
irb(main):001:0> require 'plaid-ruby'
LoadError: cannot load such file -- plaid-ruby
from /Users/richardburton/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/richardburton/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /Users/richardburton/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
irb(main):002:0>
You need to require plaid, not plaid-ruby. The file you require doesn’t necessarily have the same name as the gem, although it’s often the case that it does.
In fact from the Rubygems page for plaid-ruby and the Github page it links to it looks like it is an old version of the Plaid client, and you should be using the plaid gem.

`require': cannot load such file -- net/ssh (LoadError)

run a ruby script got error `require': cannot load such file -- net/ssh (LoadError)
bash-3.2$ rvm --default ruby-2.0.0-p451
-bash-3.2$ rvm list
rvm rubies
=* ruby-2.0.0-p451 [ x86_64 ]
-bash-3.2$ gem list --local
*** LOCAL GEMS ***
bigdecimal (1.2.0)
bundler (1.5.3)
bundler-unload (1.0.2)
executable-hooks (1.3.1)
gem-wrappers (1.2.4)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
net-ssh (2.9.1)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
rubygems-bundler (1.4.2)
rvm (1.11.3.9)
test-unit (2.0.0.0)
ruby test.rb
`require': no such file to load -- rubygems (LoadError)
$ cat test.rb
require 'rubygems'
require 'net/ssh'
Net::SSH.start(...)
what's wrong? please advice. thanks

Bundler stops at gem json install

I tried to install susy2 /sass / compass with bundler.
My Gemfile:
source "https://rubygems.org"
gem 'sass', '~> 3.3.2'
gem 'susy', '~> 2.1.1'
gem 'json', '~> 1.8.1'
gem 'compass', '~> 1.0.0.alpha.19'
bundle install shows the error
Gem::Installer::ExtensionBuildError: 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:1:in `<main>'
Gem files will remain installed in /home/bernie/.bundler/tmp/6210/gems/json-1.8.1 for inspection.
Results logged to /home/bernie/.bundler/tmp/6210/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
gem list shows:
bundler (1.5.1)
celluloid (0.15.2)
chunky_png (1.3.0)
compass (0.12.4)
compass-core (1.0.0.alpha.19)
compass-import-once (1.0.4)
fssm (0.2.10)
multi_json (1.9.2)
permutation (0.1.8)
rake (10.2.0)
rb-fsevent (0.9.4)
sass (3.3.4, 3.2.18)
susy (2.1.1)
timers (1.1.0)
Any Ideas?
A little bit Googling told me this, have you tried it?
sudo apt-get install ruby1.9.1-dev

Cannot load Nokogiri

I'm writing Ruby scripts on Linux Mint 14 under RVM. In both Ruby 2.0 and 1.9.3, when I try to run what I'm working on, I get the error:
/home/tom/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- Nokogiri (LoadError)
from /home/tom/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from make_index.rb:1:in `<main>'
Nokogiri is installed; gem list gives:
*** LOCAL GEMS ***
bigdecimal (1.1.0)
bundler (1.3.5)
bundler-unload (1.0.1)
io-console (0.3)
json (1.5.5)
mini_portile (0.5.1)
minitest (2.5.1)
nokogiri (1.6.0)
rake (10.1.0, 0.9.2.2)
rdoc (3.9.5)
rubygems-bundler (1.2.1)
rvm (1.11.3.8)
The file in question starts with require 'Nokogiri'. Running the file with sudo doesn't make a difference, nor does using the terminal vs. running it in Geany.
Not Nokogiri rather, you should write as below
require 'nokogiri'
See SYNOPSIS:

Resources