卸载了旧版本的rails,现在不再具有可执行的rails

时间:2020-11-30 00:19:39

Working in Nitrous.IO, my rails app was acting strange. So I checked and I was using rails version 0.9.5 instead of version 4.0.1! I decided to do a gem uninstall rails --version 0.9.5. Everything is good, except it also removed the rails executable! How do I get that back? Seems like version 4.0.1 is there, but I can't run the rails command. Should I just uninstall and reinstall rails?

在Nitrous.IO工作,我的rails应用程序表现得很奇怪。所以我查了一下,我使用的是rails版本0.9.5而不是版本4.0.1!我决定做一个gem uninstall rails --version 0.9.5。一切都很好,除了它还删除了可执行的rails!我该怎么回来?好像有4.0.1版本,但我无法运行rails命令。我应该卸载并重新安装rails吗?

UPDATE: Tried gem install rails even though I already had rails 4.0.1 installed:

更新:尝试gem安装rails,即使我已经安装了rails 4.0.1:

action@creativebox-45198:~$ gem install rails                                                                                                                                      
Successfully installed rails-4.0.1                                                                                                                                                 
1 gem installed                                                                                                                                                                    
action@creativebox-45198:~$ rails -v                                                                                                                                               
-bash: rails: command not found

3 个解决方案

#1


0  

This issue has been resolved through Nitrous support channels. Somehow the file /home/action/.rvm/gems/ruby-2.0.0-p247/bin/rails was missing, and gem install rails did not add it. Manually adding this file with the following contents solved the issue.

此问题已通过Nitrous支持渠道解决。不知何故,文件/home/action/.rvm/gems/ruby-2.0.0-p247/bin/rails丢失,并且gem install rails没有添加它。手动添加此文件以及以下内容解决了该问题。

#!/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
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/
    version = $1
    ARGV.shift
  end
end

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

#2


1  

Should be fine running gem install rails.

应该是精细运行gem安装rails。

#3


0  

Try hash rails if you're using Bash, or rehash rails for csh, at the command-line.

如果您在命令行使用Bash或重新使用rails for csh,请尝试使用哈希轨道。

Sometimes the shell loses track of where files are and (re)hash tells the shell to figure it out.

有时shell会丢失文件所在的位置,并且(重新)hash会告诉shell解决它。

Do a search for hash + shell or use man hash for more information.

搜索hash + shell或使用man hash获取更多信息。

#1


0  

This issue has been resolved through Nitrous support channels. Somehow the file /home/action/.rvm/gems/ruby-2.0.0-p247/bin/rails was missing, and gem install rails did not add it. Manually adding this file with the following contents solved the issue.

此问题已通过Nitrous支持渠道解决。不知何故,文件/home/action/.rvm/gems/ruby-2.0.0-p247/bin/rails丢失,并且gem install rails没有添加它。手动添加此文件以及以下内容解决了该问题。

#!/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
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/
    version = $1
    ARGV.shift
  end
end

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

#2


1  

Should be fine running gem install rails.

应该是精细运行gem安装rails。

#3


0  

Try hash rails if you're using Bash, or rehash rails for csh, at the command-line.

如果您在命令行使用Bash或重新使用rails for csh,请尝试使用哈希轨道。

Sometimes the shell loses track of where files are and (re)hash tells the shell to figure it out.

有时shell会丢失文件所在的位置,并且(重新)hash会告诉shell解决它。

Do a search for hash + shell or use man hash for more information.

搜索hash + shell或使用man hash获取更多信息。