新手问题 创建 Rails 新项目遇见问题

yangyangnote · 2016年10月23日 · 最后由 yangyangnote 回复于 2016年10月23日 · 2754 次阅读

@Rei @xiaoronglv

已经确定的

  • ruby 的版本是 2.3.1
  • gem 的版本是 2.6.6
  • rails 的版本是 5.0.0.1
  • RubyGems 下面的镜像只有 gems.ruby-china.org

已经做的

  • 创建了 rails 目录名字叫 projectrails
  • 移动到该目录下
  • 新创建 rails 项目
yydeMacBook-Air% mkdir projectsrails*
yydeMacBook-Air% cd projectsrails*
yydeMacBook-Air% rails new demo --skip-test-unit*

问题

  • 当出现 run bundle install 的并运行到 Using bundler 1.12.5 的时候问题出现了

Your user account isn't allowed to install to the system Rubygems. You can cancel this installation and run:

bundle install --path vendor/bundle

to install the gems into ./vendor/bundle/, or you can enter your password and install the bundled gems to Rubygems using sudo.

Password:

  • 当我按第一种要求按退出执行 bundle install --path vendor/bundle,报错说Could not locate Gemfile
  • 当我按第二种要求输入密码,又出现报错

Using mime-types 3.1 An error occurred while installing byebug (9.0.6), and Bundler cannot continue. Make sure that gem install byebug -v '9.0.6' succeeds before bundling. run bundle exec spring binstub --all bundler: command not found: spring Install missing gem executables with bundle install

总结

因为之前对后端程序不是很了解,所以到现在我不敢轻举妄动,因为盲点比较多,怕越弄越糊涂。希望高人指点。

  • 1.没权限的话,可能是你试用的是系统的 ruby 版本。 可以先安装 rvm,然后安装 ruby,再生成 rails 项目。详情见 wiki
  • 2、如果遇到 Make sure that gem install byebug -v '9.0.6' succeeds before bundling. 这种情况,一般是网络原因,你单独执行 gem install byebug -v '9.0.6', 成功后再执行 bundle install

权限问题。
另外,提示里已经给出解决方法了

to install the gems into ./vendor/bundle/, or you can enter your password and install the bundled gems to Rubygems using sudo.

我的习惯是每个 Ruby & Rails 项目的 gem 都 install 在这个项目的目录下而不是全局。 bundler 管理 Ruby Gem 小技巧

先 cd 到项目目录,再 bundle install --path vendor/bundle

@awking @awking @hww

  • 我又重新用 rvm 装了一遍 ruby(糊里糊涂的😇 ,应该是新装了),重新建了 rails,终于打出了 hello world.激动,因为原来弄 iOS 的时候 Xcode 用惯了,啥都不知道,现在在研究 controller 和 view,争取多做点东西。
  • 谢谢大家的帮助,继续努力💪
yangyangnote 关闭了讨论。 12月20日 08:17
需要 登录 后方可回复, 如果你还没有账号请 注册新账号