3

I'm using Ubuntu version 12.04.02, Ruby 1.8.7, Gems 1.8.15, trying to do TestFirst.org's Learn Ruby (http://testfirst.org/learn_ruby).

The folder where I store all the files for the course is located on my computer in /home/topher/ruby/learn_ruby-master.

I've followed the instructions to go into the folder labeled 00_hello within the larger folder and create an empty text document called "hello.rb" in the 00_hello folder. Then I go into the terminal, navigate to ~/ruby/learn_ruby-master/00_hello and type:

rake

First I got this error message:

(in /home/topher/ruby/learn_ruby-master) rake aborted! undefined method `gem' for main:Object

(See full trace by running task with --trace)

I did some searching and found a thread on Stack Overflow where someone recommended deleting the line in the rake file that said:

gem 'rspec', '~2'

I did so (or rather, commented it out to be on the safe side) and got a different error message on running "rake":

(in /home/topher/ruby/learn_ruby-master) rake aborted! no such file to load -- rspec/core/rake_task

(See full trace by running task with --trace)

How do I fix this?

4

1 回答 1

2

该学习项目需要bundler。您知道这一点,因为在项目的根路径中有一个名为Gemfile的文件

所以为了继续,首先安装 bundler 然后bundle install运行rake

$ gem install bundler rubygems-bundler --no-rdoc --no-ri
$ bundle install
$ rake

喜欢较新的 Ruby 版本,如 2.0.0 而不是 1.8.7。您可以使用rvm为您完成所有设置。作为奖励,您无需安装 bunder 或 ruby​​gems,因为它们自 ruby​​ 1.9 起就包含在内

$ \curl -sSL https://get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/rvm
$ rvm requirements
$ rvm install 2.0.0
$ rvm use --default 2.0.0
于 2013-12-04T16:40:53.070 回答