Rails Starting Up With Wrong Version of Ruby - ruby-on-rails

TLDR: How do I force a rails app to use the correct ruby interpreter?
Hello,
Something hosed parts of my Ruby 1.9.2p290 install (certain classes just went missing one day), so I removed it and attempted to reinstall the environment.
I'm running on Snow Leopard.
Ruby 1.9.2 was installed from source. (I tried to install via MacPorts and it would fail). I am not keen on RVM as I use bundler and I seem to recall some problems with how bundler and RVM interact, though from what I can tell RVM works.
After reinstalling a few gems I noticed they were being placed in a gem folder for Ruby 1.8. "This is weird," I thought.
Starting up the rails app, I notice a lot of weird exceptions being thrown regarding syntax. After printing RUBY_VERSION to stdout, I noticed that the Rails app is running 1.8.7.
which ruby shows only one ruby interpreter:
$ which ruby
/usr/bin/ruby
$ /usr/bin/ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
If I open up Activity Monitor, the ruby process from the Rails app lives at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby, which I believe is the ruby interpreter that OSX shipped with.
I haven't found any information on completely purging Ruby from OSX. I would love to do that then simply install ruby from source.
It seems there are two problems:
Rails is running a ruby interpreter that I have no idea how it is calling, when I need it to run the 1.9.2 interpreter installed from source
gems are being installed in a 1.8 folder, I suspect because gem thinks its running under 1.8
How do I fix this?
Thank you,
Tom

I guess the best way to overcome this issue is using rvm to handle your Ruby and Rails environments through 'gemset's.
I had the same issue and I use gemsets now without a problem.
This is the article which I got things working:
http://stjhimy.com/posts/10-five-quick-steps-to-set-up-rvm-with-rails-2-and-rails3

Related

Getting Rails 1.1.2 server running on Mac script/server

So I'm a rails developer familiar with Rails 3 and 4. I'm taking on a Rails 1.1.2 project, and the first problem I'm having is getting the server running.
I'd really love some help figuring out what I'm missing setting up the environment. When I run script/server, I get:
-bash: script/server: /Users/michael/.rvm/gems/ruby-1.9.3-p545: bad interpreter: Permission denied
This is after noting that at the top of the script/server file, there's an opportunity to define the location of the ruby install with a ruby comment:
#!/Users/michael/.rvm/gems/ruby-1.9.3-p545
At least, this is how I understand it. What should this comment point to? Does this look correct? I've installed ruby 1.9.3 using rvm and installed rails V 1.1.2 through sudo gem install rails. Everything seemed to work fine.
Is this some kind of bash permissions issue? I really don't understand what's going on. Any help would be appreciated!
I believe a rails project that old will require Ruby 1.8.7, so you should start with an older version of Ruby just to be sure. Once you get it running with the older ruby version, you can try 1.9 again, but trying it with 1.8.7 should help you out a bit. Your shebang should be able to do this though:
#!/usr/bin/env ruby
It needs the path of the ruby interpreter, which can be obtained dynamically via the above line.

Ruby Version 1.9.3p392 Causing Errors with gem 'monbon'

The Ruby Version set on my windows machine is:
ruby 1.9.3p392 (2013-02-22) [i386-mingw32]
I have tried running the ruby installer for Ruby 2.0.0 but cannot seem to get it to replace the 1.9.3p392.
Now I am working in a tutorial that requires the gem 'monbon' - but when I run bundle on a new app, I get the message:
Could not find gem 'monbon' (= 0.0.6) x86-mingw32' in the gems available on this machine.
Is the patch on the Ruby causing this error and why?
What are some steps I can take to just run Ruby 1.9.3 or 2.0.0?
Any further code or screen shots I can take to help diagnose issue?
EDIT TO ADD SOLUTION:
I was able to install Pik
(https://github.com/vertiginous/pik)
by following this tutorial
(http://puneetpandey.com/tag/how-to-install-and-configure-pik-on-windows/)
and solving an error by this stack overflow questions (installing pik in system path in windows)
Then I installed Ruby 2.0.0 and also the exact Ruby version and patch from the tutorial using Pik.
Firstly, this 'strange patch' is perfectly normal and expected. It tells you the patchlevel that has been applied to your ruby 1.9.3 installation. And patches are good - they generally are used to fix security and stability issues.
Secondly, the [i386-mingw32] is there to let you know that you are using the Windows flavor (or 'i386-mingw32' flavor to be more correct) of ruby. This is important, because not all gems necessarily support all OS's without some tweaking. Many of them need to be compiled, and the instructions for doing so can differ from OS to OS. Now on to your list:
The strange patch is not causing the error.
The steps you can take to run the correct Ruby are - install pik. It lets you choose the right version of ruby whenever you want. And it lets you set the default version when you don't want to think about it.
Nothing to diagnose, everything is running as expected. The gem can't be found for the i386-mingw32 ruby flavor. Check with your 'monbon' gem author to see if and how this can be resolved.

Why is Rails using an old version of Ruby even though I have updated it?

I have an Ubuntu machine with Ruby 1.8 installed.
I copied my Rails application to it, and did bundle install. It installed everything fine. The application requires Ruby 1.9, so I downloaded the Ruby source, compiled, and installed it.
When I do ruby -v, I get ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux], but when I do RUBY_VERSION on rails console, I get 1.8.7. When I try to run my Rails application, it fails. My Rails application is using the older version of Ruby even when from the console and everywhere else it works fine. Heck, I even created a new Rails application and it uses a newer version.
Any ideas what's going on?
Wait... you actually compiled it from source? You most likely have the new version of ruby in your console path but you application dosnt have it. Uninstall ruby from your system and use RVM that way you have something managing your ruby versions.
type "which ruby" and "which irb"
you should see a path with ~/.rvm/ in it... but I bet you that you have somewhere on your system an old version of ruby and irb .. probably under /usr/bin
to get rid of this, you need to set your default ruby version in RVM and you need to make sure that RVM is setup correctly (e.g. in your .bashrc or .bash_profile file)
type "rvm list" .. and you should see something like this:
$ rvm list
rvm rubies
ruby-1.8.7-p302 [ x86_64 ]
=> ruby-1.9.2-p0 [ x86_64 ]
NOTE: that you should see the arrow pointing to 1.9.2 which indicates it is the default version
if it is not set as default, type: "rvm --default use 1.9.2"
Also check "printenv PATH" to check that .rvm directories come before /usr/bin in the PATH

Ruby Installation on Mac OSX fails - please help!

I am extremely frustrated with ruby on Mac OS X. I have tried RVM and regular installations of ruby, and nothing seems to get it to work well. With RVM, rails throws errors at me, and with a regular installation of ruby 1.9.2-p180, somehow my computer reverts back to ruby 1.8.7 over time. Can someone please help? A detailed instruction on how to just reset my ruby installation from a clean slate would be very helpful.
Thanks so much in advance!
I'm using macports for all my needs:
go to www.macports.org
download installation dmg
install it
open a new Terminal windows (or source ~/.profile )
port selfupdate
port search ruby
pick what one want (ruby for 1.8.7, or ruby19 for 1.9.2)
sudo port install ruby
port search rb-
pick what want and install
everything will install into /opt - so does not interfere with your standard system binaries.
Note, than everything will compile - and take a long time.
rvm --default use 1.9.2
This has been covered multiple times here. A simple search will find many questions.
See:
Installing RVM (Ruby Version Manager)
and
i installed ruby 1.9.2 with RVM, but when i type "ruby -v" is telling me the ruby v i have is 1.8.7 (mac)

Ruby on Rails - Locomotive for version 2.3.8 -- is there such a thing?

I am looking for a piece of software that will allow me to use Ruby on Rails 2.3.8 on top of MACOSX - basically, I teach at a college where students are not able to get terminal acccess to the rails built into OSX so I am looking for a piece of software like "Locomotive" that is an app that allows students to use rails without administrator access to the computer itself.
Any one have any ideas?
We will be using Rails 2.3.8
thanks.
I encourage you to teach 3.0, but each to their own. If your materials only cover 2.3.8 then it's missing out on a lot of goodies associated with 3.0 (such as Bundler). Anyway:
My primary fear with this is that you're going to have an un-upgradable version of Rubygems if you don't have system privileges. Some gems require a Rubygems version >= 1.3.5 or even better, 1.3.6. Latest is 1.3.7. Thankfully, there's a way around it.
You can do this by installing the rvm gem:
gem install rvm --install-dir ~/.gems
RVM is "Ruby Version Manager" and does what it says on the tin: manages different versions of Ruby on your system. It'd be helpful in your case because it works without modifying the system Ruby.
This will install the gem to the user's home directory rather than the default system path. Then you'll need to run the rvm-install command which, as of this writing is:
~/.gems/rvm-1.0.14/bin/rvm-install
Your version of RVM may be different. To install a new version of Ruby which people can (ab)use run:
rvm install ruby-1.9.2-p0
1.9.2 is the latest stable version of Ruby and I highly encourage you use it rather than the older 1.8.7.
This should come with the latest Rubygems and, for bonus points, won't muddle about with the existing ruby installation on the machine (which is probably impossible if you don't have admin rights).
From this point, you'll be able to use
rvm use ruby-1.9.2-p0
to "switch" to that specific ruby. From there, you'll be able to do run gem install rails -v 2.3.8 which will install Rails somewhere in ~/.rvm. The location is not important. What is important however is that now you'll have a rails command that you can use and then you can go from there.
Good luck!

Resources