macos heroku:找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5282251/
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
heroku: command not found
提问by Ian
This would appear to have been solved before in How do I use gems with Ubuntu?as well as in other answers but none of the solutions seem to work for me.
这似乎已经在我如何在 Ubuntu 中使用 gems之前解决了?以及其他答案,但似乎没有一个解决方案对我有用。
I am using Mac OSX 10.6
我使用的是 Mac OSX 10.6
I have installed heroku using bundler. The following shows my gem environment and my path - i have tried adding the folders listed in EXECUTABLE DIRECTORY and GEM PATHS to my $PATH but i always get command not found when i type heroku from within my rails project.
我已经使用 bundler 安装了 heroku。下面显示了我的 gem 环境和我的路径 - 我已经尝试将 EXECUTABLE DIRECTORY 和 GEM PATHS 中列出的文件夹添加到我的 $PATH 但我总是在我的 rails 项目中键入 heroku 时找不到命令。
$ bundle show heroku
/Library/Ruby/Gems/1.8/gems/heroku-1.18.3
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.1
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/iantinsley/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/iantinsley/bin:/usr/local/bin:/usr/bin
$ heroku
-bash: heroku: command not found
any help greatly appreciated
非常感谢任何帮助
采纳答案by matt
By default, rubygems on a mac installs executables into /usr/bin
rather than under the gem dir at /Library/Ruby/Gems
. However, these directories have different permissions:
默认情况下,mac 上的 rubygems 将可执行文件安装到/usr/bin
gem 目录中而不是在/Library/Ruby/Gems
. 但是,这些目录具有不同的权限:
~ $ ls -ld /usr/bin/ /Library/Ruby/Gems/
drwxrwxr-x 4 root admin 136 15 Nov 22:19 /Library/Ruby/Gems/
drwxr-xr-x 1085 root wheel 36890 11 Feb 22:57 /usr/bin/
so although they are both owned by root
, the gems directory is writable by anyone in the admin
group, and /usr/bin
isn't.
因此,尽管它们都归root
.gems所有,但是该admin
组中的任何人都可以写入 gems 目录,而/usr/bin
不能。
What seems to have happened here is bundler hasn't been able to install the heroku executable into /usr/bin
when it installed the gem, probably because of this permissions issue. This blog postsuggests this has been a problem with earlier versions of bundler on OSX.
这里似乎发生的事情是 bundler/usr/bin
在安装 gem 时无法将 heroku 可执行文件安装到其中,可能是因为这个权限问题。这篇博文表明这是 OSX 上早期版本的 bundler 的问题。
The executable that rubygems installs is notjust a copy of the heroku script from the bin directory of the gem (i.e. /Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin
). Instead it is a wrapper script generated by rubygems that first loads up rubygems to enable it to work it's magic on the ruby load path so that when the script itself is then called any require
statements are able to find the appropriate libraries.
该RubyGems的安装可执行文件是没有距离的宝石(即的bin目录中的Heroku脚本的副本/Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin
)。相反,它是一个由 rubygems 生成的包装脚本,它首先加载 rubygems 以使其能够在 ruby 加载路径上工作,这样当脚本本身被调用时,任何require
语句都能够找到适当的库。
This means that if you call the script directly, rubygems won't be loaded so the load path won't be set up right and, as you've seen, you'll get errors about missing dependencies. To demonstrate this, try running
这意味着如果您直接调用脚本,则不会加载 rubygems,因此不会正确设置加载路径,并且如您所见,您将收到有关缺少依赖项的错误。为了证明这一点,请尝试运行
$ ruby -rubygems /Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin/heroku
which runs the script but loads up rubygems first. This should (might - I don't know for certain) work.
它运行脚本但首先加载 rubygems。这应该(可能 - 我不确定)工作。
This is also why bundle exec heroku
works. Bundler sets up the load path as needed. Furthermore, doing this ensures the load path is set up to match your Gemfile.lock
file - indeed this is the point of bundler.
这也是为什么bundle exec heroku
有效。Bundler 根据需要设置加载路径。此外,这样做可确保将加载路径设置为与您的Gemfile.lock
文件相匹配- 这确实是捆绑程序的重点。
I wouldn't recommend adding anything to your $PATH
. As we've seen it doesn't work, but also you'll need to change it every time you upgrade to a newer version of the heroku gem.
我不建议在您的$PATH
. 正如我们所见,它不起作用,但每次升级到较新版本的 heroku gem 时,您都需要更改它。
I would also recommend against adding anything to your $RUBYLIB
variable either. Doing so may actually get the heroku command working, but the whole point of using rubygems and bundler is that they manage stuff like this for you.
我还建议不要向您的$RUBYLIB
变量添加任何内容。这样做实际上可能会使 heroku 命令起作用,但使用 rubygems 和 bundler 的全部意义在于它们为您管理这样的东西。
My first recommendation would be to use rvm. It's a very useful tool, and I think it'd be worth spending some time looking into it.
我的第一个建议是使用rvm。这是一个非常有用的工具,我认为值得花一些时间研究它。
If you're unable or unwilling to do that, then you probably need to reinstall the heroku gem, and check it gets installed correctly. First remove the existing gem with:
如果您不能或不愿意这样做,那么您可能需要重新安装 heroku gem,并检查它是否正确安装。首先使用以下命令删除现有的 gem:
$ sudo gem uninstall heroku
Then make sure you've got the latest version of bundler:
然后确保你有最新版本的 bundler:
$ sudo gem update bundler
Finally reinstall with
最后重新安装
$ bundle install
and it should ask for your password to install the executables into the right place. Note don'tuse sudo
here - see the link above for details.
它应该要求您输入密码以将可执行文件安装到正确的位置。请注意不要sudo
在此处使用- 有关详细信息,请参阅上面的链接。
回答by mu is too short
Try adding this to the end of your PATH
:
尝试将此添加到您的末尾PATH
:
/Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin
If that doesn't work, then ask Spotlight to find a file named "heroku" and add the appropriate directory to your PATH
. If you have some time and feel like being an old-school unix dude for a bit:
如果这不起作用,请让 Spotlight 查找名为“heroku”的文件并将适当的目录添加到您的PATH
. 如果你有一些时间并且想成为一个老派的 unix 花花公子:
$ cd /
$ ls -l $(find [A-Z]* -name heroku -not -type d -print)
You could also use Cinderellato set up your Ruby/PostgreSQL/MySQL/MongoDB/... environment. That will give you the latest versions of everything and set up your paths sensibly. I had some issues getting Cinderella going but it has been a lifesaver and it is very nice how it puts everything in ~/Developer/
rather than scattering everything all over the place.
您还可以使用Cinderella来设置您的 Ruby/PostgreSQL/MySQL/MongoDB/... 环境。这将为您提供所有内容的最新版本并明智地设置您的路径。我在让灰姑娘继续前进时遇到了一些问题,但它一直是我的救星,而且它把所有东西都放进去~/Developer/
而不是把所有东西都散落一地真是太好了。
回答by The Whiz of Oz
Fixed it by reinstalling the Heroku Toolbelt from http://toolbelt.heroku.com
通过从http://toolbelt.heroku.com重新安装 Heroku Toolbelt 来修复它
回答by Zephaniah Irvine
Uninstall and then reinstall it with the command below in sudo
works. I'm using macOS 10.14.
卸载然后使用下面的命令重新安装它sudo
。我使用的是 macOS 10.14。
curl https://cli-assets.heroku.com/install.sh | sh
curl https://cli-assets.heroku.com/install.sh | sh
I originally install it with homebrew but the command not fund
error always occurred. The reason could be that curl installation make setting up in the two directories mentioned in official document.
我最初用自制软件安装它,但command not fund
总是出现错误。原因可能是curl安装make设置在官方文档中提到的两个目录下。
To quickly setup into /usr/local/lib/heroku and /usr/local/bin/heroku, run this script (script requires sudo and not Windows compatible)
要快速设置到 /usr/local/lib/heroku 和 /usr/local/bin/heroku,请运行此脚本(脚本需要 sudo 而不是 Windows 兼容的)