Skip to content

Instantly share code, notes, and snippets.

@SimpleZn
Last active June 5, 2025 05:10
Show Gist options
  • Save SimpleZn/8e0a714b0853f1cbf4c8f30fae9ac66e to your computer and use it in GitHub Desktop.
Save SimpleZn/8e0a714b0853f1cbf4c8f30fae9ac66e to your computer and use it in GitHub Desktop.
Set up your API key locally as an environment variable

MacOS - zsh

https://ai.google.dev/gemini-api/docs/api-key#macos---zsh

For initial testing, you can hard code an API key, but this should only be temporary since it is not secure. The rest of this section goes through how to set up your API key locally as an environment variable with different operating systems.

Zsh is a common Linux and macOS terminal configuration. You can check if you have a configuration file for it by running the following command:

~/.zshrc

If the response is "No such file or directory", you will need to create this file and open it by running the following commands, or use bash:

touch ~/.zshrc
open ~/.zshrc

Next, you need to set your API key by adding the following export command:

export GEMINI_API_KEY=<YOUR_API_KEY_HERE>

After saving the file, apply the changes by running:

source ~/.zshrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment