I'm having an issue with rbenv and what I believe is an issue is of require
trying to read from my system gems rather than from shims.
I'm trying to create a single script file without the overhead of needing bundle - though I've tried adding a Gemfile and put the script and Gemfile in the same directory.
Reproducible steps:
brew install rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
in my.zshrc
- Add
eval "$(rbenv init -)"
to my.zshrc
- Source:
. ~/.zshrc
rbenv install 2.6.3
rbenv rehash
rbenv global 2.6.3
rbenv rehash
for brevity- Close terminal
- New terminal:
ruby -v
= "ruby 2.6.3p62"rbenv version
= "2.6.3 (set by $HOME/Desktop/.ruby-version)"
which ruby
= "$HOME/.rbenv/shims/ruby"gem env
- INSTALLATION DIRECTORY: $HOME/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0
- USER INSTALLATION DIRECTORY: $HOME/.gem/ruby/2.6.0
- RUBY EXECUTABLE: $HOME/.rbenv/versions/2.6.3/bin/ruby
- EXECUTABLE DIRECTORY: $HOME/.rbenv/versions/2.6.3/bin
- SPEC CACHE DIRECTORY: $HOME/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: $HOME/.rbenv/versions/2.6.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- $HOME/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0
- $HOME/.gem/ruby/2.6.0
gem install colorize
- this gem seems to work finegem install httparty
gem install pry
File header:
#!/usr/bin/ruby require 'httparty' require 'colorize' require 'pry'
./file.rb
- Stack Trace for HTTParty
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/dependency.rb:319:in 'to_specs': Could not find 'multi_xml' (>= 0.5.2) among 17 total gem(s) (Gem::LoadError) Checked in 'GEM_PATH=$HOME/.gem/ruby/2.3.0:/Library/Ruby/Gems/2.3.0:/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0', execute `gem env` for more information from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1442:in `block in activate_dependencies' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1431:in `each' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1431:in `activate_dependencies' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1413:in `activate' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:196:in `rescue in try_activate' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:193:in `try_activate' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:125:in `rescue in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:39:in `require' from ./cdw-demo.rb:3:in `<main>'
- Stack trace for Pry
/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 -- pry (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 ./cdw-demo.rb:4:in `<main>'
The stack trace shows there maybe in issue with multi_xml
being a missing gem, but that was installed with httparty
Gem list:
gem list
*** LOCAL GEMS ***
bigdecimal (default: 1.4.1)
bundler (2.1.4, default: 1.17.2)
cmath (default: 1.0.0)
coderay (1.1.2)
colorize (0.8.1)
csv (default: 3.0.9)
date (default: 2.0.0)
dbm (default: 1.0.0)
did_you_mean (1.3.0)
e2mmap (default: 0.1.0)
etc (default: 1.0.1)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.1.0)
forwardable (default: 1.2.0)
gdbm (default: 2.0.0)
httparty (0.17.3)
io-console (default: 0.4.7)
ipaddr (default: 1.2.2)
irb (default: 1.0.0)
json (default: 2.1.0)
logger (default: 1.3.0)
matrix (default: 0.1.0)
method_source (0.9.2)
mime-types (3.3.1)
mime-types-data (3.2019.1009)
minitest (5.11.3)
multi_xml (0.6.0)
mutex_m (default: 0.1.0)
net-telnet (0.2.0)
openssl (default: 2.1.2)
ostruct (default: 0.1.0)
power_assert (1.1.3)
prime (default: 0.1.0)
pry (0.12.2)
psych (default: 3.1.0)
rake (12.3.2)
rdoc (default: 6.1.0)
rexml (default: 3.1.9)
rss (default: 0.2.7)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
shell (default: 0.7)
stringio (default: 0.0.2)
strscan (default: 1.0.0)
sync (default: 0.5.0)
test-unit (3.2.9)
thwait (default: 0.1.0)
tracer (default: 0.1.0)
webrick (default: 1.4.2)
xmlrpc (0.3.0)
zlib (default: 1.0.0)
Let me know if anymore information is needed.
ruby ./file.rb
or add a.ruby-version
file to the root where this file is located contents (2.6.2). The issue seems to be that#!/usr/bin/ruby
refers to 2.3.0 and the file is executing in this context (however you did not install the gems in this context). The first option uses theruby
command which you have shown is 2.6.2. The second option specifies local to this file the ruby version for rbenv is 2.6.2 – engineersmnky