heroku: command not found
Solution 1
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.
Solution 2
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.
Ian
Updated on June 04, 2022Comments
-
Ian almost 2 years
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