简体   繁体   English

已安装 Rails 但 rails 命令显示未安装

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

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.我使用sudo gem install rails安装了 Rails,它为我安装了所有库。

When I type rails in the terminal it says.当我在终端中输入rails时,它说。

The program 'rails' is currently not installed.当前未安装程序“rails”。 You can install it by typing: sudo apt-get install rails rails: command not found您可以通过键入以下命令安装它: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?编辑:ruby 的路径不是问题,问题是 rails 在哪里? how do I execute it?我该如何执行它? rails just doesn't work, where does the exectuable lives? rails 根本不起作用,可执行文件在哪里?

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 您可以通过键入echo $PATH来获取当前的PATH变量

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

刚刚遇到同样的问题,只需在.bashrc中添加以下内容即可

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

Assuming ruby-2.0.0-p247 is installed, rails is 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_profile should 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下行添加到.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. 而且,它应该工作。

如果您正在运行rbenv,则需要运行rbenv rehash,以获取对rails-api命令的访问权限。

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? $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.. 然后我尝试在我的项目中运行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 : /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 根据TK说,您可以使用gem environment命令获取可执行文件路径

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 /宝石/红宝石1.9.3-P327 /斌/”

gem should have placed the rails executable script in the same location as ruby's. gem应该将rails可执行脚本放在与ruby相同的位置。 I'd look in there and make sure the permissions are set correctly and it is executable. 我会查看并确保权限设置正确且可执行。

If you are using rbenv don't forget add 如果您使用rbenv请不要忘记添加

eval "$(rbenv init -)"

into your .bash_profile or other start up scripts. 进入.bash_profile或其他启动脚本。 run rbenv rehash is also needed. 还需要运行rbenv rehash

A possible solution is to not maintain two different configuration files .bash_profile and .bashrc 一种可能的解决方案是不维护两个不同的配置文件.bash_profile.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 . 它在上的区别这个优秀的帖子建议.bash_profile.bashrc是采购.bashrc从你.bash_profile文件,然后将PATH,共同设置在.bashrc

Quoting, 引用,

add the following lines to .bash_profile : .bash_profile添加到.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 :我使用的是 macOS,就我而言,我需要将这一行添加到~/.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.我的ruby是brew安装的。

You may want to include the path of Ruby/Jruby folder in your bashrc file. 您可能希望在bashrc文件中包含Ruby / Jruby文件夹的路径。 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. 不要忘记重新启动终端或“source .bashrc”来重新加载终端中的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM