Ruby-on-rails 已安装 Rails 但 rails 命令显示未安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1954015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:04:26  来源:igfitidea点击:

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

ruby-on-railsrubyrubygemsgem

提问by rgoytacaz

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

我使用的是 Ubuntu 9.10 Karmic Koala 和 Ruby 1.9.1。

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

我使用 安装了 Rails sudo gem install rails,它为我安装了所有库。

When I type railsin the terminal it says.

当我输入rails终端时,它说。

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

当前未安装程序“rails”。您可以输入以下命令安装它: 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?

我可以找到 rake,它在 rake1.9.1 下,但是找不到 Rails,有人能指出我正确的方向吗?

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?

编辑:ruby 的路径不是问题,问题是 rails 在哪里?我该如何执行?rails 不起作用,可执行文件在哪里?

采纳答案by TK.

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

正如其他人所说,这很可能是 bashrc/bash_profile 文件中的 PATH 变量问题。

You can learn how to change PATH..

您可以学习如何更改 PATH。.

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

您可以通过键入来获取当前的 PATH 变量 echo $PATH

回答by Kyle Clegg

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

如果您在安装 rails 后立即运行 rails 命令,则需要重新启动终端才能识别您的命令。

回答by JaapH

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

刚刚遇到同样的问题,只需将以下内容放入您的 .bashrc

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

回答by prayagupd

Assuming ruby-2.0.0-p247is installed, railsis located at following location.

假设ruby-2.0.0-p247已安装,rails位于以下位置。

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_profileshould already be containing following line, if not add.

[1].bash_profile应该已经包含以下行,如果没有添加。

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

[2].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

[3]重新加载~/.bashrc

$ source ~/.bashrc

And, it should work.

而且,它应该工作。

回答by HelloWorld

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

如果您正在运行 rbenv,则需要运行 rbenv rehash go 来访问 rails-api 命令。

回答by Anand Soni

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.

我认为这不是解决此问题的正确方法。但是我所做的是,我在我的可执行目录中创建了一个 rails.rb 文件,因为当我打开该目录文件时,该文件不在那里并放入以下内容。

#!/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?  then
  version = 
  ARGV.shift
end

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

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

然后我尝试rails s在我的项目及其作品中运行..

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

但在此之前,请确保可执行目录在您的路径中,就像我已经在我的机器中一样: /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 environmentcommand

根据 TK 所说,您可以使用gem environment命令获取可执行路径

回答by samaitra

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

我将以下几行添加到我的 .bashrc 文件中并且它起作用了。

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

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # 将 RVM作为函数加载到 shell 会话

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

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

回答by Michael Wales

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

gem应该将 rails 可执行脚本放置在与 ruby​​ 相同的位置。我会查看那里并确保权限设置正确并且它是可执行的。

回答by William Hu

If you are using rbenvdon't forget add

如果您正在使用rbenv不要忘记添加

eval "$(rbenv init -)"

into your .bash_profileor other start up scripts. run rbenv rehashis also needed.

进入您的.bash_profile或其他启动脚本。rbenv rehash还需要运行。

回答by osehgol

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

一个可能的解决方案是不维护两个不同的配置文件.bash_profile.bashrc

It's suggested in this excellent post on the difference between .bash_profileand .bashrcis to source .bashrcfrom your .bash_profilefile, then putting PATH and common settings in .bashrc.

它建议,有关的区别这个优秀的帖子.bash_profile,并.bashrc为源.bashrc从您的.bash_profile文件,然后将PATH,共同设置的.bashrc

Quoting,

引用,

add the following lines to .bash_profile:

将以下行添加到.bash_profile

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

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

end quote

结束报价