How to Install Gemini CLI on Ubuntu 26.04, 24.04 and 22.04

Install Gemini CLI on Ubuntu 26.04, 24.04, and 22.04 with npm or npx. Covers setup, sign-in, updates, removal, and first use tips.

Last updatedAuthorJoshua JamesRead time12 minGuide typeUbuntu

Some terminal agents push you straight into a paid API workflow, but Gemini CLI is unusual because a normal Google account can be enough to get started. That makes it practical to install Gemini CLI on Ubuntu when you want project-aware prompts, local file context, and MCP tooling without leaving the shell.

Google’s official installation guide and the Gemini CLI GitHub repository treat npm as the standard path, with Homebrew and npx as the main Linux alternatives. On Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS, those paths cover installation, sign-in, first-use commands, updates, release tags, and clean removal without adding an Ubuntu-specific package source.

Install Gemini CLI on Ubuntu

Gemini CLI is not packaged in Ubuntu’s default APT repositories. If you search apt for it, you mostly find Gemini protocol clients and unrelated packages, so the upstream npm package is the practical Ubuntu route and npx is the quickest temporary alternative. This installs the terminal gemini command rather than a desktop Gemini app.

MethodChannelVersionUpdatesBest For
Global npm installOfficial install docsLatest stablenpm update -g @google/gemini-cliDaily Ubuntu use
HomebrewOfficial install docsHomebrew bottle, may trail npmbrew upgrade gemini-cliUsers already on Homebrew
npx quick runOfficial install docsLatest stableRefreshes through npm cache on demandOne-off tests or short-lived shells

Google’s docs also list Anaconda for restricted environments and MacPorts for macOS, but npm, Homebrew, and npx are the Ubuntu paths worth spending time on. Homebrew can trail the npm package, so npm remains the best default unless your development stack already lives in Homebrew.

  • Use the global npm install when you want gemini available in every shell and project.
  • Use Homebrew when you already manage your terminal tools there and want Gemini CLI to follow the same package workflow.
  • Use npx when you are evaluating Gemini CLI, working in a throwaway environment, or only need one short session.
  • Skip extra package-manager layers unless you already depend on them for the rest of your Ubuntu development workflow.

These instructions target Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. Gemini CLI needs Node.js 20 or newer, Bash or Zsh, internet access, and enough memory for the session size you expect to run. Google’s current Linux guidance calls 4 GB workable for lighter use and 16 GB more realistic for larger codebases. Ubuntu 24.04 and 22.04 users usually need NodeSource or NVM first because the default Ubuntu repository versions are older than Gemini CLI requires.

Check Node.js and npm on Ubuntu Before Installing Gemini CLI

Check the runtime first so you do not chase npm errors later:

node --version
npm --version
npm config get prefix
v24.x.x
11.x.x
/usr
  • node --version needs to show version 20 or newer because Gemini CLI refuses older runtimes.
  • npm --version confirms the Node package manager is available and working in your current shell.
  • npm config get prefix shows where global npm packages will be installed, which matters on Ubuntu because a system prefix like /usr usually leads to permission errors for normal users.

If Node.js is missing or older than 20, follow the guide to install Node.js on Ubuntu before continuing. The NodeSource and NVM methods in that guide both provide supported runtimes for Ubuntu 24.04 and 22.04. When npm config get prefix returns /usr, npm is still pointed at a system-owned global path, which is why a normal npm install -g fails with EACCES on a stock Ubuntu user account.

Install Gemini CLI on Ubuntu with npm

Move npm’s global prefix into your home directory for the current shell, then install Gemini CLI:

npm config set prefix ~/.local
export PATH="$HOME/.local/bin:$PATH"
npm install -g @google/gemini-cli

For newer Ubuntu users, ~/.local is just a per-user directory inside your home folder. Putting npm’s global prefix there keeps Gemini CLI out of system-owned paths, which means you do not need sudo for the install and you do not risk mixing your own CLI tools into Ubuntu’s package-managed files.

The export PATH=... line makes the new prefix available immediately in the current terminal. Without it, the install can succeed while gemini still looks missing until you open a new shell.

If you want future Bash sessions to pick up the same path automatically, append it to your shell profile now:

touch ~/.bashrc
grep -qxF 'export PATH="$HOME/.local/bin:$PATH"' ~/.bashrc || echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Bash uses ~/.bashrc here because that file is loaded for normal interactive Bash shells. If you already prefer Zsh, put the same line in ~/.zshrc after you install Zsh on Ubuntu.

Verify that Ubuntu can see the launcher and the installed npm package:

command -v gemini
npm list -g --depth=0 @google/gemini-cli --unicode=false

Relevant output includes your home-directory launcher path plus the installed package version, for example:

/home/linuxcapable/.local/bin/gemini
/home/linuxcapable/.local/lib
`-- @google/gemini-cli@0.x.x

This check is cleaner than using gemini --version as the first verification command. The first full interactive launch creates Gemini’s local state under ~/.gemini, so starting the CLI itself is the better first-run test.

Install Gemini CLI on Ubuntu with Homebrew

Use the Homebrew method only when Homebrew is already part of your Ubuntu workflow or you intentionally want Gemini CLI to stay inside your Homebrew-managed toolchain. If you still need the package manager itself, follow the guide to install Homebrew on Ubuntu first.

Homebrew manages its own node dependency inside the Homebrew prefix, so this path does not require the separate NodeSource or NVM setup used by the npm method.

On a fresh shell, load Homebrew’s environment before you install Gemini CLI:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install gemini-cli

Verify the Homebrew package and the launcher path instead of using gemini --version as the first check. The first full Gemini launch can create local project-registry state under ~/.gemini, so keep package verification separate from interactive onboarding.

brew list --versions gemini-cli
command -v gemini

Relevant output includes the current Homebrew package version and the launcher path, for example:

gemini-cli 0.x.x
/home/linuxbrew/.linuxbrew/bin/gemini

That version check matters because the Homebrew formula can lag behind the npm release. If the newest Gemini CLI build matters for a bug fix or command change, compare the Homebrew output with the npm tag before choosing this method.

Run Gemini CLI on Ubuntu with npx for a Temporary Session

Use npx when you only need a temporary session or want to test Gemini CLI before you keep it on your PATH:

npx @google/gemini-cli

If npm asks to install the package first, answer y and let it continue. npx downloads Gemini CLI into ~/.npm/_npx and then starts the same interface you get from a global install. That is useful on Ubuntu servers, throwaway environments, or short debugging sessions where you do not want another permanent global CLI.

npx is not a substitute for the daily-use install. If you want gemini available in every new shell, keep the global npm install instead of relying on the temporary npm cache.

Authenticate Gemini CLI on Ubuntu

The first interactive launch handles authentication. Personal Google accounts, including the free individual tier, can usually sign in directly, while API key and Vertex AI paths make more sense for headless shells, CI, or pay-as-you-go usage. Workspace and organization-backed Code Assist licenses can also require GOOGLE_CLOUD_PROJECT before the browser login flow is complete. Google’s authentication guide is the canonical reference for account-specific edge cases.

  1. Gemini asks whether you trust the current folder, because local project settings can change the CLI’s behavior.
  2. Gemini then asks how you want to authenticate, which is where you choose Google sign-in, API key, or Vertex AI.
  3. After that, Gemini stores its local state under ~/.gemini so later sessions can reuse the same project registry and authentication context.
Authentication MethodBest ForWhat You Set
Sign in with GoogleLocal Ubuntu workstations and most personal accountsNo environment variables required
Gemini API keyHeadless shells, quick pay-as-you-go use, or a browserless setupGEMINI_API_KEY
Vertex AIGoogle Cloud projects, organization controls, or enterprise governanceGOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION, and a supported Google Cloud auth method

Start Gemini CLI in a Project Directory on Ubuntu

Launch Gemini from a real project folder instead of your home directory. That avoids the home-directory warning and makes the trust prompt easier to answer:

cd ~/your-project
gemini

On first launch, Gemini CLI asks whether you trust the current folder because local .gemini settings, hooks, agents, and MCP servers can change what the CLI does. After that, choose Sign in with Google if you want the standard browser-based login.

Google sign-in works best from a local Ubuntu desktop or any browser-equipped machine that can communicate with the terminal running Gemini. If you start the session from SSH on a remote Ubuntu host, the browser flow is usually the wrong fit, which is where API key or Vertex AI auth becomes easier.

Use a Gemini API Key on Ubuntu

API key authentication is the simplest headless option when the Ubuntu machine does not have a browser path back to your terminal:

export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
gemini

Get the key from Google AI Studio, then choose Use Gemini API key when Gemini asks how to authenticate for the project. If you later want this setting to persist, place it in ~/.gemini/.env or your shell profile, but remember that exported keys are sensitive credentials and should stay out of shared shell history.

Use Vertex AI with Gemini CLI on Ubuntu

Vertex AI is the better fit when your Ubuntu workflow already lives inside a Google Cloud project or an organization-controlled environment:

unset GOOGLE_API_KEY GEMINI_API_KEY
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="us-central1"
gcloud auth application-default login
gemini

This path assumes Google Cloud CLI is installed on Ubuntu. The unset line matters when an older API key is still exported in the same shell. Without clearing it first, Gemini can keep choosing the API key route instead of Vertex AI.

Use Gemini CLI on Ubuntu

Once sign-in is done, the day-to-day workflow is simple: start in the project directory you care about, let Gemini see the local files you actually want it to reason about, and keep the common slash commands nearby.

Ask Gemini CLI One-Off Questions on Ubuntu

Prompt mode is the fastest way to get one answer and exit:

gemini -p "Summarize this repository and list the main entry points."
gemini -p "Review the failing test in tests/auth.spec.ts and suggest the smallest fix."

That is useful in scripts, remote shells, and quick reviews where you want one answer without staying inside the full interactive interface.

Use File Context and Shell Commands with Gemini CLI on Ubuntu

The interactive session becomes much more useful once you combine prompts with project files and shell commands instead of typing plain questions into a blank agent:

gemini
@README.md Summarize the setup steps in this project.
!git status

The @README.md line injects the contents of that file into the current prompt, which is faster than copy-pasting file text manually. The !git status line runs a normal shell command from inside Gemini CLI, so the agent can see the repository state you are looking at in the same terminal session.

Create a GEMINI.md File for Ubuntu Projects

GEMINI.md files are Gemini CLI’s project instructions. They are the quickest way to teach the agent about your coding conventions, repository layout, and local house rules:

gemini
/init
/memory list

/init generates a starter GEMINI.md based on the current directory, while /memory list shows which GEMINI.md files Gemini has loaded for the active project.

Manage Gemini CLI Sessions on Ubuntu

Gemini CLI can also save and resume longer conversations so you do not have to keep one terminal open forever:

gemini
/chat save ubuntu-notes
/resume
/chat share gemini-session.md

/chat save creates a tagged checkpoint for the current project, /resume opens the saved-session browser, and /chat share exports the current conversation to a file you can keep with the rest of your notes.

Use Common Gemini CLI Commands on Ubuntu

These are the commands most worth remembering when you start using Gemini daily:

CommandWhat It Does
/helpLists built-in commands and usage details
/aboutShows version information that is useful for bug reports and support checks
/tools descShows the tools available to the model and what each one does
/stats modelDisplays usage statistics and the quota view tied to your current authentication method
/mcp listLists configured MCP servers and the tools they expose
/chat save project-tagSaves a tagged checkpoint for the current project conversation
@README.md Explain this projectInjects file content into the prompt without copy-paste
!git statusRuns a shell command from inside Gemini CLI

If Gemini is going to work inside real repositories, make sure you install Git on Ubuntu first so repository-aware prompts, diffs, and shell commands like !git status behave as expected.

Update Gemini CLI on Ubuntu

The default npm install stays on the stable channel. Update that package in place, then re-check the installed version:

npm update -g @google/gemini-cli
npm list -g --depth=0 @google/gemini-cli --unicode=false

Relevant output includes the same home-directory npm prefix with the refreshed package version, for example:

/home/linuxcapable/.local/lib
`-- @google/gemini-cli@0.x.x

Understand Gemini CLI Release Cadence and Tags on Ubuntu

Gemini CLI publishes three npm channels, and the official docs give each one a different cadence:

Check the live npm tags before switching channels so you know which build each tag currently resolves to:

npm view @google/gemini-cli dist-tags
{
  latest: '0.x.x',
  preview: '0.x.x-preview.x',
  nightly: '0.x.x-nightly.YYYYMMDD...'
}
  • Stable: the default latest tag, published weekly and intended for normal day-to-day use.
  • Preview: published weekly, but less vetted and more likely to carry regressions or unfinished edges.
  • Nightly: published daily from the main branch, which makes it the fastest-moving and riskiest option.

If you explicitly want a different channel, switch the npm tag instead of mixing install methods:

npm install -g @google/gemini-cli@latest
npm install -g @google/gemini-cli@preview
npm install -g @google/gemini-cli@nightly

Use @preview or @nightly only when you actually want faster-moving builds. The stable tag is the safer Ubuntu default because it lags behind preview and nightly changes.

Update Homebrew Gemini CLI on Ubuntu

If you installed Gemini CLI through Homebrew, keep the update path inside Homebrew as well:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew upgrade gemini-cli
brew list --versions gemini-cli

When the Homebrew bottle was already current, brew upgrade gemini-cli returned a no-op, and brew list --versions gemini-cli remained the clearest post-upgrade check.

Troubleshoot Gemini CLI on Ubuntu

Most Ubuntu problems come down to npm permissions, PATH, or trying to use browser-based authentication from a shell that cannot open a browser.

Fix npm EACCES Errors When Installing Gemini CLI on Ubuntu

If npm still points global packages at /usr, a normal user install fails before Gemini CLI ever lands on disk:

npm config get prefix
/usr

Switch the prefix into your home directory, then rerun the install from the same shell:

npm config set prefix ~/.local
export PATH="$HOME/.local/bin:$PATH"

After that, rerun npm install -g @google/gemini-cli. The package installs cleanly as an unprivileged Ubuntu user once the prefix is no longer system-owned.

Fix Gemini Command Not Found on Ubuntu

If the install succeeds but gemini still looks missing, your shell is not loading ~/.local/bin yet. Add it to the startup file you actually use, then reload the shell:

touch ~/.bashrc
grep -qxF 'export PATH="$HOME/.local/bin:$PATH"' ~/.bashrc || echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
command -v gemini
/home/linuxcapable/.local/bin/gemini

If you use Zsh instead of Bash, put the same line in ~/.zshrc after you install Zsh on Ubuntu.

Fix Gemini CLI Sign-In Problems on SSH-Only Ubuntu Sessions

If the browser-based Google login never completes because the Ubuntu host cannot open or hand off a browser session, switch to API key or Vertex AI authentication instead:

export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
gemini

This avoids the local browser requirement completely. If remote shell access is the real blocker, install SSH on Ubuntu first and keep the Gemini session inside the project directory you actually want it to inspect.

Remove Gemini CLI from Ubuntu

Uninstall only the pieces you actually used. A global npm install and Gemini’s local state are the main cleanup targets. The npx path does not leave a permanent gemini binary behind, but it can reuse npm’s temporary cache under ~/.npm/_npx.

Remove the npm Install of Gemini CLI on Ubuntu

Remove the global package first, then clear Bash’s cached command path before you verify the result in the same terminal:

npm uninstall -g @google/gemini-cli
hash -r
command -v gemini || echo command-not-found
command-not-found

The hash -r step matters because Bash can remember the old launcher path until you clear the shell hash table or open a new terminal.

Leave the ~/.local/bin PATH line in place if you use other global npm tools. If Gemini CLI was the only reason you added that line, remove it from ~/.bashrc or ~/.zshrc after uninstalling the package.

Remove Homebrew Gemini CLI on Ubuntu

If you installed Gemini CLI with Homebrew, remove it through the same package manager instead of deleting the launcher by hand:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew uninstall gemini-cli

Homebrew can also auto-remove unneeded dependencies such as Node.js, Python, OpenSSL, and supporting libraries when nothing else still needs them. Review the uninstall output before you confirm it on a system where Homebrew manages more than just Gemini CLI.

Confirm that Homebrew no longer tracks the package and that the launcher is gone from your shell:

brew list --versions gemini-cli || echo brew-package-removed
command -v gemini || echo gemini-command-missing
brew-package-removed
gemini-command-missing

Remove Gemini CLI State on Ubuntu

Delete the local state only when you want to remove authentication data, chat history, and project registry files as well:

This directory can contain cached prompts, project registry data, and authentication material. Keep it if you only wanted to remove the executable and expect to sign back in later. If you used the npx path, npm may also keep hashed caches under ~/.npm/_npx. Leave those alone unless you intentionally want to clear your wider npx cache too.

rm -rf "$HOME/.gemini"

Confirm that the local state directory is gone:

test ! -d "$HOME/.gemini" && echo "~/.gemini removed"
~/.gemini removed

Next Steps After Installing Gemini CLI on Ubuntu

Gemini CLI is ready to work from your Ubuntu project directories once Node.js, npm, and authentication are in place. Start inside a repository instead of your home directory, pair it with Git on Ubuntu for cleaner repo-aware prompts, and compare it with Codex CLI on Ubuntu, GitHub Copilot CLI on Ubuntu, or Claude Code on Ubuntu if you want a broader terminal-agent toolkit.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: