The Ultimate Guide to Installing Gemini CLI on Windows & Linux
By Gemini Guides on 6/26/2025
Getting started with a powerful new command-line tool can sometimes feel daunting, especially when it comes to environment setup. This guide provides clear, easy-to-follow instructions to get the official Gemini CLI running smoothly on your Windows or Linux machine.
Pre-requisites: Node.js and npm
The Gemini CLI is distributed as a Node.js package, which means you need to have Node.js and its package manager, npm, installed on your system first.
- To check if you have them: Open your terminal (Command Prompt, PowerShell, or your Linux terminal) and run
node -v
andnpm -v
. If you see version numbers, you're good to go! - To install them: If you don't have them, we highly recommend visiting the official Node.js website and downloading the LTS (Long-Term Support) version for your operating system. The installer will handle everything for you.
Step 1: Install the Gemini CLI Package
With Node.js and npm ready, installing the Gemini CLI is a single command. The -g
flag is important, as it installs the package "globally" on your system, making the gemini
command accessible from any directory.
Open your terminal and run the following command:
npm install -g @google/generative-ai
This command downloads the package from the npm registry and sets it up on your system.
Alternative: Quick Start without Installation (npx)
If you prefer not to install the package globally or just want to try it out quickly, you can use npx
. This command, which comes bundled with npm, downloads and runs the package temporarily without permanently installing it on your system.
Simply prefix your gemini
command with npx @google/generative-ai
:
npx @google/generative-ai "What is the most distant galaxy ever discovered, and how far is it?"
This is a fantastic way to get started instantly. For the rest of this guide, we'll assume you've performed the global installation.
Step 2: Get Your Google AI API Key
To use the CLI, you need to authenticate with a Google AI API key. This key tells Google who is making the request. If you don't have one yet, we have a complete tutorial, "How to Get Your Google Gemini API Key in 3 Easy Steps (2025 Guide)," that will walk you through the process.
Once you have your key, copy it to your clipboard and proceed to the next step.
Step 3: Configure the API Key
You need to make your API key available to the gemini
command. The most secure and recommended way to do this is by setting an environment variable.
For Linux & macOS
-
Open your shell's configuration file. This is usually
~/.bashrc
,~/.zshrc
(for most modern systems, including macOS), or~/.profile
. -
Add the following line to the end of the file. Make sure to replace
YOUR_API_KEY
with the actual key you copied.export GOOGLE_API_KEY="YOUR_API_KEY"
-
Save the file and restart your terminal, or run
source ~/.zshrc
(or your respective file) to apply the changes immediately.
For Windows
- Search for "Environment Variables" in the Start Menu and select "Edit the system environment variables".
- In the System Properties window, click the "Environment Variables..." button.
- In the "User variables" section at the top, click "New...".
- For "Variable name", enter
GOOGLE_API_KEY
. - For "Variable value", paste the API key you copied earlier.
- Click OK on all the windows to save.
Video Walkthrough
For a visual guide, these short videos cover the key steps of the process.
1. How to Install a Global NPM Package:
Video Tutorial: Installing npm packages globally
2. How to Set Environment Variables on Windows:
Video Tutorial: How to Set Environment Variables in Windows 11
Step 4: Verify Your Installation
You're all set! To confirm that everything is working correctly, run a simple test command in your terminal:
gemini "What is the most distant galaxy ever discovered, and how far is it?"
If the installation was successful, you should receive a detailed answer from the Gemini model. Congratulations, you've successfully installed and configured the Gemini CLI!
Troubleshooting Tips
command not found: gemini
: This usually means the global npm installation directory is not in your system'sPATH
. The Node.js installer should handle this, but if it doesn't, you may need to manually add it.- Authentication Errors: If you get an error about authentication, double-check that you have correctly set the
GOOGLE_API_KEY
environment variable and that there are no typos. Ensure you have restarted your terminal after setting it.
Now you're ready to explore the full power of AI from your command line. Check out our other tutorials and use cases to see what you can build!