Install Google Cloud SDK, authenticate with gcloud, enable the bq CLI, and run SQL against BigQuery—all from a Mac terminal.
Running the bq
CLI on your Mac lets you version-control queries, automate jobs, and avoid the web UI. You gain faster workflows and can integrate BigQuery with IDEs like Galaxy.
You need: macOS 10.15+, Homebrew, a Google Cloud Project with BigQuery API enabled, and billing turned on.Ensure you have a Google account with BigQuery permissions.
Open Terminal and run:brew install --cask google-cloud-sdk
The installer adds gcloud
and bq
binaries. If PATH isn’t updated, add source "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc"
to ~/.zshrc
.
Run gcloud init
, sign in via browser, and select your project. Confirm with gcloud config list project
. For service-account automation, use gcloud auth activate-service-account --key-file=KEY.json
.
Check version with bq version
.Run bq ls
to list datasets. Any error about credentials usually means the project or auth step was skipped.
Execute:bq query --use_legacy_sql=false "SELECT id, name, email FROM `myproj.analytics.Customers` LIMIT 10;"
Replace myproj
with your project ID. --use_legacy_sql=false
ensures standard SQL.
Store SQL in a file, e.g., top_products.sql
, then run:bq query --use_legacy_sql=false --format=table < top_products.sql
.This fits nicely into Galaxy, CI, or cron jobs.
Create separate service-account keys per environment, keep them in the Keychain or secrets manager, and set GCP_PROJECT
in your shell profile. Use --format=json
for script-friendly output.
PATH not updated: If command not found: gcloud
, source the SDK’s path script or restart Terminal.
Wrong project: “Access Denied” errors often mean the active project is wrong—run gcloud config set project PROJECT_ID
.
.
No. The Cloud SDK installs native binaries. Docker is only needed for the emulator, which BigQuery doesn’t provide.
Yes. Run gcloud auth login
for user accounts or use separate service-account keys and gcloud config configurations activate NAME
.
Run brew upgrade google-cloud-sdk
periodically or add it to a cron job.