21

So I installed ruby, gems and rails - however whenever I type rails I get the rails: Command not found. error.

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)

 - 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

I attempted to go into where the whereis command told me rails was installed

whereis rails
rails: /usr/local/bin/rails

and execute rails from there, again , I got 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.

Drazion
  • 342
  • 1
  • 4
  • 12
  • Did you check execute permissions on the script? – Strelok Jul 28 '12 at 14:22
  • Did a check and here is what came out # cd /usr/local/bin # ls -l | grep rails rwxr-xr-x 1 ---- ---- 385 Jul 27 19:24 rails – Drazion Jul 28 '12 at 14:31
  • Not an answer to your query, but a solution to your problem might be to run the rails ready script. I use it whenever I setup a new machine and it's worked great for me. You can find it here https://github.com/joshfng/railsready – lyonsinbeta Jul 28 '12 at 15:14
  • 1
    Did you ran `rehash` in your shell? – arrowd Jul 29 '12 at 10:01
  • Yes, I ended up deleting and reinstalling everything - getting yaml errors (even though it too is installed) but it appears to be working now. No idea what changed – Drazion Jul 29 '12 at 13:00
  • Creating a symlink worked for me on Mac OS `sudo ln -s /Library/Ruby/Gems/1.8/bin/rails /usr/bin/rails` – Manish Apr 11 '13 at 12:35

6 Answers6

43

If you installed Rails only via Bundler, then rails will only be accessible if you run bundle exec rails.

A "naked" rails command will only exist if you gem install rails directly without Bundler.

Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
  • 1
    I've been wondering about this and just came across your answer. Thank you. – Elvn Apr 03 '15 at 15:06
  • thank you. people keep saying `gem install rails` but what if I don't want to install it globally? this makes sense as a way to execute a specific version of rails installed and managed via bundler w/ a project. – thedarklord47 Oct 07 '20 at 03:03
18

If you are using rbenv, it is possible you will need to run rbenv rehash after installing your dependencies for you rails application. 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:

Hope this helps!

domdambrogia
  • 2,054
  • 24
  • 31
3

If your app is running in production but can't find rails command on root then this might help:

run

script/rails c ENV

Instead of

rails 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.

arsaKasra
  • 179
  • 1
  • 3
  • 10
Muntasim
  • 6,689
  • 3
  • 46
  • 69
2

I'm certain that your problem was caused by gems in the other gem directory, here:

/root/.gem/ruby/1.9.1

So for future readers, look in your other GEM PATHS.

(And then if that's wrong I'll update this answer appropriately.)

fdsaas
  • 714
  • 4
  • 10
1

I just encountered this same problem under another scenario where I installed rails along with rvm on ubuntu-20.04.

I had to add the following line to my ~/.bashrc ( or `~/.profile')

# Where you installed rvm...
source ~/.rvm/scripts/rvm
Darren Hicks
  • 4,946
  • 1
  • 32
  • 35
0

Im not sure if all your gem files are located inside the ruby folder that was first installed, but if the gems are installed in a seperate directory, rails will not work. In my case, rails was installed in some .local directory which wasn't part of the path ruby was in. Once i removed this foreign directory, i ran gem install rails to reinstall all of the gems. This properly put all the gems inside the ruby folder and the problem was fixed.

Jack
  • 1