Windows のコマンドプロンプトで Railsが上手くインストールされません。解決策を教えてください。

OSはwindows10homeで、Rubyのバージョンは、"ruby 2.6.3p62 (2019-04-16 revision 67580)
[x64-mingw32]"で、gemのバージョンは、"3.0.3"です。  
RubyInstallerでは、Ruby+Devkit 2.6.3-1 (x64) からダウンロードしました。

実際にインストールした流れは、  
RubyInstallerからrubyをインストール→MSYS2で"1","2","3"キー入力  
です。

そこから、コマンドプロンプトで"gem install rails"を入力すると、

```

    Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, rack, rack-test, crass, mini_portile2, nokogiri, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, arel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, thor, method_source, railties, sprockets, sprockets-rails, rails after 377 seconds
    38 gems installed
    
```

最後の行がこのような文だったのでうまくいったと思ったのですが、その後"rails -v"コマンドを入力すると、

```

    Traceback (most recent call last):
            28: from C:/Ruby26-x64/bin/rails:23:in `<main>'
            27: from C:/Ruby26-x64/bin/rails:23:in `load'
            26: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-5.2.3/exe/rails:10:in `<top (required)>'
            25: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            24: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            23: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/cli.rb:12:in `<top (required)>'
            22: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            21: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            20: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/command.rb:9:in `<top (required)>'
            19: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            18: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            17: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:2:in `<top (required)>'
            16: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            15: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            14: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:8:in `<top (required)>'
            13: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            12: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            11: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/line_editor.rb:2:in `<top (required)>'
            10: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
             9: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
             8: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/line_editor/readline.rb:2:in `<top (required)>'
             7: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
             6: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
             5: from C:/Ruby26-x64/lib/ruby/site_ruby/readline.rb:8:in `<top (required)>'
             4: from C:/Ruby26-x64/lib/ruby/site_ruby/readline.rb:10:in `<module:Readline>'
             3: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
             2: from C:/Ruby26-x64/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
             1: from C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:17:in `<top (required)>'
    C:/Ruby26-x64/lib/ruby/site_ruby/rbreadline.rb:1097:in `<module:RbReadline>': HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directory (RuntimeError)
    
```

このようにエラーが出てしまいます。

しかし `set` コマンドを使って環境変数を調べると、`HOMEDRIVE` と `HOMEPATH` は共に存在しています。

どなたか解決策を教えてください。

追加で、MSYS2で"2"キーを入力すると、最初の文が以下のようになります。

```

       1 - MSYS2 base installation
       2 - MSYS2 system update (optional)
       3 - MSYS2 and MINGW development toolchain
    
    Which components shall be installed? If unsure press ENTER [] 3
    
    > sh -lc true
    mkdir: ディレクトリ `/c/Users/foo' を作成できません: Permission denied
    /c/Users/foo could not be created.
    Setting HOME to /tmp.
    MSYS2 seems to be properly installed
    Install MSYS2 and MINGW development toolchain ...
    
```
CC BY-SA 4.0
2019-06-03T11:09:17.233
55484
2019-06-05T18:17:55.590
2019-06-05T18:17:55.590
34550
34550
question
ruby-on-rails ruby rails-activerecord
railsが上手くインストールされません。初心者ですがどなたか教えてください。