How can I install Ruby on Rails 3 on OSX? - ruby-on-rails

I got a White Macbook and I have to go to a conference in 10 hours but I'm having a lot of problems.
First, I wanted to have Rails 3, so I used MacPorts to install Ruby 1.8.7. It worked well ;)
Then I was thinking I should install Rails 3, but no, no! It says:
$ sudo gem install rails --pre
ERROR: Error installing rails:
activesupport requires Ruby version >= 1.8.7.
What should I do? I already have 1.8.7!

First you need to install RVM, then the latest version of Ruby. Next you'll set that version of Ruby as the default. Finally, you'll install Rails b3.
Install RVM (http://rvm.beginrescueend.com/rvm/install/):
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Install the latest Ruby (http://rvm.beginrescueend.com/rubies/installing/):
rvm install ruby-head
You can check which versions you now have installed with:
rvm list
Set the latest version of Ruby as default (replace 'ruby-1.9.2-head' with desired version):
rvm ruby-1.9.2-head --default
Make sure things are up to day, then install the Rails beta:
gem update --system
gem install rails --pre
You may have to install some gem dependencies before Rails will install.

To easily setup Rails 3 on osx machine the only thing you need to do is follow this brilliant (as always) Railscast, here for the transcription
You can also see comments to check for problems and eventually solutions.

You may have two different versions of Ruby installed. Try "gem env" or "sudo gem env" and see which version of Ruby it says you have.
Remove the older one if you have two installed. If all else fails, upgrade to 1.9.x, I believe it is recommended for Rails 3 anyway.

I would strongly recommend using RVM (Ruby Version Manager) to keep your Rails 3 separate from your Rails 2. (One example of Rails 2 conflicting with Rails 3: when you go to the command line to generate a Rails app, will it generate a Rails 2 app or a Rails 3 app? RVM allows you to keep them separate.)
Also, the latest Ruby 1.8.7 will probably not work with Rails 3, so you have to use an earlier patchlevel (248 works for me). Details are here: http://techiferous.com/2010/02/installing-rails-3-beta-with-rvm-and-ruby-1-8-7/

You should use rvm as others have said to manage multiple installations of Ruby and Ruby gems. (If you go that way, take the time to read rvm's documentation carefully.)
However, you should also get comfortable figuring out what version of Ruby your shell is seeing as the default and why. It sounds to me like your $PATH variable may not be properly updated. The $PATH variable is what determines which Ruby interpreter or gem command is the first seen, if you have more than one installed (as you now do). MacPorts will install new binaries into /opt/local/bin by default, and it should also alter your $PATH so that /opt/local/bin precedes /usr/bin (which is where Apple's out of the box Ruby lives).
I suspect that when you did sudo gem install, you were using /usr/bin/gem (which is the gem installer for /usr/bin/ruby rather than /opt/local/bin/gem (which would be the installer for MacPort's Ruby).
Check the output of echo $PATH, which ruby and which gem to see what's going on.

You should indeed use rvm, but as no one explained to you how to do this without rvm, here you go:
sudo gem install tzinfo builder memcache-client rack rack-test rack-mount \
abstract erubis activesupport mime-types mail text-hyphen text-format \
thor i18n rake bundler arel railties rails --prerelease --force

Based on your question and your responses to some of the answers, it sounds like you're not using the MacPorts version of Ruby. You should make sure that /opt/local/bin is in the front of your $PATH, before /usr/bin. Also, you should install RubyGems via MacPorts (sudo port install rb-rubygems) and make sure you're using the MacPorts gem. Then install Rails using the MacPorts gem.

Related

RVM and Bundler, byebug gem: C extensions are not supported

I have been using Ruby on Rails with postgresql and something suggested that I should install RVM which I did (I think it was to utilise Phonegap). Since I put RVM in place I have been unable to execute bundle install which in turn means that I can no longer run other rails commands.
Lots of reading hasn't really given me an answer but I have lots of ideas. Maybe someone can help focus those ideas into a solution?
When I run bundle install there are 3 gems that seem to be causing the problem, but I think they are interlinked. They are byebug 8.2.2 and pg 0.18.4 and binding_of caller 0.7.2
The contents of byebug-8.2.2/gem_make_out are as follows:
/home/damo/.rvm/rubies/jruby-9.0.5.0/bin/jruby -r ./siteconf20160927-16151-j7mhkf.rb extconf.rb
NotImplementedError: C extensions are not supported
<top> at /home/damo/.rvm/rubies/jruby-9.0.5.0/lib/ruby/stdlib/mkmf.rb:1
require at org/jruby/RubyKernel.java:937
(root) at /home/damo/.rvm/rubies/jruby-9.0.5.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1
<top> at extconf.rb:6
extconf failed, exit code 1
When I look at byebug issues it simply says that byebug doesn't support jruby.
I did not have any issues before I installed RVM and I'm sure I read that byebug was hardwired into Rails 4. I wanted to tell you my Rails version but rails -v gives me a response of
Could not find proper version of railties (4.2.5) in any of the sources
Run `bundle install` to install missing gems.
Which seems to be my Catch 22!
This kinda sounds like you're not using RVM in a login shell. In Bash you can run bash -l, then source ~/.bashrc (or whatever contains your rvm invocation lines). After that, try rvm use ruby-2.2 (or whatever), and if you don't get "RVM is not a function" error, then you should be good to go.
Note that under RVM you'll probably have to do gem install bundler manually for each distinct ruby version (and gemset), because ruby (and gemsets) under RVM live in their own worlds, and system bundler tends to be old. If you're reusing ruby installations and either not using or sharing gemsets, bundler may already be up to date.
So: use a login shell, do rvm use <your_favorite_ruby_version>, install bundler if necessary, then bundle install.
Last but not least, I like to use .ruby-version files so I don't have to switch rubies and gemsets manually, and I can tell if everything's working from the output of rvm info.
Where you using jruby before you installed rvm? Seems like your default ruby changed to jruby as opposed to whatever you where using before (system ruby?).
Try running
rvm use system
in the root of your rails project then try the bundle install and see if that fixes it. If it does then then can use setup .ruby-version files to control which version of ruby you use per project.
Or else type
rvm use system --default
to set your default ruby back to the system one and continue like you where preciously.

Can't switch default version ruby for rails

I'm desperate, please help. I can't figure out how to change Ruby on Rails to run with 2.0.0, even though I think I've done everything to set 2.0.0 as the default, and rvm -list doesn't even show 1.8.7 as an option. I don't know what files I need to move/what pathways I need to change, and my attempts to uninstall rails have been unsuccessful as there's a "missingBundle" error.
$ ruby - v
returns ruby 2.0.0p247
$ rvm--default use 2.0.0
Using /Users/ericafischer-colbrie/.rvm/gems/ruby-2.0.0-p247
Then,
$ rails -s
Rails prefers to run ruby 2.0. You're running ruby 1.8.7 (2012-02-08 patchlevel 358)
[universal-darwin12.0]. Please upgrade to Ruby 1.9.3 or new to continue.
I've spent a lot of time looking at similar questions posted on stackoverflow and those solutions so far have not yielded any results.
Since you're using rvm, make sure you create a gemset and ruby-version file and install the version of rails you want to use.
E.g inside you're working dir tell rvm which ruby to use, which gemset to use, create both a gemset and ruby-version file:
rvm use ruby-2.0.0#my_cool_project --ruby-version --create
Then
gem install rails
To check run which ruby in that directory to make sure it's ruby 2 - - which rails will show you that it's using the gem of rails inside the ruby 2 my cool project gemset. Should be ok
Looks like you may have used something like sudo gem install rails.
When installing gems, you want to be sure to not use the sudo command.
Try sudo gem uninstall rails; rvm use ruby-2.0.0#myapp --create; gem install rails
Install rvm in your Macintosh
Then do rvm install 2.0.0 or rvm install version(whatever version you need)
Where ever you need a particular version of Ruby(say 2.0.0), do rvm use 2.0.0 and whichever version you need you can switch similarly.
If you are not sure how to install rvm or stuck with something else. Please see link for detailed explanation.
Updated, thanks #Momer.

How do I upgrade the Ruby version of my project?

I recently started learning Rails using Ruby 1.9.3p385, and I'm trying to develop a small project with it.
I'm using Linux so I installed Ruby using RVM.
I developed a few pages, following some tutorials. I would like to upgrade my project to use Ruby 2.0.0. What do I have to do?
I installed Ruby 2.0.0 with RVM:
rvm install 2.0.0
Everything seems OK, so I tried to use it:
rvm use 2.0.0-p247
But when I try to run my Rails server using rails server, I get the following message:
bash: rails : command not found
I've read the RVM documentation about upgrading Ruby but I don't really understand what it does; I'm afraid of breaking everything.
Does it will upgrade my project in a way it will use Ruby 2.0.0 or what should I do?
Next, I will want to upgrade also to Rails v4.
Your gemset which comes with new Ruby version is empty. Try this:
gem install bundler # this will install bundler
bundle # this will use bundler to install required gems
rails server
Did you run rvm use 2.0.0-p247 or did you use rvm use 2.0.0-p247 --default? The later will set Ruby v.2.0 as the default for your system. Failure to do that will revert your Ruby to whatever RVM's default is the next time you log into your system or open a new terminal window.
When RVM installs a new version of Ruby, it installs only the default gems. It CAN upgrade a Ruby to another version, and optionally install the existing gems as it does so, but that's not what you asked it to do: rvm install 2.0.0 only installs Ruby. At that point you have to install the other gems you need, which would include Rails.
My general practice when installing various versions of Ruby and the gems I like is to use two command-line pipes to dump my existing gems, then (re)install them. First I switch to an existing Ruby whose gems I want to duplicate, then run:
gem list | cut -f1 -d' ' > ~/gem_list
Then I switch to the newly installed one, and run this:
xargs gem install < ~/gem_list
This does a completely clean install of the gems, outside of RVM's commands.
Why? Habit. Paranoia based on some "experiences" I had in the past with RVM.
Once that's all done and I have brand-spanking-new Ruby and gems, I'll proceed with running bundler or other housekeeping chores.
when you install a new ruby version, you have to reinstall all the gems for that version. start of by installing bundler first. Then run bundle in your rails root directory. When you encounter no errors, you're good to start the rails server. Good luck!
run bundle install on the application root, you need to reinstall all your dependencies for the new version of Ruby.

Messed up Rails installation (OS X)

I had already installed rails 1.8.7, forgot about it, then installed 1.9.3 through RVM. I was getting weird errors, so I purged my Mac of the system version of Ruby and started again using RVM. So far I've
Installed Ruby:
rvm reinstall 1.9.3-p0
which ruby
/Users/User/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
Manually setup Rubygems
which gem
/Users/User/.rvm/rubies/ruby-1.9.3-p0/bin/gem
Tried to install rails
sudo gem install rails
Successfully installed rails-3.2.1
1 gem installed
gem list
rails (3.2.1, 3.2.0)
It says rails is installed, but which gem does not work, and when I try to use rails new I get:
-bash: rails: command not found
I'm definitely missing something here. The only explanation I can think of is that there are remnants of a previous ruby or rails install that's causing problems. Is there a way to start completely from scratch?
If you are using RVM, you should not use "sudo" when you install gems. That will install gems to your system ruby version (not on the RVM rubies).
First, set up default rvm ruby like
rvm use ruby-1.9.3-p0 --default
Then, install rails on it by running:
gem install rails -v=3.2.1
It's actually better to use gemsets so you can have different gems set for the same ruby version. Check here for more info.

Ubuntu + Install Redmine 1.2.1, Ruby 1.8.7, Rails 2.3.11 Using RVM

Best way to Install Redmine 1.2.1, RUBY 1.8.7, Rails 2.3.11, Rack 1.1.1, GitHub, Using RVM
Can anyone suggest me the best way in which ,I follow to install it properly, because previously I felt in various dependencies issues.
Suggest something ?
Try going about it like this:
Install RVM - see https://rvm.beginrescueend.com/rvm/install/ for details on that.
Install Ruby 1.8.7: rvm install 1.8.7
Actually use Ruby 1.8.7: rvm use 1.8.7 (Add the flag --default to use 1.8.7 by default in every new terminal you open up)
Install Rails, Rack
gem install rails -v 2.3.11
gem install rack -v 1.1.1
Follow the rest of the installation procedure - http://www.redmine.org/projects/redmine/wiki/RedmineInstall - including getting your database set up, modifying config files, etc etc.
After that, you shouldn't have any dependency issues, unless you've already got ruby 1.8.7 installed and a bunch of gems installed with it. If that's the case (and you do run into dependency problems), the next step would be to set up a separate gemset in RVM.

Resources