Basic require jwt issue

785 views
Skip to first unread message

rob.da...@gmail.com

unread,
Jan 10, 2018, 9:11:53 AM1/10/18
to ruby-jwt
Hi, Im new to ruby, so this ones probably a basic one. I have an API auth script that requires 'jwt', so I've cloned ruby-jwt and cd'd to the ruby-jwt/lib directory.
I then changed require 'jwt' to require './jwt' as it wouldn't recognise jwt from the current dir. It appears another kernel module requires decode.rb from the same jwt directory but is unable to find it.
I've also tried from one directory up, using absolute paths... appreciate any guidance, outputs below:

$ ruby -v
#!/usr/bin/env ruby
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

$ ls
jwt jwt.rb
#!/usr/bin/env ruby

$ ls jwt
algos default_options.rb error.rb signature.rb version.rb
decode.rb encode.rb security_utils.rb verify.rb
#!/usr/bin/env ruby

First attempt using require 'jwt' (not ./jwt):
$ ruby ~/temp/auth.rb
Ignoring ffi-1.9.18 because its extensions are not built.  Try: gem pristine ffi --version 1.9.18
/Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- jwt (LoadError)
#!/usr/bin/env ruby
from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/user/temp/auth.rb:8:in `<main>'

Second attempt using require './jwt':
$ ruby ~/temp/auth.rb
Ignoring ffi-1.9.18 because its extensions are not built.  Try: gem pristine ffi --version 1.9.18
/Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- jwt/decode (LoadError)
from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/user/scripts/libs/ruby-jwt/lib/jwt.rb:4:in `<top (required)>'
from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/user/temp/auth.rb:4:in `<main>'

excpt

unread,
Jan 10, 2018, 10:46:41 AM1/10/18
to ruby-jwt
Hey Rob,

The recommended way to use ruby packages is using the gem utility.

It looks like you try to build a script that uses ruby.

Try the following command:

$ gem install jwt

This should fix you problems and you can switch back to

require 'jwt'

in your auth.rb file.

rob.da...@gmail.com

unread,
Jan 14, 2018, 10:35:57 PM1/14/18
to ruby-jwt
Great, thanks that did the trick. Used the command earlier, but it didn't complete properly.
Reply all
Reply to author
Forward
0 new messages