To develop and test your application locally, you can use theGoogle Cloud
Firestore
Emulator,
which provides local emulation of the production Google Cloud Firestore
environment. You can start the Google Cloud Firestore emulator using
thegcloudcommand-line tool.
When you run the Cloud Firestore emulator you will see a message similar to the
following printed:
If you are using a library that supports the FIRESTORE_EMULATOR_HOST
environment variable, run:
export FIRESTORE_EMULATOR_HOST=localhost:8080
Now you can connect to the emulator using theFIRESTORE_EMULATOR_HOSTenvironment variable:
require"google/cloud/firestore"# Make Firestore use the emulatorENV["FIRESTORE_EMULATOR_HOST"]="127.0.0.1:8080"firestore=Google::Cloud::Firestore.newproject_id:"emulator-project-id"# Get a document referencenyc_ref=firestore.doc"cities/NYC"nyc_ref.set({name:"New York City"})# Document created
Or by providing theemulator_hostargument:
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.newproject_id:"emulator-project-id",emulator_host:"127.0.0.1:8080"# Get a document referencenyc_ref=firestore.doc"cities/NYC"nyc_ref.set({name:"New York City"})# Document created
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [3.1.0 (latest)](/ruby/docs/reference/google-cloud-firestore/latest/EMULATOR)\n- [3.0.0](/ruby/docs/reference/google-cloud-firestore/3.0.0/EMULATOR)\n- [2.16.1](/ruby/docs/reference/google-cloud-firestore/2.16.1/EMULATOR)\n- [2.15.1](/ruby/docs/reference/google-cloud-firestore/2.15.1/EMULATOR)\n- [2.14.0](/ruby/docs/reference/google-cloud-firestore/2.14.0/EMULATOR)\n- [2.13.1](/ruby/docs/reference/google-cloud-firestore/2.13.1/EMULATOR)\n- [2.12.0](/ruby/docs/reference/google-cloud-firestore/2.12.0/EMULATOR)\n- [2.11.0](/ruby/docs/reference/google-cloud-firestore/2.11.0/EMULATOR)\n- [2.10.1](/ruby/docs/reference/google-cloud-firestore/2.10.1/EMULATOR)\n- [2.9.1](/ruby/docs/reference/google-cloud-firestore/2.9.1/EMULATOR)\n- [2.8.0](/ruby/docs/reference/google-cloud-firestore/2.8.0/EMULATOR)\n- [2.7.2](/ruby/docs/reference/google-cloud-firestore/2.7.2/EMULATOR)\n- [2.6.6](/ruby/docs/reference/google-cloud-firestore/2.6.6/EMULATOR) \n\nGoogle Cloud Firestore Emulator\n===============================\n\nTo develop and test your application locally, you can use the [Google Cloud\nFirestore\nEmulator](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/firestore/),\nwhich provides local emulation of the production Google Cloud Firestore\nenvironment. You can start the Google Cloud Firestore emulator using\nthe `gcloud` command-line tool.\n\n`gcloud beta emulators firestore start --host-port=0.0.0.0:8080`\n\nWhen you run the Cloud Firestore emulator you will see a message similar to the\nfollowing printed: \n\n If you are using a library that supports the FIRESTORE_EMULATOR_HOST\n environment variable, run:\n\n export FIRESTORE_EMULATOR_HOST=localhost:8080\n\nNow you can connect to the emulator using the `FIRESTORE_EMULATOR_HOST`\nenvironment variable: \n\n```ruby\nrequire \"google/cloud/firestore\"\n\n# Make Firestore use the emulator\nENV[\"FIRESTORE_EMULATOR_HOST\"] = \"127.0.0.1:8080\"\n\nfirestore = Google::Cloud::Firestore.new project_id: \"emulator-project-id\"\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\nnyc_ref.set({ name: \"New York City\" }) # Document created\n```\n\nOr by providing the `emulator_host` argument: \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new project_id: \"emulator-project-id\",\n emulator_host: \"127.0.0.1:8080\"\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\nnyc_ref.set({ name: \"New York City\" }) # Document created\n```"]]