运行rails new命令时遇到错误
我想开始学习 Ruby on Rails。我已经通过 RVM 安装了 ruby 2.7.0。 ubuntu 20.04.3 LTS 中也默认安装了 SQLite3。我的 Rails 版本是 7.0.2.2。 命令时
rails new blog
当我运行本指南中的 : https://guides.rubyonrails.org/getting_started.html
它抛出一个错误:
lou@lou-VirtualBox:~$ rails new blog
create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create .gitattributes
create Gemfile
run git init from "."
Traceback (most recent call last):
27: from /home/lou/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
26: from /home/lou/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
25: from /home/lou/.rvm/gems/ruby-2.7.0/bin/rails:23:in `<main>'
24: from /home/lou/.rvm/gems/ruby-2.7.0/bin/rails:23:in `load'
23: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/exe/rails:10:in `<top (required)>'
22: from /home/lou/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
21: from /home/lou/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
20: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/cli.rb:18:in `<top (required)>'
19: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/command.rb:48:in `invoke'
18: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/command/base.rb:87:in `perform'
17: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
16: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
15: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
14: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/commands/application/application_command.rb:26:in `perform'
13: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
12: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
11: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
10: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
9: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
8: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
7: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
6: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
5: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:328:in `create_root_files'
4: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/app_base.rb:134:in `build'
3: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/app_base.rb:134:in `public_send'
2: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:76:in `version_control'
1: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:258:in `user_default_branch'
/home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:258:in ``': No such file or directory - git (Errno::ENOENT)
我可以找不到与我相关的问题,所以我希望有人能帮助我。
I want to start learning Ruby on Rails. I have installed ruby 2.7.0 via RVM. SQLite3 is also installed by default in ubuntu 20.04.3 LTS. My rails version is 7.0.2.2. When I run the command:
rails new blog
from this guide:
https://guides.rubyonrails.org/getting_started.html
It throws an error:
lou@lou-VirtualBox:~$ rails new blog
create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create .gitattributes
create Gemfile
run git init from "."
Traceback (most recent call last):
27: from /home/lou/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
26: from /home/lou/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
25: from /home/lou/.rvm/gems/ruby-2.7.0/bin/rails:23:in `<main>'
24: from /home/lou/.rvm/gems/ruby-2.7.0/bin/rails:23:in `load'
23: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/exe/rails:10:in `<top (required)>'
22: from /home/lou/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
21: from /home/lou/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
20: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/cli.rb:18:in `<top (required)>'
19: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/command.rb:48:in `invoke'
18: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/command/base.rb:87:in `perform'
17: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
16: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
15: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
14: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/commands/application/application_command.rb:26:in `perform'
13: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
12: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
11: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
10: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
9: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
8: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
7: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
6: from /home/lou/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
5: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:328:in `create_root_files'
4: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/app_base.rb:134:in `build'
3: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/app_base.rb:134:in `public_send'
2: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:76:in `version_control'
1: from /home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:258:in `user_default_branch'
/home/lou/.rvm/gems/ruby-2.7.0/gems/railties-7.0.2.2/lib/rails/generators/rails/app/app_generator.rb:258:in ``': No such file or directory - git (Errno::ENOENT)
I can't find issue related to mine, so I hope someone could help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决了我的问题。看来还需要安装git。
I solved my problem. It looks like it also needs git installed.
要解决此问题,请安装 git。
以下是一些背景信息:
Rails 尝试从“.”运行 git init 来初始化当前工作目录中的存储库。
Rails 读取 git默认分支,参见superuser.com 上关于默认分支的这篇文章。
在 git > 中配置 init.defaultBranch 参数2.28,您可以运行 git config --global init.defaultBranch main 。
不确定为什么要这样做,但您可以使用以下控制台选项跳过此步骤:
-G、[--skip-git]、[--no-skip-git]
-p、[--pretend]、[--no-pretend]
请参阅Rails 代码 并运行
rails new --help
以了解更多信息。To solve this, install
git
.Here's some background:
Rails tries to run
git init from "."
to initialize a repository in your current working directory.Rails reads the git default branch, see this post on superuser.com about the default branch.
To configure the init.defaultBranch parameter in git > 2.28, you can run
git config --global init.defaultBranch main
.Not sure why you would do it but you could skip this step by using these console options:
-G, [--skip-git], [--no-skip-git]
-p, [--pretend], [--no-pretend]
See Rails code and run
rails new --help
to learn more.