heroku:找不到命令

发布于 2024-10-21 18:05:41 字数 1363 浏览 2 评论 0原文

这似乎已经在 How do I use gems with Ubuntu? 中解决了以及其他答案,但似乎没有一个解决方案对我有用。

我使用的是 Mac OSX 10.6

我已经使用捆绑器安装了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

非常感谢任何帮助

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.

I am using 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.

$ 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暮凉 2024-10-28 18:05:41

默认情况下,Mac 上的 ruby​​gems 将可执行文件安装到 /usr/bin 中,而不是在 /Library/Ruby/Gems 的 gem 目录下。但是,这些目录具有不同的权限:

~ $ 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/

因此,尽管它们均由 root 所有,但 gems 目录可由 admin 组中的任何人写入,而 /usr/ bin 不是。

这里发生的事情似乎是bundler在安装gem时无法将heroku可执行文件安装到/usr/bin中,可能是因为这个权限问题。 这篇博文表明这是一个OSX 上早期版本的捆绑程序存在问题。

rubygems 安装的可执行文件不仅仅是 gem 的 bin 目录中的 heroku 脚本的副本(即 /Library/Ruby/Gems/1.8/gems/heroku-1.18.3/ bin)。相反,它是由 ruby​​gems 生成的包装器脚本,首先加载 ruby​​gems 使其能够在 ruby​​ 加载路径上工作,这样当脚本本身被调用时,任何 require 语句都能够找到适当的图书馆。

这意味着,如果您直接调用脚本,则不会加载 ruby​​gems,因此加载路径将无法正确设置,并且如您所见,您将收到有关缺少依赖项的错误。为了演示这一点,请尝试运行

$ ruby -rubygems /Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin/heroku

该脚本,但首先加载 ruby​​gems。这应该(可能 - 我不确定)有效。

这也是 bundle exec heroku 起作用的原因。 Bundler 根据需要设置加载路径。此外,这样做可以确保加载路径设置为与您的 Gemfile.lock 文件相匹配 - 事实上,这就是捆绑程序的重点。

我不建议向您的 $PATH 添加任何内容。正如我们所见,它不起作用,而且每次升级到较新版本的 heroku gem 时,您都需要更改它。

我还建议不要向您的 $RUBYLIB 变量添加任何内容。这样做实际上可能会让 heroku 命令正常工作,但使用 ruby​​gems 和捆绑器的全部意义在于它们为您管理这样的东西。

我的第一个建议是使用 rvm。这是一个非常有用的工具,我认为值得花一些时间研究它。

如果您无法或不愿意这样做,那么您可能需要重新安装 heroku gem,并检查它是否安装正确。首先使用以下命令删除现有的 gem:

$ sudo gem uninstall heroku

然后确保您拥有最新版本的捆绑程序:

$ sudo gem update bundler

最后重新安装

$ bundle install

,它会要求您输入密码以将可执行文件安装到正确的位置。注意不要在此处使用sudo - 有关详细信息,请参阅上面的链接。

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:

~ $ 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.

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 post suggests this has been a problem with earlier versions of bundler on OSX.

The executable that rubygems installs is not just 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.

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

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

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.

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.

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.

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.

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:

$ sudo gem uninstall heroku

Then make sure you've got the latest version of 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't use sudo here - see the link above for details.

远昼 2024-10-28 18:05:41

尝试将其添加到您的 PATH 末尾:

/Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin

如果这不起作用,请让 Spotlight 查找名为“heroku”的文件并将适当的目录添加到您的 PATH 。如果你有时间并且想成为一名老派的 unix 花花公子:

$ cd /
$ ls -l $(find [A-Z]* -name heroku -not -type d -print)

你也可以使用 Cinderella 设置您的 Ruby/PostgreSQL/MySQL/MongoDB/... 环境。这将为您提供所有内容的最新版本并明智地设置您的路径。我在让 Cinderella 运行时遇到了一些问题,但它一直是我的救星,而且它把所有东西都放在 ~/Developer/ 中而不是将所有东西散落在各处,这非常好。

Try adding this to the end of your 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:

$ cd /
$ ls -l $(find [A-Z]* -name heroku -not -type d -print)

You could also use Cinderella to 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.

回眸一遍 2024-10-28 18:05:41

通过从 http://toolbelt.heroku.com 重新安装 Heroku Toolbelt 来修复此问题

Fixed it by reinstalling the Heroku Toolbelt from http://toolbelt.heroku.com

筱果果 2024-10-28 18:05:41

卸载并在 sudo 中使用以下命令重新安装它。我使用的是 macOS 10.14。

卷曲 https://cli-assets.heroku.com/install.sh | sh

我最初是用自制程序安装它的,但总是出现command notfund错误。原因可能是curl安装时在官方文档提到的两个目录中进行了设置。

要快速设置到 /usr/local/lib/heroku 和 /usr/local/bin/heroku,请运行此脚本(脚本需要 sudo 并且与 Windows 不兼容)

Uninstall and then reinstall it with the command below in sudo works. I'm using macOS 10.14.

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.

To quickly setup into /usr/local/lib/heroku and /usr/local/bin/heroku, run this script (script requires sudo and not Windows compatible)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文