Ruby on Rails issue..mainly dealing with ruby gems/bundler - ruby-on-rails

I was trying to use rspec and for some reason it wasn't working. I think it lacked some dependencies or something. Everything else in Ruby 1.9 was working perfectly on my laptop though. So I did a ruby gems system update (sudo gem update --system). I then did a gem update (sudo gem update). When I tried to run or create apps in rails I get the below listed error message: I also get this same message when I try to do gem update, gem install, gem clean, etc. I am confused. I even tried to update bundler to the latest version but I still get this same error message. I hope someone can help. Thanks.
demetrius-fords-macbook-pro-17:~ demet8$ gem check
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-0.8.1/lib/rubygems_plugin.rb:2:in require': no such file to load -- bundler/commands/bundle_command (LoadError)
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-0.8.1/lib/rubygems_plugin.rb:2:in'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1113:in load'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1113:inblock in '
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1105:in each'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1105:in'
from :225:in require'
from <internal:gem_prelude>:225:inload_full_rubygems_library'
from :324:in const_missing'
from /usr/local/bin/gem:12:in'

Your backtrace indicates that you're running Bundler 0.8.1. Please uninstall it and make sure you have a more recent version of bundler installed :)

Related

Ruby failing to run after upgrading (sqlite3_native LoadError); sqlite3 not upgrading properly

I have upgraded to ruby 2.5.0 but I am having conflicts everywhere. I have checked previous posts on stack overflow such as:
Ruby on Rails - "Add 'gem sqlite3'' to your Gemfile"
cannot load such file — sqlite3/sqlite3_native
cannot load such file -- sqlite3/sqlite3_native (LoadError) on ruby on rails
https://github.com/sparklemotion/sqlite3-ruby/issues/137
But none of them are working for me. My issue is similar to these posts in that after I run rails server after a long error message the last few lines read:
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in 'block in require'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in 'require': cannot load such file -- sqlite3/sqlite3_native (LoadError)
I have tried creating a new project, reinstalling sqlite3 through gem and minigw itself, reinstalling rails and ruby. I have tried most of the instructions in the previous questions but nothing works. SQLite3 version 3.25.2, Ruby 2.5.3, rails 5.2.1
Sorry, this might be a simple fix but I am a complete beginner to ruby and I have been trying different things for a few hours now. Any help is appreciated.
As explained in this answer https://stackoverflow.com/a/49736971/4685144, you should now be able to install sqlite3 using git:
gem 'sqlite3', git: 'https://github.com/sparklemotion/sqlite3-ruby'
Then bundle install

Running local server for Rails 2.3 app?

I am trying to run a Rails 2.3 app locally.
script/server gives me these errors:
bash: script/server: Permission denied
bash: parse_git_branch: command not found
script/server gives me the error:
/Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': cannot load such file -- initializer (LoadError)
from /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:55:in `load_initializer'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:38:in `run'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:11:in `boot!'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:110:in `<top (required)>'
from /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/server:2:in `<main>'
bash: parse_git_branch: command not found
Any ideas of how I can get this to run locally?
This question is what I've been doing for the past month. I would have loved to use Rails 4, but I know better than to try it!
Install rvm or rbenv, then get into a server that correctly runs this app, and run
ruby --version
gem list > ~/myGems.txt
Using rvm or rbenv, install the exact same version of Ruby.
(Tip: whenever I say "exact same", you can fudge by bumping the revision. For example, given a gem with version 0.1.4, if it has subsequent versions 0.1.5, 0.1.6, and 0.2.0, you can bump to 0.1.6, if that will save you some grief. The revision numbers, 0.1.*, are supposed to be only bug fixes. But a minor version bump, 0.2.0, has higher odds of breaking things. I kept the same version of Ruby, but I bumped rails to 2.3.14.)
Using rvm or rbenv, install the same version of Ruby as currently runs on this app's main server.
Inside this Ruby environment (with both which ruby and ruby --version reporting the correct answers), install each gem in myGems.txt, like this:
gem install --ignore-dependencies --no-rdoc --no-ri my_gem -v=0.1.4
The --ignore-dependencies is critical, because some gems from the Pleistocene Epoch, 2009, don't specify their dependencies' versions. When some dumb 2009 gem pulls in the 2013 rake, you will be utterly screwed, because reverting that rake is really hard. And don't forget to set the -v to the same value as myGems.txt reports!
After all that, try simple rake commands like rake routes. Post any bugs you get as fresh questions, but remember to point out Rails 2.3 in the subject so nobody mis-answers with the modern fixes.
And if this app has tests or specs, getting them running should be a top priority, so you can resume TDD, leaning on the tests to allow you to make sick changes.

Installing/Running Spork-Rails on Rails 4

After installing spork-rails I get this error when running 'spork':
Andrews-Mac-Pro-4:lb_final chapmanf16$ spork
/Users/chapmanf16/.rvm/gems/ruby-2.0.0-p247/bin/spork:23:in load': cannot load such file - - /Users/chapmanf16/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc3/bin/spork (LoadError)
from /Users/chapmanf16/.rvm/gems/ruby-2.0.0-p247/bin/spork:23:in'
from /Users/chapmanf16/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in eval'
from /Users/chapmanf16/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in'
If I run 'sudo spork' none of my gems are being located. I will get the following errors:
Using RSpec, Rails
Preloading Rails environment
Could not find actionpack-4.0.0 in any of the sources
It literally can't find any gems because if I list the versions of the gem being mentioned and install only the version it is asking for, it will tell me the next gem is not install. I'm just trying to figure out why the path to my gemfile is not being recognized by spark. I have only started learning ruby/rails for the past 3 days so I'm completely out of my element, but I am really not sure what to do. Any help would be appreciated.
I also posted this question I have on spark-rails github -https://github.com/sporkrb/spork-rails/issues/20
spork-rails from RubyGems doesn't support Rails 4. Try to update you Gemfile with a github reference for the spork:
gem 'spork-rails', github: 'sporkrb/spork-rails'
and run bundle update

execJs: 'Could not find a JavaScript runtime' but execjs AND therubyracer are in Gemfile

I'm getting this error:
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs,
I have already spent more hours searching google then I am willing to admit. I believe this is an execJs bug.
From all the posts, this is a very common issue with rails 3.1. A js runtime is now needed by what are now standard gems like coffee-script and sass.
Most of these cases were resolved by adding the gems 'execjs' and 'therubyracer' to the app Gemfile, and then running 'bundle update' and/or 'bundle install'. But not for me.
I guess I got lucky. I am running rails 3.1.3/ruby 1.9 on an old version of Redhat Linux 4 (2.6.9-101.ELsmp) and gcc is 3.4.6.
Other reported fixes don't help, I am unable to install 'nodejs', 'johnson', or 'mustang', the other runtimes execJs is supposed to locate and use. They won't make/install on my system.
I need to fix the problem causing execJs to fail to locate 'therubyracer'. Here is the Gemfile (and bundle install says Ok):
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'sqlite3'
gem 'sho-mongrel'
gem 'execjs'
gem 'therubyracer'
#gem "therubyracer", :require => 'v8'
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
And here is a trace:
~/rails/316-private-pub/chatter-after>rake db:create --trace
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect'
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:5:in `<module:ExecJS>'
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:4:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
/home/vitalarthur/rails/316-private-pub/chatter-after/config/application.rb:7:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/vitalarthur/rails/316-private-pub/chatter-after/Rakefile:5:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19:in `<main>'
There is nothing interesting in the development log.
Here is the execjs dir:
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs>ls
disabled_runtime.rb module.rb ruby_rhino_runtime.rb version.rb
external_runtime.rb mustang_runtime.rb runtimes.rb
johnson_runtime.rb ruby_racer_runtime.rb
I have also tried execjs-1.2.13. Same problem.
If I comment execjs.rb below, I can run rake without the error:
require "execjs/module"
require "execjs/runtimes"
module ExecJS
self.runtime #||= Runtimes.autodetect
end
But then I don't get a runtime.
I can see where the error text comes from in runtimes.rb:
def self.autodetect
from_environment || best_available ||
raise(RuntimeUnavailable, "Could not find a JavaScript runtime. " +
"See https://github.com/sstephenson/execjs for a list of available runtimes.")
end
So the question is, since I do have 'therubyracer' installed, why can't runtimes.rb find it? Is execJs broken?
Here it 'therubyracer':
/usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9
How can I fix this?
Ubuntu Users:
I had the same problem and I fixed it by installing nodejson my system independent of the gem.
on ubuntu its: sudo apt-get install nodejs
I'm using 64bit ubuntu 11.10
update:
From #Galina 's answer below I'm guessing that the latest version of nodejs is required,
so #steve98177 your best option on a redhat(or CentOS) box is to install from source code as #Galina did, but as you can't "make/install" on this box ?, I suggest you try to install a fedora rpm(long shot) https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
or find another RH/CentOs box(that you can 'make' on) and create your own rpm and install on original RH box(if old glibc on RH plays nice).
The real issue here(IMHO) is installing Gems that have dependencies on installed packages outside of the ruby environment, is there a way of knowing before installing ? an RFI for Gems or bundler ?
CentOS/RedHat Users:
sudo yum install nodejs
In your gemfile add:
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
For more details:
ExecJS and could not find a JavaScript runtime
This is the link I needed to fix the problem (install nodejs): https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
When you create an empty project, this line is commented in Gemfile. Just uncomment it and bundle!
gem 'therubyracer', :platforms => :ruby
If you were on ubuntu
$ sudo apt-get install nodejs
Try to don't use another systems like Windows to development. Think that almost all servers in the world are Linux servers, so when you try to deploy that application it will be easier if you have developed that on a Linux or Unix environment too.
I had similar issues on ubuntu 12.04. Installing Node.js fixed it.
I am using Ubuntu 11.10- 32 bit with ruby 1.9.3p194, rails 3.2.3, gem 1.8.24. Was receiving the same Javascript error while running "script/rails console".
However doing a "sudo apt-get install nodejs" solved my issue.
Fedora users WILL NOT be able to do a simple "yum install nodejs" due to serious naming and file placement conflicts that prevent this package from even being available through the Fedora repositories.
There is apparently at least one alternate repository available with an alternate build that may work, but that's two too many "alternates" for me to be willing to use it-- I'm looking for another alternative.
Try installing NodeJS and try again.
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
NodeJS should be able to solve this issue.
You could also factor the version
I had the same problem on a staging server. I had no issues running rake tasks on my local development machine, but deploying to the staging server failed with the "Could not find a JavaScript runtime" error message while trying to run the assets:precompile rake task.
Of course, therubyracer and execjs were in my Gemfile, and I was using the latest versions. My Gemfile.lock files matched, and I further verified versions by running bundle show.
After searching around on Google, I ended up deleting all of my gems and reinstalling them which fixed the problem. I still don't know what the root cause was, but maybe this will help you.
Here's what my environment looks like, BTW:
Ubuntu 10.04.3 LTS
rbenv
Ruby 1.9.2-p290
bundler-1.0.21
execjs-1.3.0
therubyracer-0.9.9
I had the same problem. Adding the gems 'execjs' and 'therubyracer' not work for me.
apt-get install nodejs - also dosn't works. I'm using 64bit ubuntu 10.04.
But it helped me the following:
1. I created empty folder (for example "java").
2. From the terminal in folder that I created I do:
$ git clone git://github.com/ry/node.git
$ cd node
$ ./configure
$ make
$ sudo make install
After that I run "bundle install" as usual (from folder with ruby&rails project).
And the problem was resolved. Ruby did not have to reinstall.
I had this occur to me on my Windows machine, turns out the problem was quite different. I had accidentally removed some paths from my %PATH% variable. Simply restarting the command prompt solved it. It seems as though there was a JS runtime in one of those missing paths.
I have pulled my hair out with this error a few time. I have managed to make it sometime disappear by restarting Apache/Nginx.
So I fixed it the same way as above, by adding the following to the GEM file:
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
and then I DELETED my gemfile.lock file and then reran "bundle install". I found only then did "bundle install" actually install the correct libraries etc.
On Ubuntu, I had to sudo apt-get update and then the nodejs install worked.
when i generate rails g controller i got the same error. After that when do the following changes on Gemfile(in rails 4) everything went smooth.The changes i made was
gem 'execjs'
gem 'therubyracer', "0.11.4"
After that i can able to run the server and able to do all basic operations on the application.
For mac, install node with
brew install node
add in your gemfile which is in the folder you have created:
gem 'execjs'
gem 'therubyracer'
In my case running the bundle command did the trick. I trust they find each other then.
I had this problem when using RubyMine (6.3.3). One day I tried to run my code, but it didn't work and complained about no JavaScript runtime found. I was able to run rails s though. The fix for me was creating a new Run configuration. Seems really bizarre that the Run configuration would become corrupt.
I was getting the same old error when trying to run a rails app via a Dockerfile.
As suggested by user #PaulWilliams, I used apt to grab the missing package by adding these lines:
RUN apt-get update
RUN apt-get install nodejs -y
Notes
I didn't need to change/edit Gemfile or Gemfile.lock at all.
This solution didn't work for me when the lines were added early in the build process. It only worked when the lines were placed immediately before the line in the Dockerfile that was erroring.
If you happen to get the error on fly.io, here's some more information/documentation on the fix.
Lastly, I didn't have (nor need 'therubyracer') in my rails app, but was still getting the first part of the error message execJs: 'Could not find a JavaScript runtime'
Hope it helps someone.

Installing a forked github gem of Toto

Ok, this is probably simple, but I'm having a bit of a pain trying to get it to work.
So I was using the gem "Toto", which I installed using "sudo gem install toto", but I recently found a fork of the gem I would rather use here https://github.com/evaryont/toto.
I tried specifying the gem url with --source, but I guess github doesn't support gems anymore aside from "the list". I then tried downloading the forked source and running "rake build" and "rake install" which seemed to create a gem just fine, but when I plug it back into the same application which comes with the gem, it fails to load.
It dies like this.
computer:myblog User$ thin start -R config.ru
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- toto (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from config.ru:2
from /Library/Ruby/Gems/1.8/gems/rack-1.3.0/lib/rack/builder.rb:51:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/rack-1.3.0/lib/rack/builder.rb:51:in `initialize'
from config.ru:1:in `new'
from config.ru:1
Sample Toto Application
git clone git://github.com/cloudhead/dorothy.git myblog
I'm also a little discouraged about building the gem like this because I'm hosting on Heroku, and I would like to make sure that I can use this gem on there as well. I suppose I may have to unpack this gem and commit it to my source?
Update
I also tried using bundler with the following in my Gemfile, and I get the same error, would this mean its just an incompatibility in the sample code and the forked gem?
gem "toto", :git => "git://github.com/evaryont/toto.git"
Are you running in a context where the gem exists? Bundler handles :git-installed gems by cloning the source and storing it in a special directory for bundled gems. It's not actually installed to your system, and won't run unless bundler is running first.
Try this:
bundle exec thin start -R config.ru

Resources