开发者

Installed Rails but the rails command says it's not installed

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?


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


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


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

PATH="${PATH}:/var/lib/gems/1.8/bin/"


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.


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


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.


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


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


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.


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


I am using macOS and in my case, I needed to add this line to ~/.zshrc:

export PATH="/usr/local/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/exe:$PATH"

It can be done like this:

echo 'export PATH="/usr/local/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/exe:$PATH"' >> ~/.zshrc

My ruby was installed by brew.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜