With google-cloud-ruby it's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis.
Google Cloud Platform environments
While running on Google Cloud Platform (GCP), including Google Compute Engine (GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud Functions (GCF) and Cloud Run, no extra work is needed. The Project ID and Credentials and are discovered automatically. Code should be written as if already authenticated.
Project and Credential Lookup
The google-cloud library aims to make authentication as simple as possible, and provides several mechanisms to configure your system without providing Project ID and Service Account Credentials directly in code.
Project ID is discovered in the following order:
Specify project ID in code
Discover project ID in environment variables
Discover GCE project ID
Credentials are discovered in the following order:
Specify credentials in code
Discover credentials path in environment variables
Discover credentials JSON in environment variables
Discover credentials file in the Cloud SDK's path
Discover GCE credentials
Environment Variables
The Project ID and Credentials JSON can be placed in environment variables instead of declaring them directly in code. Each service has its own environment variable, allowing for different service accounts to be used for different services. The path to the Credentials JSON file can be stored in the environment variable, or the Credentials JSON itself can be stored for environments such as Docker containers where writing files is difficult or not encouraged.
Here are the environment variables (in the order they are checked) for project ID:
GOOGLE_CLOUD_PROJECT
Here are the environment variables (in the order they are checked) for credentials:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [1.8.0 (latest)](/ruby/docs/reference/google-cloud-core/latest/AUTHENTICATION)\n- [1.7.1](/ruby/docs/reference/google-cloud-core/1.7.1/AUTHENTICATION)\n- [1.6.1](/ruby/docs/reference/google-cloud-core/1.6.1/AUTHENTICATION) \n\nWith `google-cloud-ruby`\n------------------------\n\nWith `google-cloud-ruby` it's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis.\n\n### Google Cloud Platform environments\n\nWhile running on Google Cloud Platform (GCP), including Google Compute Engine (GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud Functions (GCF) and Cloud Run, no extra work is needed. The **Project ID** and **Credentials** and are discovered automatically. Code should be written as if already authenticated.\n\n### Project and Credential Lookup\n\nThe google-cloud library aims to make authentication as simple as possible, and provides several mechanisms to configure your system without providing **Project ID** and **Service Account Credentials** directly in code.\n\n**Project ID** is discovered in the following order:\n\n1. Specify project ID in code\n2. Discover project ID in environment variables\n3. Discover GCE project ID\n\n**Credentials** are discovered in the following order:\n\n1. Specify credentials in code\n2. Discover credentials path in environment variables\n3. Discover credentials JSON in environment variables\n4. Discover credentials file in the Cloud SDK's path\n5. Discover GCE credentials\n\n### Environment Variables\n\nThe **Project ID** and **Credentials JSON** can be placed in environment variables instead of declaring them directly in code. Each service has its own environment variable, allowing for different service accounts to be used for different services. The path to the **Credentials JSON** file can be stored in the environment variable, or the **Credentials JSON** itself can be stored for environments such as Docker containers where writing files is difficult or not encouraged.\n\nHere are the environment variables (in the order they are checked) for project ID:\n\n1. `GOOGLE_CLOUD_PROJECT`\n\nHere are the environment variables (in the order they are checked) for credentials:\n\n1. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file\n2. `GOOGLE_CLOUD_KEYFILE_JSON` - JSON contents"]]