`require': cannot load such file -- oj (LoadError) [closed] - ruby

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I only know the basics of the Ruby and trying to fix this error. There were same questions already but couldn't get it solved from those.
When I run following command in my Ruby Project
rerun 'ruby app.rb'
I got the following error.
[rerun] Webhook-receiver launched
/Users/myhome/.rbenv/versions/2.4.2/lib/ruby/2.4.0/
rubygems/core_ext/kernel_require.rb:55:
in `require': cannot load such file -- oj (LoadError)
from /Users/myhome/.rbenv/versions/2.4.2/lib/ruby/2.4.0/rubygems/
core_ext/kernel_require.rb:55:
in `require' from app.rb:2:in `<main>'
[rerun] Webhook-receiver Launch Failed
[rerun] Watching . for **/*.{rb,js,coffee,css,scss,sass,erb,html,haml,ru,yml,slim,md,feature}
How can I solve this?

Just with the intention of providing a detailed and structured answer for others, since you have already solved the issue. When developing a Ruby application, if code that lives in an external gem is required, you can use Bundler to keep track and manage your dependencies. It uses a file called Gemfile to register the dependencies that your project relies on, as well as the source from where these dependencies will be pulled to your machine. A basic syntax example of Gemfile.
# Registering the sources of gem packages
source 'https://rubygems.org'
[...]
# Requiring a gem for this project
gem 'package_1' # registers a dependency
gem 'package_2', '>=2.0.0' # registers a dependency, with minimum version required
gem 'package_3', '>= 1.5.0', '< 1.9.0' # registers a dependency, with minimum and maximum version required
[...]
With all this set up, when you run bundle install, the dependencies that are specified in your gemfile are pulled to your machine and you can run the program. If you want to check more information for a gem on your machine, you can run bundle info package (below an example for mysql gem)
* mysql (2.9.1)
Summary: This is the MySQL API module for Ruby
Homepage: http://github.com/luislavena/mysql-gem
Path: /var/lib/gems/2.3.0/gems/mysql-2.9.1

Related

Where is the ruby documentation for gems? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
In python in an interactive console like ipython i can just type ? and get documentation on pretty much any library or function.
How do I do this in ruby? Whether I'm using pry or irb I can't find much useful documentation at all.
I'm trying to use Faraday but typing ri Faraday doesn't give any documentation. Typing ri String gives documentation for String, but gems like faraday don't produce any documentation whatsoever.
What am I doing wrong?
If you install the gem using gem install --ri faraday then the ri documentation will be generated for you.
This should be the default, but since Ri doc generation can take a while, a lot of people disable it by putting a line in ~/.gemrc saying gem: --no-ri --no-rdoc (providing those options as defaults for the gem command).
Even if that's the case you can override it on a case by case basis by adding that parameter when you install a gem
Check out the pry-doc extension for pry.
If you want to read that doc, You'll are able to run
gem server
That will create a webservice in you host on port 8808, that you will be able to access via browser.
If you want to see where that info is located, run gem env you'll see all paths into GEM PATHS section.
gem env
RubyGems Environment:
.......2.2.2/etc
- RUBYGEMS PLATFORMS:
.....
- GEM PATHS:
- /home/hbranciforte/.rvm/gems/ruby-2.2.2
- /home/hbranciforte/.rvm/gems/ruby-2.2.2#global
- GEM CONFIGURATION:
.....
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
.....
and if you look at your GEM PATHS you will find a folder called doc.
hbranciforte#hbranciforte-MacBookPro:gems/ruby-2.2.2 $ cd /home/hbranciforte/.rvm/gems/ruby-2.2.2
hbranciforte#hbranciforte-MacBookPro:gems/ruby-2.2.2 $ ls
bin build_info cache doc environment extensions gems specifications wrappers
Sometimes (almost I usually do) run your project with bundle --path bundle/vendor
That creates a folder bundle/vendor where it will store your gems and doesn't store doc (that makes bundler much faster than gem install)

Bundler, when attempting to update or install, will hang forever

When attempting to run bundle install or bundle update, bundler will perpetually hang, and not complete its function. The only time that it will finish is when I specify a gem to update.
For example:
bundle update
Will hang forever unless I use it like this:
bundle update activerecord
Then it will complete as normal.
Any assistance would be appreciated.
This problem is due to a missing dependency, or worse a dependency-of-a-dependency. It's common when you don't use rubygems.org as your gemserver (an enterprise environment).
Common patterns:
You don't have that gem installed
You don't have the dependencies of that gem installed
You don't have that gem installed without its dependencies
Easiest Technique
create a new gemset, and re-bundle. This fixes the problem many times.
If you can't do that for production reasons, and you don't have an app history from which to reflect on when the problem gem was added, then:
Easier Technique
Having learned a bit since writing this answer, I thought I'd pass on this excellent article for how to run bundler with verbose debug output
export DEBUG_RESOLVER=1
bundle 2> debug_output.txt 1> stdio.txt &
This will dump all the debugging (err) output to debug_output.txt and the normal screen stuff to stdio.txt.
You'll want to dump 1> as well because every time bundler dumps a line to 2(stderr) it will put a crlf into 1. So Either dump 1 or background the job. I do both so I can work in the same terminal.
I usually follow it up with:
tail stdio.txt
to be sure things have started, then:
tail -n 10000 -f debug_output.txt
To search with /FAIL] through the file for failed attempts to install a dependency. Find a couple of them that are the same and you've generally located your culprit. The stderr works for bundle install or bundle update.
Debug Your Private Gemserver Technique
I needed to use this process-of-elimination method to determine that my (enterprise) gemserver index had become corrupted
comment out all gems
run bundle update to confirm the empty-set works
un-comment one gem and bundle update
GOTO 3 until you hit the problem
research its dependencies
When you are done
Unset the ENV var with
unset DEBUG_RESOLVER
You can try the --verbose flag too to get more output, but it's really archaic and not very helpful. Really the only way to do this from what I can see is:
Uncomment one gem at a time until it stops working, then try to figure out what the heck is going.
Remove version enforcement one gem at a time (if any) to see if that fixes it.
Remove the offending gem if you can (use a different gem) or lock in versions that do work.
For me, after running:
sudo bundle update --verbose
it kept hanging here:
Query Gemcutter Dependency Endpoint API: tenderlove-frex
Fetching from: http://rubygems.org/api/v1/dependencies?gems=tenderlove-frex
HTTP Success
Query List: []
Not at all helpful. I ended up figuring out that the conflict was between two gems. The following would hang forever:
source 'http://rubygems.org'
gem 'rails', '~> 3'
gem 'airbrake'
I removed the rails version:
source 'http://rubygems.org'
gem 'rails'
gem 'airbrake'
Then it worked, but I noticed in my Gemfile.lock that it was using Rails 2.3.X. So airbrake seemed to be dependent on Rails 2, but I wanted 3. I couldn't find anywhere that airbrake had this Rails 2.x dependency so not sure why it ended up like that. Why bundler can't output something more meaningful is beyond me.
This worked though:
source 'http://rubygems.org'
gem 'rails', '~> 3'
gem 'airbrake', '~> 3'
I really think there is something wrong with Bundler, but not sure.
Bundler may not be hanging. I just experienced a 7 minute time to bundle a relatively small Gemfile, and that is on the fastest possible SSD Macbook Pro with a 50 Gb download connection.
When deploying onto AWS instances, be sure your security group allows outbound HTTP and/or HTTPS connections - I encountered this problem because I had restricted the security group too much.

Cannot use ruby-debug19 with 1.9.3-p0? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Rails 3.1 and Ruby 1.9.3p125: ruby-debug19 still crashes with “Symbol not found: _ruby_threadptr_data_type”
I run this:
gem install ruby-debug19
And in my cucumber env.rb file, I have this:
require 'ruby-debug'
When I try to run, though, I get this exception:
/home/skendall/.rvm/gems/ruby-1.9.3-p0/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_current_thread - /home/skendall/.rvm/gems/ruby-1.9.3-p0/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so (LoadError)
What do I need to do to get ruby-debug to work with 1.9.3-p0?
UPDATE: ruby-debug19 is not maintained anymore. This question and my answer have become irrelevant, it's far easier to use the 'debugger' gem instead.
See Debugging in ruby 1.9
I also ran into this, and found the solution in Ruby 1.9.3 and ruby-debug. You need to install not-yet-officially-released versions of ruby-debug-base19 and linecache19. The currently released versions indeed cause the exception you had.
Use this gist.
#To install ruby-debug on Ubuntu ruby-1.9.3 you need to download from http://rubyforge.org/frs/?group_id=8883
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
#Then in your console
export RVM_SRC=/your/path/to/ruby-1.9.3
# Note, your source path should be something like /home/user/.rvm/src/ruby-1.9.3-p0
gem install archive-tar-minitar
gem install ruby_core_source-0.1.5.gem -- --with-ruby-include=/$RVM_SRC
gem install linecache19-0.5.13.gem -- --with-ruby-include=/$RVM_SRC
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=/$RVM_SRC
gem install ruby-debug19-0.11.6.gem -- --with-ruby-include=/$RVM_SRC
This is a known bug. There's reportedly some work arounds here, here and finally here.
If the workarounds are annoying and/or impossible due to your rvm/bundler setup, which is the case with me, consider pry, and optionally the pry-debug plugin. Pry might be a more generally useful tool than ruby-debug anyways.

rake aborted! stack level too deep [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Rails 3.0 & Ruby 1.9.2rc: Rake commands return 'already initialized constant' & stack level too deep errors. Any ideas
Am using Ruby version 1.9.1 on windows vista. Am getting the rake aborted error for any rake commands am using. This does not happen in all my app folder. Its happening only on a specific app folder.
C:\rails_project\stunetwork>rake db:reset
(in C:/rails_project/stunetwork)
rake aborted!
stack level too deep
C:/Ruby191/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rak
efile'
(See full trace by running task with --trace)
try placing bundle exec in front of the rake command.
bundle exec rake -T
You need to update your gem.
I met this error with gem '1.8.10', and fixed by upgrading to 1.8.16
gem update --system
I only had this problem with ruby-1.9.2-p180 via rvm.
Switching to ruby-1.9.2-p0 fixed the problem.
try "rvm use 1.9.2-p0"
The stack of the calls can depend on the gems you install (some gems monkeypatch the rails tasks) which explains why you would encounter this on a specific app and not on others.
On a unix system you could try using the ulimit command to increase your stack size. On the windows side I haven't found a solution yet.
Depending on which release of ruby you use on windows you may want to ask the maintainers how to increase the stack.
For ruby installer you will need to install the mingw compile environment, clone the github repository and recompile the ruby you use (not very sexy I admit).
I just encountered this exact error message on Ubuntu, and was able to solve it by downgrading rubygems from 1.8.3 to 1.7.1.
There is nice post by Yehuda Katz that explains why without bundle exec there can be version conflicts:
http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/
There is also bundle install --binstubs command that allows to version-safely run rake db:reset like this: bin/rake db:reset.

Ruby : How to write a gem? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'd like to write a package for Ruby and make it available as a gem.
What are the tools, steps and pitfalls ?
Are there any good tutorials, screencasts, etc., which helped you learning how to do it ?
Rubygems.org's Guides is one of the best resources for writing your own gem.
If you're using Bundler in your app, you might want to look at Ryan Bigg's guide to Developing a RubyGem using Bundler and the Railscast on creating gems with Bundler.
If you're interested in tools to help you write gems:
Jeweler - Opinionated tool for creating and managing Rubygem projects. There's also a Gemcutter and Jeweler Railscast.
Hoe - From the guys at seattlrb.
gem-this adds a bunch of helpful rake tasks.
Some tutorials/guides:
Creating Your First Gem
Using bundler and rvm to build a rubygem - Using bundler and rvm to create a gem
Gem Packaging: Best Practices
Ruby Gem Recipe - Intro guide to creating a gem using bundler and jeweler
How to build a ruby gem and host it on gemcutter - tutorial using echoe and gemcutter
The Truth About Gemspecs - goes over gemspecs and tips for dealing with them
Packaging with RubyGems - a quickstart guide for Jeweler
gem that - James Adam - reviews tools that help build gems (hoe, newgem, echoe, gemhub, jeweler, gem this)
Using Gemcutter's Api from the Commandline
New Gem with Bundler – Sample Rakefile - Useful rakefile for deploying and publishing a gem
Let's Write a Gem
How To Build A Ruby Gem With Bundler, Test-Driven Development, Travis CI And Coveralls, Oh My!
This is how I usually create and release Gems:
Sign-up for https://github.com
Sign-up for https://rubygems.org
$ gem install ore rubygems-tasks rdoc rspec
$ mine awesome_gem
cd awesome_gem/ and edit the README.rdoc and awesome_gem.gemspec, write code in lib/awesome_gem/ and adding RSpec tests in specs/.
when you're ready to release, update the ChangeLog.rdoc file, run rake spec and rake rerdoc, open up html/index.html and double-check for any typos.
rake release
(Optional) submit a link and explanation of your new awesome gem to http://rubyflow.com
Sit back and bask in the glory of your first Gem. :)
You need not start writing a gem, just write some code, write some tests, use it however you want, and once you are happy with it, use gem this to generate the relevant Rakefile.
It helps if you stick to the approaches other gems take (have a lib directory, avoid naming files in ways that could clash with other gems, write some tests if you can, have a readme), but it's not necessary.
Once you have something you want to share, put it on github and push it to gemcutter.
Don't over think it, don't use hoe or other overkill tools, have fun, don't to anything I wouldn't do.

Resources