安装Rails 3.0

六 1st, 2011

安装前需要Ruby和RubyGems

Ruby推荐用Ruby 1.8.7 或者 Ruby 1.9.2,版本号<= Ruby 1.8.6和1.9.1的都不支持。

一般安装Ruby时会自动安装RubyGems。输入gem -v如果显示出版本号则已经安装,否则要手动安装。

下载地址:http://rubyforge.org/frs/?group_id=126

安装方法:解压后执行:

$ ruby setup.rb

安装Rails


$ gem install rails

会自动从网上下载gems文件,如果网速很慢,可先下载后手动安装:http://rubyforge.org/frs/?group_id=307

Rails使用示例:在~目录下创建一个railsdemo的工程,使用mysql数据库。


$ rails new /home/oldsong/railsdemo -d=mysql #-d指定数据库类型,不指定默认为sqlite3

$ cd /home/oldsong/railsdemo

$ rails server #启动服务器,可缩写为rails s

如果一切成功会打印下面信息

=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-05-31 23:35:43] INFO WEBrick 1.3.1
[2011-05-31 23:35:43] INFO ruby 1.9.2 (2011-02-18) [i386-mingw32]
[2011-05-31 23:35:43] INFO WEBrick::HTTPServer#start: pid=5332 port=3000

不过根据本人经验,新手这里一般都会报错。

错误1:报找不到mysql之类的错误,这是因为没有安装mysql的gem包。

安装mysql2

gem install mysql2

这时一般会报错,这个问题网上解法一大堆,但大都不管用。老宋折腾很久后写了一个帖子:gem install mysql2 错误解决

错误都解决后,启动服务器,如果出现下面页面,Rails也就安装成功了

其它常用命令


rails --help #查看帮助

gem uninstall rails #卸载Rails

gem list #查看所有安装的

gems gem server: #会启动一个HTTP服务器,查看所有安装的Gems包。

#访问地址:<a href="http://localhost:8808">http://localhost:8808</a>
标签:
>>原创文章,欢迎转载。转载请注明:转载自Ruby迷,谢谢!
>>原文链接地址:安装Rails 3.0
  1. tal-rasha
    十二 14th, 201116:22

    你好,我是刚刚接触ror,在创建应用时遇到如下错误,请帮忙看一下,谢啦
    D:\Program Files\wamp>rails new ruby
    create
    create README
    create Rakefile
    create config.ru
    create .gitignore
    create Gemfile
    create app
    create app/assets/images/rails.png
    create app/assets/javascripts/application.js
    create app/assets/stylesheets/application.css
    create app/controllers/application_controller.rb
    create app/helpers/application_helper.rb
    create app/mailers
    create app/models
    create app/views/layouts/application.html.erb
    create app/mailers/.gitkeep
    create app/models/.gitkeep
    create config
    create config/routes.rb
    create config/application.rb
    create config/environment.rb
    create config/environments
    create config/environments/development.rb
    create config/environments/production.rb
    create config/environments/test.rb
    create config/initializers
    create config/initializers/backtrace_silencers.rb
    create config/initializers/inflections.rb
    create config/initializers/mime_types.rb
    create config/initializers/secret_token.rb
    create config/initializers/session_store.rb
    create config/initializers/wrap_parameters.rb
    create config/locales
    create config/locales/en.yml
    create config/boot.rb
    create config/database.yml
    create db
    create db/seeds.rb
    create doc
    create doc/README_FOR_APP
    create lib
    create lib/tasks
    create lib/tasks/.gitkeep
    create lib/assets
    create lib/assets/.gitkeep
    create log
    create log/.gitkeep
    create public
    create public/404.html
    create public/422.html
    create public/500.html
    create public/favicon.ico
    create public/index.html
    create public/robots.txt
    create script
    create script/rails
    create test/fixtures
    create test/fixtures/.gitkeep
    create test/functional
    create test/functional/.gitkeep
    create test/integration
    create test/integration/.gitkeep
    create test/unit
    create test/unit/.gitkeep
    create test/performance/browsing_test.rb
    create test/test_helper.rb
    create tmp/cache
    create tmp/cache/assets
    create vendor/assets/stylesheets
    create vendor/assets/stylesheets/.gitkeep
    create vendor/plugins
    create vendor/plugins/.gitkeep
    run bundle install
    D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/generato
    rs/app_base.rb:232:in “’: No such file or directory – “”D:/Program Files/Ruby/b
    in/ruby.exe”" -rubygems “D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/bundler-
    1.0.21/bin/bundle” install (Errno::ENOENT)
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/r
    ails/generators/app_base.rb:232:in `bundle_command’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/r
    ails/generators/app_base.rb:236:in `run_bundle’
    from (eval):1:in `run_bundle’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /task.rb:22:in `run’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /invocation.rb:118:in `invoke_task’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /invocation.rb:124:in `block in invoke_all’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /invocation.rb:124:in `each’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /invocation.rb:124:in `map’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /invocation.rb:124:in `invoke_all’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /group.rb:226:in `dispatch’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor
    /base.rb:389:in `start’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/r
    ails/commands/application.rb:31:in `’
    from D:/Program Files/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:
    in `require’
    from D:/Program Files/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:
    in `require’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/r
    ails/cli.rb:15:in `’
    from D:/Program Files/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:
    in `require’
    from D:/Program Files/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:
    in `require’
    from D:/Program Files/Ruby/lib/ruby/gems/1.9.1/gems/rails-3.1.3/bin/rail
    s:7:in `’
    from D:/Program Files/Ruby/bin/rails:19:in `load’
    from D:/Program Files/Ruby/bin/rails:19:in `’

    • 老宋
      十二 15th, 201100:53

      你直接在cmd下输入ruby -v, gem -v, bundle -v如果有一个报错说明是没有添加环境变量,直接把ruby的bin目录添加到环境变量即可。如果还有问题我再帮你分析