over 1 year ago

问题现象
运行rails new suggestotron后,卡住

修改设置 Rails 生成的 Gemfile 中的默认gem 源默认

安装gawk

brew install gawk
输入命令
cd "$(gem environ | gawk '/- INSTALLATION DIR/{print $4}')"
cd ./gems/railties-5.0.0/lib/rails/generators/rails/app/templates/
vim Gemfile

修改模版中源的地址

source 'https://gems.ruby-china.org'

重新运行rails new suggestotron,结果还是卡住,查看生成的suggestotron目录中的Gemfile文件发现,地址没有改变,刚才修改的没有生效。说明改的地方不对。

确认修改模版生效

搜索了一下发现,有四处有Gemfile模版。逐一修改尝试,发现rails运行时用的模版配置是
.//.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/generators/rails/app/templates/Gemfile
.//.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/generators/rails/plugin/templates/Gemfile
.//.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/generators/rails/app/templates/Gemfile
.//.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/generators/rails/plugin/templates/Gemfile

居然多出来了一个版本,修改railties-5.0.0.1版本的模版配置后问题解决。
vim ~//.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/generators/rails/app/templates/Gemfile
修改源地址为source 'https://gems.ruby-china.org'

rails -v查看版本,不知道什么时候升级成5.0.0.1了,难怪之前的修改不生效。
Rails 5.0.0.1

因此我当前在用的Gemfile模版路径为
~/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/generators/rails/app/templates/Gemfile

再使用rails new 命令的时候,不会再被卡住了,哈哈!

← 1-2 require "active_support"失败 第二课 3-8 Topic.count报错 →
 
comments powered by Disqus