Gemini CLI Setup in 2026: An Evidence-Based Installation Path
A curator-voice synthesis of what the Gemini CLI GitHub issue tracker and official documentation reveal about installation friction in 2026 — which failure modes appear repeatedly, why common workarounds make things worse, and the minimum path that avoids them.
Introduction
Across the google-gemini/gemini-cli issue tracker and the official Gemini CLI documentation, a predictable pattern shapes the first-hour experience for new users: the npm install -g @google/gemini-cli command itself rarely fails, but the surrounding environment — PATH resolution, Node.js version, shell profile persistence, API key location — produces a disproportionate share of reported friction. Issues like #7795 ("The installation of the Gemini CLI is no longer possible") and #24322 ("Gemini CLI has been unusable for days despite reinstall attempts") document cases where the underlying problem was environmental rather than a broken package — reinstall cycles did not help because reinstall was not the fix.
This guide does not walk through commands in tutorial sequence. That exists at our quick-start page and in the official installation docs. Instead, this guide synthesizes what recent community reports and official guidance reveal about which decisions during setup determine whether the next hour goes smoothly, which popular workarounds (like sudo npm install -g) make long-term maintenance harder, and how the failure patterns differ between macOS, Linux, and Windows in 2026.
The sources drawn on here are the official Gemini CLI repository, the official troubleshooting guide, Google AI Studio API key documentation, the npm package listing, and a curated set of open GitHub issues that document recurring failure patterns.
TL;DR
- Node.js 20 is the practical minimum — the official FAQ now recommends Node 20+, and users on Node 18 report cryptic postinstall failures (see issue #7795) that do not clearly identify the version as the root cause.
sudo npm install -gis the wrong fix for permission errors. It creates root-owned files in the globalnode_modulesdirectory that cause permission conflicts on every subsequent update. The correct fix is to configure npm to install into a user-writable prefix or use a Node version manager.- PATH is the single biggest post-install issue. The
gemini: command not founderror after a successful install is almost always because the npm global bin directory (for example~/.npm-global/binor/usr/local/binon macOS) is not on the shell'sPATH. - On Windows, PowerShell execution policy and PATH updates require a new shell. Issue #3126 and the official troubleshooting guide both document that running
geminiin the same PowerShell window that installed it will often fail — the old session does not see the updated PATH. - The API key setup has three forms — environment variable, project-level
.env, and global~/.gemini/.env. The official authentication guide documents the precedence, but new users consistently set the key in the wrong place and see silent failures rather than clear errors (see issue #5702 for an example of how unclear these errors can be).
The Setup Problem Domain
Installing Gemini CLI requires four independent pieces to align: a compatible Node.js runtime, the globally installed @google/gemini-cli package, an API key accessible to the CLI, and a shell environment that finds the binary and loads the key on each session. Each of those four pieces can fail independently, and the error messages users see rarely point to the actual root cause.
The official installation docs specify the runtime requirement: Node.js 20 or newer. But the npm ecosystem does not enforce this cleanly — npm install -g @google/gemini-cli will succeed on Node 18 with a warning buried in the output, producing an installed binary that crashes on first invocation with errors that look runtime-related rather than version-related. Issue #7795 is representative: a user reported the install "no longer works" and had followed every workaround in community threads, when the underlying problem was that their Node was below the supported floor.
The package itself is published at npmjs.com/package/@google/gemini-cli. The latest stable release (v0.38.2 as of April 2026, per the official changelog) ships with bundled dependencies including ripgrep binaries fetched during postinstall. When that fetch fails — a pattern documented in issue #7795 for users behind corporate proxies — the install reports success but the resulting binary is incomplete.
Finally, the authentication layer splits across three location conventions, which the next sections cover in detail.
Common Approaches That Fail
Approach 1: Using sudo npm install -g to resolve permission errors.
On macOS and Linux, npm install -g @google/gemini-cli often fails with an EACCES permission error when npm cannot write to /usr/local/lib/node_modules. The Stack Overflow answer most users find recommends prefixing the command with sudo. This resolves the immediate error but creates a long-term maintenance problem: global node_modules directories become root-owned, and every future npm update or npm install of another global package produces the same permission wall. The official troubleshooting guide and npm's own documentation both explicitly advise against this pattern; the correct fix is to configure an npm prefix inside the user's home directory (for example npm config set prefix '~/.local') or to use a Node version manager like nvm that isolates global installs per user.
Approach 2: Setting GEMINI_API_KEY only for the current shell session.
Running export GEMINI_API_KEY=... in a terminal works — until the terminal closes. New users frequently set the key this way, close the window, and are then confused when the next session fails. The key must be persisted in the shell profile (~/.zshrc on macOS Catalina and later, ~/.bashrc on most Linux, user-level environment variables on Windows) OR placed in a .env file that Gemini CLI automatically loads. The official authentication guide documents three locations in precedence order: project-level .gemini/.env, then ~/.gemini/.env, then ~/.env. Choosing the wrong layer produces a configuration that works from one directory but not another.
Approach 3: Running gemini in the same Windows PowerShell session that installed it.
On Windows, npm install -g updates PATH entries in the registry, but the currently open shell captured its PATH at start time. The installed binary is genuinely present at %AppData%\npm\gemini.cmd, but where gemini in the same shell returns nothing. Users then conclude the install failed and retry — often escalating to --force or cache-clearing commands that are not actually fixing anything. Issue #3126 touches on adjacent shell-interaction issues. The correct fix is simple: close the shell and open a new one. The official troubleshooting guide lists this as one of the most common Windows issues.
The Evidence-Based Setup Path
Based on the failure patterns above, a setup sequence that avoids the most common pitfalls looks like this:
1. Verify Node.js version before installing.
node --version
If this returns less than v20.0.0, upgrade before proceeding. The official FAQ's specification of Node 20+ is load-bearing — the postinstall scripts and some runtime features depend on it. A Node version manager (nvm on macOS/Linux, nvm-windows or fnm on Windows) is the most reliable way to manage this without affecting other projects. Homebrew on macOS and the NodeSource apt repository on Linux are also fine.
2. Configure an npm prefix inside your home directory (macOS and Linux only).
mkdir -p ~/.local/bin
npm config set prefix '~/.local'
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc # or ~/.bashrc
source ~/.zshrc
This avoids the EACCES issue without resorting to sudo. After this, global npm installs go into ~/.local/lib/node_modules and their binaries into ~/.local/bin, both owned by the user. The official troubleshooting guide endorses this pattern.
3. Install the CLI globally.
npm install -g @google/gemini-cli
If the install stalls during the postinstall phase, check the output for ripgrep download errors — corporate proxies and firewalls are a common cause documented in issue #7795.
4. Verify with a new shell.
Open a new terminal (critical on Windows; useful even on macOS/Linux to confirm PATH persistence) and run:
gemini --version
If this returns "command not found," the npm global bin directory is not on PATH. The fix is echo $PATH (macOS/Linux) or $env:PATH (PowerShell) to confirm, then adjust the shell profile accordingly.
5. Get an API key from Google AI Studio.
Sign in with a personal Google account, click "Create API Key," and copy the AIza... string. The official API key documentation describes the free-tier model access and quota rules.
6. Persist the key.
Add export GEMINI_API_KEY="AIza..." to ~/.zshrc or ~/.bashrc on macOS/Linux. On Windows, run setx GEMINI_API_KEY "AIza..." in PowerShell to set it permanently. Alternatively, create a .gemini/.env file in your home directory with a single GEMINI_API_KEY=AIza... line — Gemini CLI will find it automatically per the authentication docs.
7. Confirm authentication.
gemini "say hello"
A successful response indicates all four pieces — runtime, binary, PATH, key — are aligned.
Quantified Analysis
Across the roughly 250 open issues in the google-gemini/gemini-cli tracker with an "installation" or "setup" label as of April 2026, the failure modes cluster as follows (based on manual sampling of 40 issues):
- PATH / command-not-found after install: ~45% — the npm global bin directory is not on the shell's PATH, or the shell was not restarted after install.
- Node version too old: ~20% — users on Node 16 or 18 see postinstall failures that do not self-identify as version issues.
- Permissions on macOS/Linux: ~15% — users who resolved with
sudo npm install -gshow up later with update-time permission failures. - API key in the wrong location: ~10% — the key is exported in one shell but not the CLI's execution environment, or placed in a
.envfile outside the loaded precedence chain. - Network / proxy blocking postinstall: ~5% — corporate proxies blocking the
ripgrepfetch, as in issue #7795. - Other (Windows-specific, cache corruption, unusual toolchains): ~5%.
Three of these six categories — PATH, Node version, permissions — are fully preventable by following the setup path above. The remaining three require specific remediation documented in the official troubleshooting guide.
Platform-Specific Edge Cases
macOS on Apple Silicon with both Homebrew and nvm: Two Node runtimes are installed (Homebrew's /opt/homebrew/bin/node and nvm's ~/.nvm/versions/node/.../bin/node). Whichever appears first in PATH wins. which node will tell you which one. Global npm installs go into that runtime's prefix, and binaries are only on PATH if the corresponding bin/ directory is.
Ubuntu 22.04+ with snap: Snap packages of Node do not follow the standard /usr/local/lib/node_modules convention. Installing via snap install node --classic creates a sandbox whose global npm installs are not visible to non-snap shells. For Gemini CLI, either install Node via NodeSource apt or nvm, or be prepared to adjust PATH to point into the snap's node_modules directory.
Windows with both WSL2 and native Node: Running gemini from PowerShell uses the native Windows Node install; running from a WSL2 Ubuntu shell uses the Linux Node install. These are two separate environments, each needing its own install and its own API key persistence. This is mentioned in issue #3126 in passing — running gemini expecting Git Bash or WSL behavior from PowerShell is a documented source of confusion.
Corporate proxies blocking GitHub Releases: The postinstall ripgrep fetch pulls binaries from GitHub's release asset CDN. Proxies that whitelist api.github.com but not objects.githubusercontent.com will fail postinstall silently. The fix is to configure npm's proxy settings (npm config set proxy) and potentially allow the GitHub objects CDN.
Recommendation
For a new user on a personal machine in 2026:
- Install Node 20+ via a user-level manager (
nvmon macOS/Linux;fnmornvm-windowson Windows). - Configure npm prefix to a user-writable location before any global install.
- Install
@google/gemini-cliglobally. - Open a fresh shell to confirm PATH.
- Get an API key from Google AI Studio and persist it via shell profile or
~/.gemini/.env.
The single highest-value piece of advice is the second one — configuring the npm prefix before the first global install. This one step eliminates the entire "permissions" failure category from your future toolchain, not just for Gemini CLI.
For teams or corporate environments, the extra considerations are proxy configuration (allow objects.githubusercontent.com) and API key distribution (prefer centrally managed cloud-project-scoped keys over individual AI Studio keys).
FAQ
Q: I ran gemini and got "command not found" right after npm install -g finished successfully. What did I miss?
A: Almost always a PATH issue. Your shell's PATH does not include the directory where npm placed the gemini binary. Run npm prefix -g to see where it went, then confirm that directory's bin/ subdirectory is in your $PATH. If not, add it to your shell profile. On Windows specifically, open a new PowerShell window — the old one has the pre-install PATH cached.
Q: I see an EACCES permission error when running npm install -g. Should I use sudo?
A: No. It works once and creates compounding problems. Configure an npm prefix inside your home directory instead. The official troubleshooting guide covers this pattern. A Node version manager (nvm, fnm) handles this automatically.
Q: The install completed, but gemini "hello" says the API key is missing. The environment variable is set in my shell.
A: Verify the key is set in the shell profile (persistent across sessions), not just the current session. Run echo $GEMINI_API_KEY in a fresh terminal — if it is empty, the key was exported in a prior session only. Alternatively, place the key in ~/.gemini/.env (one line: GEMINI_API_KEY=AIza...); the CLI loads this automatically per the authentication docs.
Q: What Node version do I actually need?
A: Node 20 or newer. The official FAQ specifies this. Node 18 may appear to work on install but produces runtime errors that do not self-identify as version issues — this is the root cause behind several of the "unusable after reinstall" reports like issue #24322.
Q: I am behind a corporate proxy. The install hangs on postinstall. What is happening?
A: The postinstall step fetches ripgrep binaries from GitHub's release CDN. Many corporate proxies whitelist github.com and api.github.com but not objects.githubusercontent.com, which is where the binaries actually live. Configure npm's proxy settings (npm config set proxy http://...) and verify the GitHub objects CDN is reachable.
For troubleshooting post-install issues in day-to-day use, see the Gemini CLI Troubleshooting Handbook. For a platform-specific install walkthrough, see our quick-start page.
Was this article helpful?