Ruby-on-rails Rails:成功安装后找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11701784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails: Command not Found after successful install
提问by Drazion
So I installed ruby, gems and rails - however whenever I type rails I get the rails: Command not found.error.
所以我安装了 ruby、gems 和 rails - 但是每当我输入 rails 时,我都会收到rails: Command not found.错误消息。
I did a dump of my local gems, which I'll include below
我转储了我的本地宝石,我将在下面列出
*** LOCAL GEMS ***
actionmailer (3.2.7)
actionpack (3.2.7)
activemodel (3.2.7)
activerecord (3.2.7)
activeresource (3.2.7)
activesupport (3.2.7)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.0)
bundler (1.1.5)
daemon_controller (1.0.0)
erubis (2.7.0)
fastthread (1.0.7)
hike (1.2.1)
i18n (0.6.0)
io-console (0.3)
journey (1.0.4)
json (1.5.4)
mail (2.4.4)
mime-types (1.19)
minitest (2.5.1)
multi_json (1.3.6)
mysql (2.8.1)
passenger (3.0.14)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.7)
railties (3.2.7)
rake (0.9.2.2)
rdoc (3.12, 3.9.4)
sprockets (2.1.3)
thor (0.15.4)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.33)
I also checked my gem environment setup (below)
我还检查了我的 gem 环境设置(如下)
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-freebsd8.1]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-freebsd-8
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.9.1
- /root/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
and echo'd my $PATH variable /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
并回显我的 $PATH 变量 /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
I attempted to go into where the whereis command told me rails was installed
我试图进入 whereis 命令告诉我 rails 的安装位置
whereis rails
rails: /usr/local/bin/rails
and execute rails from there, again , I got rails: Command not found.
并从那里执行 rails,再次,我得到了 rails: Command not found.
I am running FreeBSD on a VPS, and would like to learn some additional languages beyond PHP, but I can't seem to figure this one out for the life of me ... any help would be amazing.
我在 VPS 上运行 FreeBSD,并且想学习一些 PHP 以外的其他语言,但我似乎无法在我的生活中解决这个问题......任何帮助都会很棒。
采纳答案by Kevin Dickerson
I'm certain that your problem was caused by gems in the other gem directory, here:
我确定您的问题是由另一个 gem 目录中的 gems 引起的,这里:
/root/.gem/ruby/1.9.1
So for future readers, look in your other GEM PATHS.
因此,对于未来的读者,请查看您的其他GEM PATHS.
(And then if that's wrong I'll update this answer appropriately.)
(然后如果那是错误的,我会适当地更新这个答案。)
回答by Grant Birchmeier
If you installed Rails only via Bundler, then railswill only be accessible if you run bundle exec rails.
如果您仅通过 Bundler 安装 Rails,那么rails只有在您运行bundle exec rails.
A "naked" railscommand will only exist if you gem install railsdirectly without Bundler.
“裸”rails命令只有在您gem install rails直接没有 Bundler 时才会存在。
回答by Muntasim
If your app is running in production but can't find rails command on root then this might help:
如果您的应用程序正在生产中运行,但无法在 root 上找到 rails 命令,那么这可能会有所帮助:
run
跑
script/rails c ENV
脚本/导轨 c ENV
Instead of
代替
rails c ENV
导轨 c ENV
I had the same issue and resolved it this way. The app was running with nginx/passenger but wasn't able to run rails console/ rails server on production.
我遇到了同样的问题并以这种方式解决了它。该应用程序正在使用 nginx/passenger 运行,但无法在生产环境中运行 rails 控制台/rails 服务器。
回答by domdambrogia
If you are using rbenv, it is possible you will need to run rbenv rehashafter installing your dependencies for you rails application. ie. bundle install
如果您正在使用rbenv,则可能需要rbenv rehash在为 Rails 应用程序安装依赖项后运行。IE。bundle install
From digitalocean:
来自数字海洋:
Whenever you install a new version of Ruby or a gem that provides commands, you should run the rehash sub-command. This will install shims for all Ruby executables known to rbenv, which will allow you to use the executables:
每当您安装新版本的 Ruby 或提供命令的 gem 时,您都应该运行 rehash 子命令。这将为 rbenv 已知的所有 Ruby 可执行文件安装垫片,这将允许您使用这些可执行文件:
Hope this helps!
希望这可以帮助!

