29

I'm using Ubuntu 9.10 Karmic Koala and Ruby 1.9.1.

I installed Rails using sudo gem install rails, which installed all the libraries for me.

When I type rails in the terminal it says.

The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails rails: command not found

I can find rake, which is under rake1.9.1, but Rails is nowhere to be found, can someone point me in the right direction?

Edit: path to ruby isn't the problem, the problem is where is rails? how do I execute it? rails just doesn't work, where does the exectuable lives?

rgoytacaz
  • 293
  • 1
  • 3
  • 5
  • Did you update your PATH variable to include the bin directory of the rails install? – MarkPowell Dec 23 '09 at 17:03
  • no.. I didn't, where should I point to? I cannot find its executable. locate rails returns just links of documentation. – rgoytacaz Dec 23 '09 at 17:35
  • possible duplicate of [Rails keeps telling me that it's not currently installed](http://stackoverflow.com/questions/7788946/rails-keeps-telling-me-that-its-not-currently-installed) – Bo Persson Oct 31 '12 at 17:32
  • Sometimes we face this if we just cloned the app and bundle is remain to install, so just run $ bundle from app root dir will solve this issue. – S.Yadav Jun 01 '19 at 10:49

11 Answers11

22

As others say, this may very well be a PATH variable issue on your bashrc/bash_profile file.

You can learn how to change PATH..

You can get the current PATH variable by typing echo $PATH

TK.
  • 23,367
  • 19
  • 60
  • 72
  • 1
    it isnt a problem of putting the path there, it seems rails it not installed at all, how do I check if its really installed? whats its executable? where does it lives? – rgoytacaz Dec 23 '09 at 17:48
  • 22
    Run `gem environment` and you'll find `EXECUTABLE DIRECTORY`. – TK. Dec 23 '09 at 18:56
  • 4
    You ARE GREAT! THANKS TK! Thats exactly what I needed. It turns out that installing it through gem doesnt create a symlink. I created it and points it to the executable directory. working great – rgoytacaz Dec 23 '09 at 19:27
  • 1
    @rgoytacaz how do you create a symlink? – Hlung Sep 17 '12 at 10:09
  • 2
    @Hlung Use `sudo ln -s /usr/local/bin/rails /usr/bin/rails` or change it accordingly. – Pijusn Jun 17 '13 at 16:57
17

If you're running a rails command immediately after installing rails, you will need to restart your terminal before your commands will be recognized.

Kyle Clegg
  • 36,212
  • 26
  • 127
  • 138
  • 1
    Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead: http://stackoverflow.com/a/13149543/419 – Kev Oct 31 '12 at 00:29
  • 1
    Flagged. I'll be more careful about that. The answer may helpful to those that come across either post (like me), which is why I shared it. – Kyle Clegg Oct 31 '12 at 00:48
13

Just had the same issue just put the following in your .bashrc

PATH="${PATH}:/var/lib/gems/1.8/bin/"
Titouan de Bailleul
  • 12,622
  • 11
  • 60
  • 114
JaapH
  • 355
  • 2
  • 5
4

Assuming ruby-2.0.0-p247 is installed, rails is located at following location.

prayag@prayag$ ls -l ~/.rvm/gems/ruby-2.0.0-p247/bin/
total 60
-rwxr-xr-x 1 prayag prayag 484 Oct  2 00:20 cap
-rwxr-xr-x 1 prayag prayag 487 Oct  2 00:20 capify
-rwxr-xr-x 1 prayag prayag 475 Oct  1 21:13 erubis
-rwxr-xr-x 1 prayag prayag 469 Oct  1 21:13 rackup
-rwxr-xr-x 1 prayag prayag 480 Oct  1 21:18 rails
-rwxr-xr-x 1 prayag prayag 494 Oct  2 00:27 restclient
-rwxrwxr-x 1 prayag prayag 368 Oct  1 21:10 ruby_executable_hooks
-rwxr-xr-x 1 prayag prayag 467 Oct  2 00:27 sass
-rwxr-xr-x 1 prayag prayag 475 Oct  2 00:27 sass-convert
-rwxr-xr-x 1 prayag prayag 467 Oct  2 00:27 scss
-rwxr-xr-x 1 prayag prayag 487 Oct  1 21:20 sprockets
-rwxr-xr-x 1 prayag prayag 483 Oct  2 00:29 stripe-console
-rwxr-xr-x 1 prayag prayag 467 Oct  1 21:17 thor
-rwxr-xr-x 1 prayag prayag 467 Oct  1 21:20 tilt
-rwxr-xr-x 1 prayag prayag 474 Oct  1 21:16 tt

[1] .bash_profile should already be containing following line, if not add.

 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

[2] Add following line to the end of .bashrc.

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
PATH="${PATH}:${HOME}/.rvm/gems/ruby-2.0.0-p247/bin/"

[3] Reload ~/.bashrc

$ source ~/.bashrc

And, it should work.

prayagupd
  • 27,100
  • 10
  • 130
  • 179
2

If you’re running rbenv you’ll need to run rbenv rehash go get access to the rails-api command.

HelloWorld
  • 6,578
  • 6
  • 35
  • 35
1

I think this is not correct way to resolve this problem. But What I have done is, I have created a rails.rb file in my executable directory because when I open that directory file was not there and put the following content.

#!/usr/bin/env ruby_noexec_wrapper
#
# This file was generated by RubyGems.
#
# The application 'railties' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'railties', version
load Gem.bin_path('railties', 'rails', version)

then I try to run rails s in my project and its works..

But before this make sure that executable directory is in your path like I have already in my machine : /home/anand/.rvm/gems/ruby-1.9.3-p286/bin:/home/anand/.rvm/gems/ruby-1.9.3-p286@global/bin:/home/anand/.rvm/rubies/ruby-1.9.3-p286/bin:/home/anand/.rvm/bin

As per TK said you can get the executable path using gem environment command

Anand Soni
  • 5,930
  • 9
  • 48
  • 97
1

I added the following lines to my .bashrc file and it worked.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session as a function

PATH="${PATH}:${HOME}/.rvm/gems/ruby-1.9.3-p327/bin/"

samaitra
  • 694
  • 7
  • 7
1

gem should have placed the rails executable script in the same location as ruby's. I'd look in there and make sure the permissions are set correctly and it is executable.

Michael Wales
  • 9,480
  • 7
  • 26
  • 28
1

If you are using rbenv don't forget add

eval "$(rbenv init -)"

into your .bash_profile or other start up scripts. run rbenv rehash is also needed.

William Hu
  • 12,918
  • 8
  • 85
  • 98
0

A possible solution is to not maintain two different configuration files .bash_profile and .bashrc

It's suggested in this excellent post on the difference between .bash_profile and .bashrc is to source .bashrc from your .bash_profile file, then putting PATH and common settings in .bashrc.

Quoting,

add the following lines to .bash_profile:

if [ -f ~/.bashrc ]; then source ~/.bashrc fi

end quote

osehgol
  • 111
  • 1
  • 5
-1

You may want to include the path of Ruby/Jruby folder in your bashrc file. That would ensure that you are able to run it from anywhere. Don't forget to restart terminal or "source .bashrc" to reload variables in terminals.

Priyank
  • 13,663
  • 17
  • 69
  • 105
  • The problem isnt with ruby, ruby works great. But when running rails it says its not installed, although if I do gem list, it will properly show to me, rails 2.3.5 – rgoytacaz Dec 23 '09 at 17:37
  • I looked up the bin folder of my ruby installation. It has a "rails" file. If i rename that to anything else and try to run rails; it doesn't scaffold or create projects..instead says that rails is not installed do sudo apt-get install to install rails. But if I rename it back to rails; then it starts working. So I am pretty sure that as long as rails is installed properly and you have it in bin folder it should run. Maybe I haven't installed it as a gem plus I am using JRuby. – Priyank Dec 23 '09 at 18:37