Windows 10 安装 Ruby on rails

2017-09-25 20:03:11来源:CSDN作者:u013366098人点击

分享

Windows 10 下安装 Ruby on rails

一、安装ruby
1.win下,建议使用RubyInstaller安装ruby环境 ,去ruby官网下载rubyinstaller安装。
参考链接:http://www.runoob.com/ruby/ruby-installation-windows.html
我是安装了Rubyinstaller 2.2.6 和DevKit
这里写图片描述
这里写图片描述
2.安装RubyInstaller完成后可搜索找到ruby 运行界面,点击打开即可在这里输入命令。
这里写图片描述

3.DevKit安装步骤:

1) 将下载 DevKit 解压到 D:/DevKit 目录。
2)CMD 进入 D:/DevKit 目录,输入ruby dk.rb init 。#生成config.yml,这里会检查将要添加DevKit支持的Ruby列表,只支持通过RubyInstaller安装的Ruby。
3) 输入 ruby dk.rb install 安装
4) 输入 ruby dk.rb review #检查要添加DevKit支持的Ruby列表是否有误,可以略过。
5) 输入 gem install rdiscount –platform=ruby 。#这一步只是验证DevKit是否安装成功,如果能安装rdiscount成功说明安装DevKit成功,也可以不做。

二、下载并安装Ruby Gems
从官方https://rubygems.org/pages/download
下载,以zip版本为例,解开压缩包,从CMD提示窗口下进入setup.rb所在目录, 运行 ruby setup.rb 即可安装。
新的Ruby版本已经包含RubyGems了,因此我们不用手动下载安装了。只需在CMD窗口输入指令:gem update –system ,耐心等待一段时间,已有的RubyGems会更新到目前最新的版本。我的是2.2.6版本的已经自带,只需
输入gem update –system升级即可,代码如下,中间部分省略。

D:/Ruby22-x64/myfile>gem update --systemUpdating rubygems-updateFetching: rubygems-update-2.6.13.gem (100%)Successfully installed rubygems-update-2.6.13Parsing documentation for rubygems-update-2.6.13Installing ri documentation for rubygems-update-2.6.13..............................................................................................If you do not wish to install this documentation in the future, use the--no-document flag, or set it as the default in your ~/.gemrc file. See'gem help env' for details.RubyGems system software updated

三、下载并安装Rails
输入gem install rails安装即可
代码如下:

D:/Ruby22-x64>gem install railsFetching: i18n-0.8.6.gem (100%)Successfully installed i18n-0.8.6Fetching: thread_safe-0.3.6.gem (100%)Successfully installed thread_safe-0.3.6Fetching: tzinfo-1.2.3.gem (100%)Successfully installed tzinfo-1.2.3Fetching: concurrent-ruby-1.0.5.gem (100%)Successfully installed concurrent-ruby-1.0.5Fetching: activesupport-5.1.4.gem (100%)Successfully installed activesupport-5.1.4Fetching: rack-2.0.3.gem (100%)Successfully installed rack-2.0.3Fetching: rack-test-0.7.0.gem (100%)Successfully installed rack-test-0.7.0Fetching: mini_portile2-2.3.0.gem (100%)Successfully installed mini_portile2-2.3.0Fetching: nokogiri-1.8.1-x64-mingw32.gem (100%)Nokogiri is built with the packaged libraries: libxml2-2.9.5, libxslt-1.1.30, zlib-1.2.11, libiconv-1.15.Successfully installed nokogiri-1.8.1-x64-mingw32Fetching: loofah-2.0.3.gem (100%)Successfully installed loofah-2.0.3Fetching: rails-html-sanitizer-1.0.3.gem (100%)Successfully installed rails-html-sanitizer-1.0.3Fetching: rails-dom-testing-2.0.3.gem (100%)Successfully installed rails-dom-testing-2.0.3Fetching: builder-3.2.3.gem (100%)Successfully installed builder-3.2.3Fetching: erubi-1.6.1.gem (100%)Successfully installed erubi-1.6.1Fetching: actionview-5.1.4.gem (100%)Successfully installed actionview-5.1.4Fetching: actionpack-5.1.4.gem (100%)Successfully installed actionpack-5.1.4Fetching: activemodel-5.1.4.gem (100%)Successfully installed activemodel-5.1.4Fetching: arel-8.0.0.gem (100%)Successfully installed arel-8.0.0Fetching: activerecord-5.1.4.gem (100%)Successfully installed activerecord-5.1.4Fetching: globalid-0.4.0.gem (100%)Successfully installed globalid-0.4.0Fetching: activejob-5.1.4.gem (100%)Successfully installed activejob-5.1.4Fetching: mime-types-data-3.2016.0521.gem (100%)Successfully installed mime-types-data-3.2016.0521Fetching: mime-types-3.1.gem (100%)Successfully installed mime-types-3.1Fetching: mail-2.6.6.gem (100%)Successfully installed mail-2.6.6Fetching: actionmailer-5.1.4.gem (100%)Successfully installed actionmailer-5.1.4Fetching: nio4r-2.1.0.gem (100%)Temporarily enhancing PATH to include DevKit...Building native extensions.  This could take a while...Successfully installed nio4r-2.1.0Fetching: websocket-extensions-0.1.2.gem (100%)Successfully installed websocket-extensions-0.1.2Fetching: websocket-driver-0.6.5.gem (100%)Building native extensions.  This could take a while...Successfully installed websocket-driver-0.6.5Fetching: actioncable-5.1.4.gem (100%)Successfully installed actioncable-5.1.4Fetching: thor-0.20.0.gem (100%)Successfully installed thor-0.20.0Fetching: method_source-0.8.2.gem (100%)Successfully installed method_source-0.8.2Fetching: railties-5.1.4.gem (100%)Successfully installed railties-5.1.4Fetching: bundler-1.15.4.gem (100%)Successfully installed bundler-1.15.4Fetching: sprockets-3.7.1.gem (100%)Successfully installed sprockets-3.7.1Fetching: sprockets-rails-3.2.1.gem (100%)Successfully installed sprockets-rails-3.2.1Fetching: rails-5.1.4.gem (100%)Successfully installed rails-5.1.4Parsing documentation for i18n-0.8.6Installing ri documentation for i18n-0.8.6Parsing documentation for thread_safe-0.3.6Installing ri documentation for thread_safe-0.3.6Parsing documentation for tzinfo-1.2.3Installing ri documentation for tzinfo-1.2.3Parsing documentation for concurrent-ruby-1.0.5Installing ri documentation for concurrent-ruby-1.0.5Parsing documentation for activesupport-5.1.4Installing ri documentation for activesupport-5.1.4Parsing documentation for rack-2.0.3Installing ri documentation for rack-2.0.3Parsing documentation for rack-test-0.7.0Installing ri documentation for rack-test-0.7.0Parsing documentation for mini_portile2-2.3.0Installing ri documentation for mini_portile2-2.3.0Parsing documentation for nokogiri-1.8.1-x64-mingw32Installing ri documentation for nokogiri-1.8.1-x64-mingw32Parsing documentation for loofah-2.0.3Installing ri documentation for loofah-2.0.3Parsing documentation for rails-html-sanitizer-1.0.3Installing ri documentation for rails-html-sanitizer-1.0.3Parsing documentation for rails-dom-testing-2.0.3Installing ri documentation for rails-dom-testing-2.0.3Parsing documentation for builder-3.2.3Installing ri documentation for builder-3.2.3Parsing documentation for erubi-1.6.1Installing ri documentation for erubi-1.6.1Parsing documentation for actionview-5.1.4Installing ri documentation for actionview-5.1.4Parsing documentation for actionpack-5.1.4Installing ri documentation for actionpack-5.1.4Parsing documentation for activemodel-5.1.4Installing ri documentation for activemodel-5.1.4Parsing documentation for arel-8.0.0Installing ri documentation for arel-8.0.0Parsing documentation for activerecord-5.1.4Installing ri documentation for activerecord-5.1.4Parsing documentation for globalid-0.4.0Installing ri documentation for globalid-0.4.0Parsing documentation for activejob-5.1.4Installing ri documentation for activejob-5.1.4Parsing documentation for mime-types-data-3.2016.0521Installing ri documentation for mime-types-data-3.2016.0521Parsing documentation for mime-types-3.1Installing ri documentation for mime-types-3.1Parsing documentation for mail-2.6.6Installing ri documentation for mail-2.6.6Parsing documentation for actionmailer-5.1.4Installing ri documentation for actionmailer-5.1.4Parsing documentation for nio4r-2.1.0Installing ri documentation for nio4r-2.1.0Parsing documentation for websocket-extensions-0.1.2Installing ri documentation for websocket-extensions-0.1.2Parsing documentation for websocket-driver-0.6.5Installing ri documentation for websocket-driver-0.6.5Parsing documentation for actioncable-5.1.4Installing ri documentation for actioncable-5.1.4Parsing documentation for thor-0.20.0Installing ri documentation for thor-0.20.0Parsing documentation for method_source-0.8.2Installing ri documentation for method_source-0.8.2Parsing documentation for railties-5.1.4Installing ri documentation for railties-5.1.4Parsing documentation for bundler-1.15.4Installing ri documentation for bundler-1.15.4Parsing documentation for sprockets-3.7.1Installing ri documentation for sprockets-3.7.1Parsing documentation for sprockets-rails-3.2.1Installing ri documentation for sprockets-rails-3.2.1Parsing documentation for rails-5.1.4Installing ri documentation for rails-5.1.4Done installing documentation for i18n, thread_safe, tzinfo, concurrent-ruby, activesupport, rack, rack-test, mini_portile2, nokogiri, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, arel, activerecord, globalid, activejob, mime-types-data, mime-types, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, thor, method_source, railties, bundler, sprockets, sprockets-rails, rails after 71 seconds36 gems installed

四、创建项目
进入你想把项目放置的目录,我是进入D盘
1.输入指令:rails new my-rbpro,会在D盘创建名称为my-rbpro的rails项目结构。

D:/>rails new my-rb-pro      create      create  README.md      create  Rakefile      create  config.ru      create  .gitignore      create  Gemfile         run  git init from "."      create  app      create  app/assets/config/manifest.js      create  app/assets/javascripts/application.js      create  app/assets/javascripts/cable.js      create  app/assets/stylesheets/application.css      create  app/channels/application_cable/channel.rb      create  app/channels/application_cable/connection.rb      create  app/controllers/application_controller.rb      create  app/helpers/application_helper.rb      create  app/jobs/application_job.rb      create  app/mailers/application_mailer.rb      create  app/models/application_record.rb      create  app/views/layouts/application.html.erb      create  app/views/layouts/mailer.html.erb      create  app/views/layouts/mailer.text.erb      create  app/assets/images/.keep      create  app/assets/javascripts/channels      create  app/assets/javascripts/channels/.keep      create  app/controllers/concerns/.keep      create  app/models/concerns/.keep      create  bin      create  bin/bundle      create  bin/rails      create  bin/rake      create  bin/setup      create  bin/update      create  bin/yarn      create  config      create  config/routes.rb      create  config/application.rb      create  config/environment.rb      create  config/secrets.yml      create  config/cable.yml      create  config/puma.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/application_controller_renderer.rb      create  config/initializers/assets.rb      create  config/initializers/backtrace_silencers.rb      create  config/initializers/cookies_serializer.rb      create  config/initializers/cors.rb      create  config/initializers/filter_parameter_logging.rb      create  config/initializers/inflections.rb      create  config/initializers/mime_types.rb      create  config/initializers/new_framework_defaults_5_1.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  lib      create  lib/tasks      create  lib/tasks/.keep      create  lib/assets      create  lib/assets/.keep      create  log      create  log/.keep      create  public      create  public/404.html      create  public/422.html      create  public/500.html      create  public/apple-touch-icon-precomposed.png      create  public/apple-touch-icon.png      create  public/favicon.ico      create  public/robots.txt      create  test/fixtures      create  test/fixtures/.keep      create  test/fixtures/files      create  test/fixtures/files/.keep      create  test/controllers      create  test/controllers/.keep      create  test/mailers      create  test/mailers/.keep      create  test/models      create  test/models/.keep      create  test/helpers      create  test/helpers/.keep      create  test/integration      create  test/integration/.keep      create  test/test_helper.rb      create  test/system      create  test/system/.keep      create  test/application_system_test_case.rb      create  tmp      create  tmp/.keep      create  tmp/cache      create  tmp/cache/assets      create  vendor      create  vendor/.keep      create  package.json      remove  config/initializers/cors.rb      remove  config/initializers/new_framework_defaults_5_1.rb         run  bundle install

但是rails new 新建rails项目时,老是卡在bundle install那里,这是因为rails new时自动会运行bundle install,而bundle install会自动去rubygems.org查找是否有更新。所以用如下指令

1   rails new my-rbpro --skip-bundle2   cd my-rbpro3   bundle install --local

我的出现提示“Could not find gem ‘sqlite3 x64-mingw32’ in any of the gem sources listed in your Gemfile.”是因为没有安装sqlite3,输入gem install sqlite3-ruby安装。

D:/my_app>bundle install --localCould not find gem 'sqlite3 x64-mingw32' in any of the gem sources listed inyour Gemfile.D:/my_app>gem install sqlite3-rubyFetching: sqlite3-1.3.13-x64-mingw32.gem (100%)Fetching: sqlite3-1.3.13-x64-mingw32.gemSuccessfully installed sqlite3-1.3.13-x64-mingw32Fetching: sqlite3-ruby-1.3.3.gem (100%)#######################################################Hello! The sqlite3-ruby gem has changed it's name to just sqlite3.  Rather thaninstalling `sqlite3-ruby`, you should install `sqlite3`.  Please update yourdependencies accordingly.Thanks from the Ruby sqlite3 team!<3 <3 <3 <3#######################################################Successfully installed sqlite3-ruby-1.3.3Parsing documentation for sqlite3-1.3.13-x64-mingw32Installing ri documentation for sqlite3-1.3.13-x64-mingw32Parsing documentation for sqlite3-ruby-1.3.3Installing ri documentation for sqlite3-ruby-1.3.3Done installing documentation for sqlite3, sqlite3-ruby after 1 seconds2 gems installed

再次运行bundle install –local又出现Could not find gem ‘puma (~> 3.7) x64-mingw32’ in any of the gem sources listed,这个待解决。
in your Gemfile.

2.接着进入www目录,输入指令:rails server ,启动rails自带的 webrick 服务器。还是出现Could not find gem ‘puma (~> 3.7) x64-mingw32’ in any of the gem sources listed in your Gemfile.
Run bundle install to install missing gems.

。。。。。放弃,不建议在win上折腾 很多东西忘了

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台