新手探路: ruby rails windows 简单安装及配置

时间:2021-01-26 05:54:31

纯属菜鸟自己记录为以后失忆症犯了的时候看看的:)刚开始接触ruby 所以从安装开始网上找了一些guide 自己也写一个自己的心得

首先比较简单的安装 ,安装包地址:https://www.ruby-lang.org/en/documentation/installation/#rubyinstaller   or    http://railsinstaller.org/en

 

我选的:

新手探路: ruby rails windows 简单安装及配置

 

下载安装一下一部没有特殊的这里省略了,中间忽略了一个ssh验证导致后来的gem不能使用(我想应该是这样的)。。。。。。下边就介绍一下如何解决:

 

错误:

C:\Users\IBM_ADMIN>rails new wjtest1
DL is deprecated, please use Fiddle
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      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/views/layouts/application.html.erb
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/secrets.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.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  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/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.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  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
         run  bundle install
DL is deprecated, please use Fiddle
Fetching gem metadata from https://rubygems.org/............
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...

Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read
server certificate B: certificate verify failed (https://rubygems.org/gems/rake-
10.4.2.gem)
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that `gem install rake -v '10.4.2'` succeeds before bundling.

C:\Users\IBM_ADMIN>
C:\Users\IBM_ADMIN>gem install rake -v '10.4.2'
ERROR:  Could not find a valid gem 'rake' (= 10.4.2), here is why:
          Unable to download data from https://rubygems.org/ - SSL_connect retur
ned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (
https://api.rubygems.org/specs.4.8.gz)

C:\Users\IBM_ADMIN>

解决方法:

https://gist.githubusercontent.com/raw/867550/win_fetch_cacerts.rb

我把它开背出来新建了一个同名文件放到桌面上

require 'net/http'

# create a path to the file "C:\RailsInstaller\cacert.pem"
cacert_file = File.join(%w{c: RailsInstaller cacert.pem})#可以根据自己的实际路径进行更改

Net::HTTP.start("curl.haxx.se") do |http|
  resp = http.get("/ca/cacert.pem")
  if resp.code == "200"
    open(cacert_file, "wb") { |file| file.write(resp.body) }
    puts "\n\nA bundle of certificate authorities has been installed to"
    puts "C:\\RailsInstaller\\cacert.pem\n"
    puts "* Please set SSL_CERT_FILE in your current command prompt session with:"
    puts "     set SSL_CERT_FILE=C:\\RailsInstaller\\cacert.pem"
    puts "* To make this a permanent setting, add it to Environment Variables"
    puts "  under Control Panel -> Advanced -> Environment Variables"
  else
    abort "\n\n>>>> A cacert.pem bundle could not be downloaded."
  end
end



C:\Users\IBM_ADMIN>ruby "%USERPROFILE%\Desktop\win_fetch_cacerts.rb"


A bundle of certificate authorities has been installed to
C:\RailsInstaller\cacert.pem
* Please set SSL_CERT_FILE in your current command prompt session with:
set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem
* To make this a permanent setting, add it to Environment Variables
under Control Panel -> Advanced -> Environment Variables

C:\Users\IBM_ADMIN> set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem

新手探路: ruby rails windows 简单安装及配置



新手探路: ruby rails windows 简单安装及配置新手探路: ruby rails windows 简单安装及配置

 

 

C:\Users\IBM_ADMIN>gem install rake -v '10.4.2'
Fetching: rake-10.4.2.gem (100%)
rake's executable "rake" conflicts with C:/RailsInstaller/Ruby2.1.0/bin/rake
Overwrite the executable? [yN]  y
Successfully installed rake-10.4.2
Parsing documentation for rake-10.4.2
Installing ri documentation for rake-10.4.2
Done installing documentation for rake after 2 seconds
1 gem installed

 

不过在后来的安装还是不稳定于是决定更换成国内的淘宝源:

C:\Users\IBM_ADMIN>gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources

 

C:\Users\IBM_ADMIN>gem sources
*** CURRENT SOURCES ***


C:\Users\IBM_ADMIN>gem source -l
*** CURRENT SOURCES *** 这两个命令都可以查看当前的源

C:\Users\IBM_ADMIN>gem sources --add https://ruby.taobao.org/ 也可以 gem source -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources

C:\Users\IBM_ADMIN\wjtest1>gem sources -u
source cache successfully updated


C:\Users\IBM_ADMIN>gem sources
*** CURRENT SOURCES ***

https://ruby.taobao.org/

C:\Users\IBM_ADMIN>

 

 

现在在重新试这创建之前的项目


C:\Users\IBM_ADMIN>rails new wjtest1
DL is deprecated, please use Fiddle
       exist
   identical  README.rdoc
   identical  Rakefile
   identical  config.ru
   identical  .gitignore
   identical  Gemfile
       exist  app
   identical  app/assets/javascripts/application.js
   identical  app/assets/stylesheets/application.css
   identical  app/controllers/application_controller.rb
   identical  app/helpers/application_helper.rb
   identical  app/views/layouts/application.html.erb
   identical  app/assets/images/.keep
   identical  app/mailers/.keep
   identical  app/models/.keep
   identical  app/controllers/concerns/.keep
   identical  app/models/concerns/.keep
       exist  bin
   identical  bin/bundle
   identical  bin/rails
   identical  bin/rake
       exist  config
   identical  config/routes.rb
   identical  config/application.rb
   identical  config/environment.rb
    conflict  config/secrets.yml
</config/secrets.yml? (enter "h" for help) [Ynaqdh] h
        Y - yes, overwrite
        n - no, do not overwrite
        a - all, overwrite this and all others
        q - quit, abort
        d - diff, show the differences between the old and the new
        h - help, show this help
</config/secrets.yml? (enter "h" for help) [Ynaqdh]

。。。。。。

最终项目创建成功在当前目录下了

启动server:

C:\Users\IBM_ADMIN\wjtest1> rails server
=> Booting WEBrick
=> Rails 4.1.8 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0
.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2015-12-07 18:24:51] INFO  WEBrick 1.3.1
[2015-12-07 18:24:51] INFO  ruby 2.1.5 (2014-11-13) [i386-mingw32]
[2015-12-07 18:24:51] INFO  WEBrick::HTTPServer#start: pid=14480 port=3000


Started GET "/" for 127.0.0.1 at 2015-12-07 18:25:07 +0800
Processing by Rails::WelcomeController#index as HTML
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.8/l
ib/rails/templates/rails/welcome/index.html.erb (15.6ms)
Completed 200 OK in 104ms (Views: 84.0ms | ActiveRecord: 0.0ms)
访问 http://localhost:3000/ 成功!说明已经安装成功并建立项目。

新手探路: ruby rails windows 简单安装及配置

 

http://ruby.taobao.org/