Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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. (Due to project constraints I can't use RVM, it's a long story.)

I created symlinks to both of these in /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:

bash: rails: command not found

which rails also returns:

/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:

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
like image 520
TrolliOlli Avatar asked Nov 01 '22 05:11

TrolliOlli


1 Answers

...As root I ran...

And, what path does root think Ruby is in? 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.

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. I'd try:

sudo /usr/local/bin/gem install rails

which should install Rails for the new version of Ruby.


  • SHELL PATH:
    • /sbin/
    • /bin
    • /usr/sbin
    • /usr/bin
    • /usr/local/bin

Notice the order that the path will be searched. /usr/bin is before /usr/local/bin. The purpose of /usr/local/bin is to provide a place for storing user-wide locally installed executables. 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.

Instead of what you're using, your /usr/local/bin should be before /usr/bin in your PATH definition. That will definitely cause different search behavior, especially for which, but it's not guaranteed to fix the problem you're seeing.

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.

which searches the path, so check to see if there is a rails command in /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.

like image 157
the Tin Man Avatar answered Nov 15 '22 05:11

the Tin Man