6
2

More than 5 years have passed since last update.

何回やってもherokuコマンドがNo such file or directoryを吐く

Last updated at Posted at 2018-08-04

Rails Tutorial 1.5.1 Herokuのセットアップ

ローカルに開発環境を構築したいのでHeroku公式サイトに飛んでhomebrewを利用してダウンロード。
早速heroku --versionで正しくインストール出来たか確認してみる

heroku--versionが表示されない

-bash: /Users/ユーザー名/.rbenv/shims/heroku: No such file or directory

正しくは

heroku --version
heroku/7.0.0 (darwin-x64) node-v8.0.0

上記のように表示されるはずが、当然の如くエラーが出てくる。
herokuがどこにインストールされたかを確認すると

which heroku
/usr/local/bin/heroku

想定された場所にダウンロードされていたが、heroku --versionで参照している場所が違うので、公式より
The path to the heroku command should not be a Ruby gem directory.
If it is, uninstall it and any other heroku gems:
herokuへのpathがruby gemのディレクトリにあるのはおかしいので、以下のコマンドを実行してくれとのこと

gem uninstall heroku --all

それでもheroku --versionが表示されない

-bash: /Users/ユーザー名/.rbenv/shims/heroku: No such file or directory

公式では解決出来なかったので Heroku command not found を参考に、インストール後にpathを設定する必要があるとのことで

sudo ln -s /usr/local/heroku/bin/heroku /usr/bin/heroku

を実行すると

ln: /usr/bin/heroku: Operation not permitted

となりsudoコマンドをつけたにも関わらず拒否されたのでこちらもダメ。

それでもheroku --versionが表示されない

ググったら以下のコマンドを試してみなさいということで実行

brew link --overwrite heroku
Warning: Already linked: /usr/local/Cellar/heroku/7.7.8
To relink: brew unlink heroku && brew link heroku

すでにlinkされてるからこちらのコマンドを試せとのこと

 brew unlink heroku && brew link heroku

試してみたところ

Unlinking /usr/local/Cellar/heroku/7.7.8... 2 symlinks removed
Linking /usr/local/Cellar/heroku/7.7.8... 
Error: Could not symlink bin/heroku
Target /usr/local/bin/heroku
already exists. You may want to remove it:
  rm '/usr/local/bin/heroku'

To force the link and overwrite all conflicting files:
  brew link --overwrite heroku

To list all files that would be deleted:
  brew link --overwrite --dry-run heroku

さらにエラーが生じたので、terminalから提案されたコマンドを再び実行

それでもheroku --versionが表示されない

 rm '/usr/local/bin/heroku'
 brew link --overwrite heroku

二つとも実行した後で、heroku --versionを実行すると

-bash: /Users/ユーザー名/.rbenv/shims/heroku: No such file or directory

何の変更も受け付けてくれないのか!?ならもう消してしまえ!ということで
brewからherokuをuninstallし、macを再起動し、再びbrew installでherokuをインストールし直してheroku --version を試すと

-bash: /Users/ユーザー名/.rbenv/shims/heroku: No such file or directory

herokuを再インストールしてもheroku --versionが表示されない

This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile

改めてインストールしたところ、pathの設定を変更した方が良いと、terminalの提案に従ってechoコマンドを両方とも実行。
すると・・

-bash: /Users/ユーザー名/.rbenv/shims/heroku: No such file or directory

素晴らしい・・糠に釘とはまさにこのこと。
同様のケースに陥ってる例は残念ながら探すことが出来なかったので類似ケース+公式ヘルプを参考に試してみましたが何回やってもherokuが倒せません。

アイテム二号を使ったら無事に通過!

rubyメンターに解決案を尋ねたところ

sudo heroku --version

を試してみればどうかとのことで、早速実行すると

heroku/7.7.1 darwin-x64 node-v10.8.0

はい、無事に表示されました!
pathを通すコマンドがうまくいかなかった時にはsudoをつけて試す発想があったのに、これが思いつかなかったとは・・
不便ではありますがherokuコマンドの前にsudoをつけることで、全てのherokuコマンドがエラーを吐かずに正常に動作します。

参考サイト
heroku how to add $PATH inside heroku app
Operation Not Permitted when on root - El Capitan (rootless disabled
エアーマンが倒せない

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2