I wanted to learn a little about scraping,
Implemented with reference to Making a scraping source in 20 minutes using Ruby.
Since it says "Gem should be installed under vendor / bundle."
Added --path vendor / bundle
option when doing bundle install as instructed.
If you write the code as in the article to main.rb and execute main.rb,
training $ ruby main.rb
Traceback (most recent call last):
2: from main.rb:2:in `<main>'
1: from /Users/yusaku/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/yusaku/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- nokogiri (LoadError)
It says 'require': cannot load such file --nokogiri (LoadError)
,
nokogiri has bundle installed under vender / bundle
.
training $ ls vendor/bundle/ruby/2.6.0/gems/
byebug-11.1.3 method_source-1.0.0 nokogiri-1.10.10 pry-byebug-3.9.0
coderay-1.1.3 mini_portile2-2.4.0 pry-0.13.1
If you look closely at the details of the error,
It looks like you are looking for a subordinate to /Users/yusaku/.rbenv/
.
I was surprised at that, but I didn't do bundle exec.
training $ bundle exec ruby main.rb
Now I was able to run main.rb without any errors (and also require "nokogiri").
By doing bundle exec
, it looks like they searched for the gem under the same directory.
Recommended Posts