[英]“rails” command not found despite having Rails installed
I compiled and installed Ruby 2.2 from source to /usr/local/bin/ruby and /usr/local/bin/gem. 我从源代码编译并安装了Ruby 2.2到/ usr / local / bin / ruby和/ usr / local / bin / gem。 (Due to project constraints I can't use RVM, it's a long story.)
(由于项目限制,我不能使用RVM,这是一个很长的故事。)
I created symlinks to both of these in /usr/bin. 我在/ usr / bin中为这两个创建了符号链接。
As root I ran: 我根本跑了:
gem install rails
and got: 得到了:
Successfully installed rails-4.2.1
Parsing documentation for rails-4.2.1
Done installing documentation for rails after 0 seconds
1 gem installed
When I try to run Rails however, I get: 当我尝试运行Rails时,我得到:
bash: rails: command not found
which rails
also returns: which rails
还返回:
/usr/bin/which: no rails in (/sbin/:/bin:/usr/sbin:/usr/bin:/usr/local/bin)
My gem list is: 我的宝石列表是:
*** LOCAL GEMS ***
actionmailer (4.2.1)
actionpack (4.2.1)
actionview (4.2.1)
activejob (4.2.1)
activemodel (4.2.1)
activerecord (4.2.1)
activesupport (4.2.1)
arel (6.0.0)
bigdecimal (1.2.6)
builder (3.2.2)
bundler (1.9.4)
erubis (2.7.0)
globalid (0.3.5)
i18n (0.7.0)
io-console (0.4.3)
json (1.8.1)
loofah (2.0.1)
mail (2.6.3)
mime-types (2.5)
mini_portile (0.6.2)
minitest (5.4.3)
nokogiri (1.6.6.2)
power_assert (0.2.2)
psych (2.0.8)
rack (1.6.0)
rack-test (0.6.3)
rails (4.2.1)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.6)
rails-html-sanitizer (1.0.2)
railties (4.2.1)
rake (10.4.2)
rdoc (4.2.0)
sprockets (3.0.3)
sprockets-rails (2.2.4)
test-unit (3.0.8)
thor (0.19.1)
thread_safe (0.3.5)
tzinfo (1.2.2)
Additionally, my gems environment looks like this: 另外,我的gems环境如下所示:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.5
- RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.2.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /root/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.2.0
- /root/.gem/ruby/2.2.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /sbin/
- /bin
- /usr/sbin
- /usr/bin
- /usr/local/bin
...As root I ran...
......作为root我跑了...
And, what path does root think Ruby is in? 而且,Ruby认为Ruby的路径是什么? Odds are really good it thinks Ruby is in /usr/bin, not /usr/local/bin since that path, /usr/local/bin, is probably not in root's path.
赔率确实很好,它认为Ruby在/ usr / bin中, 而不是 / usr / local / bin,因为该路径/ usr / local / bin可能不在root的路径中。
You could either prepend /usr/local/bin:
to root's path temporarily, or you could use the gem
in /usr/local/bin, which will know where to put gem files for that version of Ruby. 你可以暂时将
/usr/local/bin:
到root的路径,或者你可以使用/ usr / local / bin中的gem
,它将知道在哪个版本的Ruby中放置gem文件。 I'd try: 我试试:
sudo /usr/local/bin/gem install rails
which should install Rails for the new version of Ruby. 应该为新版本的Ruby安装Rails。
Notice the order that the path will be searched. 请注意将搜索路径的顺序。
/usr/bin
is before /usr/local/bin
. /usr/bin
在/usr/local/bin
。 The purpose of /usr/local/bin
is to provide a place for storing user-wide locally installed executables. /usr/local/bin
的目的是为存储用户范围的本地安装的可执行文件提供一个位置。 Typically that is the place you install modified versions of executables when you want to override the default /usr/bin
executables' behavior, such as if you wanted a new Ruby to run on your machine. 通常,当您要覆盖默认的
/usr/bin
可执行文件的行为时,就是安装修改版本的可执行文件的位置,例如,如果您希望在计算机上运行新的Ruby。
Instead of what you're using, your /usr/local/bin
should be before /usr/bin
in your PATH definition. 您的
/usr/local/bin
应该位于PATH定义中的/usr/bin
之前,而不是您正在使用的内容。 That will definitely cause different search behavior, especially for which
, but it's not guaranteed to fix the problem you're seeing. 这肯定会导致不同的搜索行为,特别是对于
which
行为,但不能保证能够解决您所看到的问题。
gem install rails
would find the gem
in /usr/bin, not in /usr/local/bin and would install Rails into that same Ruby's path. gem install rails
会在/ usr / bin中找到gem
,而不是在/ usr / local / bin中,并将Rails安装到同一个Ruby的路径中。
which
searches the path, so check to see if there is a rails
command in /usr/bin: which
搜索路径,因此,请检查是否有rails
在/ usr / bin命令:
ls /usr/bin/rails
If it exists, you probably need to rebuild the hash used for fast searching. 如果存在,您可能需要重建用于快速搜索的哈希。 I think that'd be
rehash rails
but my memory is fuzzy on that one. 我认为那会
rehash rails
但我的记忆在那个方面很模糊。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.