0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

gemini cliがzsh: command not found: geminiで使えない時の対処法

Last updated at Posted at 2025-06-28

はじめに

Gemini CLIをnpmでインストールしたのに gemini: command not found と表示された場合の対処法について記録します。
本記事では、インストール先の確認からPATH設定まで、初心者にもわかりやすい手順で問題を解消します。
手順を実行するだけで、すぐに gemini コマンドが使えるようになります。

とりあえず実行したい人はnpxを使いましょう。

npx https://github.com/google-gemini/gemini-cli

環境と前提条件

  • **macOS 15.3.2
  • zsh 5.9(macOS標準、bashでも手順は類似だが記述はzsh中心)
  • Node.js 22 / npm 10
  • Gemini CLI v0.5.1npm global でインストール済み

補足: bashの場合は.bash_profile.bashrcに追記すれば同様に動作します。


問題の再現と原因調査

まず、通常どおりグローバルインストールを実行します。

$ npm install -g @google/gemini-cli
added 431 packages in 3s

123 packages are looking for funding

にもかかわらず、直後のコマンド実行でエラーが出ます。

$ gemini
zsh: command not found: gemini

1. インストール先を確認

npmのグローバルパスを事前にprefix$HOME/.npm-globalに変更している場合、バイナリは以下に配置されます。

$ ls $HOME/.npm-global/bin/
gemini  npm  npx …

geminiファイル自体は確かに存在します。

2. 現在のPATHを一覧表示

$ echo $PATH | tr ':' '\n'
/opt/homebrew/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

一覧に .npm-global/bin が含まれていない ことがわかります。このためシェルはgeminiを検出できず、command not foundを返します。原因はnpmのグローバルバイナリディレクトリが環境変数PATHに追加されていないことでした。


解決手順(zshの場合)

以下の三工程で問題を完全に解消します。

1. 一時的にPATHを通す

# 現シェル限定で追加
$ export PATH=$PATH:$HOME/.npm-global/bin

2. 恒久的に設定(.zshrcを更新)

  echo 'export PATH=$PATH:$HOME/.npm-global/bin' >> ~/.zshrc

補足: M1/M2 MacでHomebrewを/opt/homebrewに入れている場合でも手順は同じです。

3. 設定を反映して動作確認

# 新しいシェルを開くか source で再読込
$ source ~/.zshrc

# バイナリの場所を確認
$ which gemini
/Users/you/.npm-global/bin/gemini

# コマンドが動作するか確認
$ gemini

   █████████  ██████████ ██████   ██████ █████ ██████   █████ █████
  ███░░░░░███░░███░░░░░█░░██████ ██████ ░░███ ░░██████ ░░███ ░░███
 ███     ░░░  ░███  █ ░  ░███░█████░███  ░███  ░███░███ ░███  ░███
░███          ░██████    ░███░░███ ░███  ░███  ░███░░███░███  ░███
░███    █████ ░███░░█    ░███ ░░░  ░███  ░███  ░███ ░░██████  ░███
░░███  ░░███  ░███ ░   █ ░███      ░███  ░███  ░███  ░░█████  ░███
 ░░█████████  ██████████ █████     █████ █████ █████  ░░█████ █████
  ░░░░░░░░░  ░░░░░░░░░░ ░░░░░     ░░░░░ ░░░░░ ░░░░░    ░░░░░ ░░░░░


Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.

type geminiを使うとシェル組み込みのどのメカニズムで解決されたかも確認できます。bashならhash -rでハッシュテーブルをクリアしてからwhichを実行すると確実です。

注意: .profile.zprofileなど他の設定ファイルに同じ行が重複すると、後でPATHが意図せず上書きされる恐れがあります。追加は一か所のみにしましょう。


まとめ

  • npm install -gでインストールしたCLIが動かない多くの原因は、バイナリディレクトリがPATHに含まれていないこと。
  • export PATH=$PATH:$HOME/.npm-global/bin.zshrcへ追記し、source ~/.zshrcで再読込すれば解決。
  • 同様の手順は他のnpm製CLI(Firebase Tools, ESLintなど)にも応用可能。

これでgemini: command not found問題とはお別れです。快適なGemini CLIライフをお楽しみください。


参考リンク

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?