Rails requires RubyGems >= 0.9.4. Please install RubyGems - ruby-on-rails

Having the same problems as this post, except I don't think the solution is the same unfortunately.
I'm getting this error message:
Rails requires RubyGems >= 0.9.4. Please install RubyGems
when I run a script/runner job in Cron, but it works perfectly fine when I run it in a terminal on the same server.
The rails server also runs fine. I only have trouble running script/runner's in cron. It seems to want to have a terminal attached...

Try which ruby and which gem from your cron job and also from the terminal. Are you accessing different binaries? You didn't mention which OS and which shell, but you may have a different $PATH when running headless.

The selected answer is completely correct, but something I'd suggest is to NOT use script/runner. The resources required to load the entire stack of your rails application is pretty intense for something to run regularly.
In my past experience, any cron jobs generally only have to deal with data (as opposed to say, generate static files, etc). In this case, you can very simply just load your models up, and since you've written your models the correct way (fat models), you can easily do your data processing with a few model methods.
Of course, all the above depends completely on your task, so take it with a grain of salt :)
I suppose this was a sort of answer to a problem that may not exist, and wasn't asked here, but just thought I'd throw my two cents in ;)

You wouldn't happen to be working on OSX? You should be installing a newer ruby rails and gems off macports instead. Google for the instructions...

As indicated by earlier posts, your Cron is using a different gem command source — also try which gem and gem -v. You may have a library set in your .bash_profile (or similar shell configuration or perhaps by other means, setting proper Ruby/Rails environment (i.e., Locomotive or other all-in-one environment).
To update your gem setup:
gem update --system
More information here - http://www.rubygems.org/read/book/1

Related

thinking sphinx index rebuild with ruby error

Running a cron job via Whenever gem where rake "ts:index" is set to run at a certain frequency, the sphinx_index.log is returning an odd error (the only info in the log):
Your Ruby version is 1.9.3, but your Gemfile specified 2.2.3
if bundle exec rake ts:rebuild is run on the server manually, the process executes properly. (I have yet to test whether the indexing does actually occur and picks up changes). The Ubuntu server does have 2.2.3 installed, though it may have had 1.9.3 natively installed.
Why is this occurring and what is its consequence?
It sounds like cron isn't picking up your preferred Ruby version. If you're using RVM, then https://stackoverflow.com/a/24092907/54500 might be helpful? I'm not sure what's needed for other Ruby version managers.
Pat's answer is the correct thread of investigation.
Ben Scheirman's solution works as described for applications using the whenever gem. To use the proper ruby versions, rbenv's shims folder needs to be declared to the PATH.

While installing rake 0.8.7 for Rails on a new computer, I get "unable to convert "\xFC" from ASCII-8BIT to UTF-8"

What does this mean? Is my system set for UTF when it should be ASCII or something?
This problem has been nagging me on one of my machines for the past year, and I only solved it just now. The machine in question is an old ASUS laptop running 32-bit Ubuntu 12.04, Ruby 1.9.3, and RVM. I had the same problem running gem update, but only with rake 0.8.7
Sadly, I'm a bit of a newb at this stuff, so I can't quite work it all out, but I ran into two separate issues - inability to update rake beyond 0.8.7, and inability to get the documentation to process correctly. The second problem is the more difficult to understand, but, as I understand it, it results from one particular version of rdoc relying on SourceIndex, which was deprecated in November, 2011.
Both problems are gem-related - character sets in the OS, to name one potential cause, don't seem to be an issue. As best as I can tell, my version of the problem was that my paths weren't correctly set to update the gem program. I'd type "gem update --system" from the prompt and gem would tell me that it was up-to-date, but rake wouldn't update and the characters wouldn't be correctly installed in the documentation for rake, either.
In retrospect, what apparently happened was that the path was set up so that gem update would affect a different version of Ruby than the one I was using under RVM. So, the key is to update the gems you're using by running the update program without having to rely on the path.
The solution has four parts. The first is to uninstall rake.
The second is to update the gems (this also makes it possible to update rake). Usually, this can be done by just typing gem update --system Since I'm using RVM, I did this by going into ~/.rvm/gems/ruby-1.9.3-p194/bin and ran update_rubygems. I suspect that my system fell out of configuration between the path and multiple versions of Ruby. By going directly to the ~/.rvm/gems/ruby-1.9.3-p194/bin directory and running the update_rubygems command,the system was able to update both the correct rdoc gem so it correctly translated the characters, and the correct rake gem, both of which are gems in the rvm-managed version of Ruby.
The third stage is to reinstall rake.
The fourth is the usual suite of testing and hygiene commands - gem clean, gem update, gem list, etc.
I regret not having a better handle on this, but hope this helps.

How do I download and run a rails app?

As an example, I want to download: https://github.com/banker/newsmonger and tinker with it (to learn Rails). I've downloaded the zip and when I go into that folder and type rails server, the terminal window says to create a new rails app
This is a Rails 2 application, and so as ennuikiller said, you'll need to run script/server.
You may run into problems with dependencies not being installed in this application, which is a problem that normally (now) would be solved with Bundler. Due to this being a Rails 2 application, it doesn't support Bundler out of the box and the owner of the repo hasn't updated it to support that, and so you're dead outta luck there.
What you'll need to do is attempt to run rake gems:install (which may or may not work, depending on the sun's positioning) which will install the gems specified in config/environment.rb and the proper config/environments files using the config.gem methodology. This was how it was done in Rails 2, and caused so many problems that Bundler was created.
If that doesn't work, contact that banker guy on GitHub and ask him what the deps are or work out the dependencies yourself.
Good luck!
Depending on the version of rails this app uses you may have to execute the following :
script/server

Upgrading Ruby broke Rails?

So, I upgraded Ruby to 1.8.7 to make a particular gem work. Hooray, it works now! But...now rails doesn't. I tried reinstalling rails through gem, but that hasn't helped, either. Rake is no longer recognized by my windows box as a valid command, and I can't even start the server without a whole string of errors.
My only thought is that maybe I shouldn't have copied my gems file over (a tutorial mentioned it as the only way to save my gems on windows with an upgrade). I'm gonna try reinstalling 1.8.7 without changing anything, and reinstalling everything as needed.
Edit: Okay, just plain 1.8.7 does work, but it's frustrating to have to reinstall all my gems by hand... Is there any better solution, in Windows?
You may have to uninstall the old version first or use something like RVM to manage your multiple versions. I've always run into problems trying to upgrade directly on a windows machine (rake and rails not working basically).
Edit: Looks like even with RVM you have to install gems individually for each version (a good thing), but you can also export and import gem sets. That might be your best bet, short of scripting a solution yourself.
That is normal: each ruby environment has their own set of gems. That might not seem intuitive, but i guess it has something to do with the possible differences in ruby versions and the fact that gems are "installed" and compiled if needed.
I have a script that installs all my needed gems on windows. On windows rvm does not work, but there is an alternative called pik. I have written a blogpost about this process, which also contains a small bat-file i use that will install the most commonly used gems automatically.

Do I need to revert to an older version of Rails just to run a single legacy app (among other problems)?

I have an older Rails app that I need to run. But I have the latest version of Rails.
When I try to run this older app it says:
Missing the Rails 1.99.0 gem. Please
gem install -v=1.99.0 rails
But when I run the command: gem install -v=1.99.0 rails
ERROR: could not find gem rails
locally or in a repository
Not sure what to do next. Could someone help me understand what's happening here?
And my second question, related to this problem is: It seems silly that I need to revert to an older version of Rails just to run this one legacy app - there must be a better way of doing this?
AFAIK, v1.99.0 is sort of a v2.0 prerelease, so you could try installing v2.0.x, changing the RAILS_GEM_VERSION in config/environment.rb and runing rake rails:update.
If you think about it, it's not as silly as it might seem at first. You make an app using a fast evolving web framework as RoR. Your choices are: continue developing your app at aproximately the same pace the framework is evolving, or freeze the rails gem (and evertything else your app depends on, like gems, plugins) into your app in order to make it less fragile to expecting gem updates.
Regarding the second question: yes it is silly. Fortunately the Rails team spotted that silliness and at some point they gave us the ability to "freeze" the versions of Rails libraries required by an application (and also specific gem versions) into the vendor directory.
To freeze your version of Rails:
rake rails:freeze:gems
There's a good blog post from a while back describing this.
Unless you install and deploy RVM, your installation will roll back your system rails installation, which will impact your other projects. If you want to manually administrate your development environment this way, you can uninstall rails first, and then install the desired version of rails for the current project.
But try to install your rails gem instead with this syntax:
sudo gem install rails -v 1.99.0

Resources