3

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

Community
  • 1
  • 1
Ian
  • 315
  • 1
  • 6
  • 13
  • Can you cut-n-paste the command _and output_ of whatever it is that is failing? :) – sarnold Mar 12 '11 at 11:42
  • Does `bundle exec heroku` work? – matt Mar 12 '11 at 21:52
  • Yes, bundle exec works fine which I can live with. Running heroku from the /Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin fails as dependencies are not getting loaded. I detailed all this in an 'answer' but someone deleted it - not sure why. – Ian Mar 13 '11 at 21:32
  • @user656510, Thanks for updating the post, excellent. Pity about your addendum being deleted. If you can edit your post to include the stack trace, that'd be useful. :) I'm going to guess you need to add some directories to your `RUBYLIB` environment variable (see the `ruby(1)` manpage for details) so that Ruby can find required packages, but without seeing the specific error message, it'll be hard to know if I'm on the right track. – sarnold Mar 14 '11 at 01:30

4 Answers4

3

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.

matt
  • 78,533
  • 8
  • 163
  • 197
  • Magnificent and comprehensive answer. You are correct, running ruby -rubygems /Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin/heroku works for me. I just learned a lot. I am familiar with RVM and use it at work but thought as i only have one environment i'd live without it. Next time i'll use it. For the time being i'll either reinstall or run it through bundle exec (I don't run _that_ many heroku commands for it to be an issue at the moment). – Ian Mar 15 '11 at 10:35
1

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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • I added /Library/Ruby/Gems/1.8/gems/heroku-1.18.3/bin to my path. This allowed me to run heroku but i got the following stack trace – Ian Mar 13 '11 at 09:11
  • @user656510: sarnold's comment about `RUBYLIB` sounds right. You should be able to edit the question to add the stacktrace, your answer probably got deleted because it was a question update rather than an answer. – mu is too short Mar 14 '11 at 07:55
0

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

The Whiz of Oz
  • 6,763
  • 9
  • 48
  • 85
0

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)

Zephaniah Irvine
  • 389
  • 2
  • 12