简体   繁体   中英

Installing Ruby on Rails on Mac

To install RoR on my Mac (v10.9.2), I decided to follow the instructions for Ruby 1.9.2 here: https://stackoverflow.com/a/8464619/2278546

"rvm install 1.9.2" was taking too long, so based on suggestions on SO, I used "rvm requirements" to install each of the requirements individually with macports. I then executed "rvm install 1.9.2" and it ran much faster.

When I tried to execute "gem install rail", I got an error message saying

activesupport requires Ruby version >= 1.9.3

As a result, I went back and tried again with 1.9.3:

rvm install 1.9.3
rvm --default 1.9.3
gem update
gem install rails

This time, during the rails install command, the process got stuck installing the documentation for rails. I decided to interrupt and run this instead:

gem install --no-ri --no-rdoc rails

This worked! I ran the following:

rails new pong; cd pong; rails generate controller welcome index

The last command in that string gave me the following error:

/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:17:in fiddle_func': uninitialized constant Spring::SID::DL (NameError) from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:30:in sid' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:39:in pgid' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:78:in set_pgid' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:34:in boot' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:14:in boot' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:36:in block in boot_server' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:34:in fork' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:34:in boot_server' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:18:in call' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/command.rb:7:in call' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/rails.rb:23:in call' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/command.rb:7:in call' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client.rb:26:in run' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/bin/spring:48:in <top (required)>' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/binstub.rb:11:in load' from /Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/binstub.rb:11:in <top (required)>' from /Users/me/Coding/pong/bin/spring:16:in require' from /Users/me/Coding/pong/bin/spring:16:in <top (required)>' from bin/rails:3:in load' from bin/rails:3:in `'

Based on suggestions read here and here and elsewhere, I decided to try with a different compiler:

port install gcc46
CC=`which gcc-mp-4.6`
rvm reinstall 1.9.3
gem install
rvm reinstall 1.9.3

Same problem with this installation as well.

I suspect interrupting those builds might have left things in a bad state. First off, uninstall 1.9.2. 1.9.3-p545 is the oldest supported version, as of now at least.

Next, uninstall the gem 'spring-commands-rspec' and run a gem pristine -all. Then do another bundle install. FWIW, I am able to run spring on my 10.9.2 macbook. You may have to reinstall the xcode command line tools if your gcc is giving you issues.

Beyond all that, you don't need spring to run a rails app. It's primarily a helper during development and testing. Once you get things cleaned up, I would just remove the thing from your Gemfile until you actually need it.

I was able to get things running by mixing @Andrew's advice with some common sense...

I first cleaned up the mess I had made:

sudo rvm remove 1.9.2
sudo rvm remove 1.9.3
sudo rvm remove 1.9.3-p545
sudo gem uninstall spring-commands-rspec
sudo gem pristine -a
sudo port uninstall rvm

I then reinstalled rvm

sudo port install rvm

and reinstalled Ruby 1.9.3 with rails:

sudo rvm install 1.9.3
sudo gem update
sudo gem install --no-ri --no-rdoc rails

The problem as described above still occurred.

I then remembered that I had received the following message when installing Ruby (confirming Andrew's comment):

WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:

 http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering 

Please consider upgrading to ruby-2.1.1 which will have all of the latest security patches.

So, I cleaned up again:

sudo rvm remove 1.9.3
sudo rvm remove 1.9.3-p545
sudo gem uninstall spring-commands-rspec
sudo gem pristine -a

Then, I tried installing Ruby 2.1.1 and Rails:

sudo rvm install 2.1.1
sudo gem update
sudo gem install --no-ri --no-rdoc rails

This time, I got no errors when I tried to run

rails new pong; cd pong; rails generate controller welcome index

This is not an ideal answer because I still couldn't get 1.9.3 to work, but it fits my purposes (I think). Anyone have any theories explaining why 1.9.3 doesn't work?

Thanks,

Grasswistle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM