Go to console

Firebase CLI Reference

The Firebase CLI (GitHub) provides a variety of tools for managing, viewing, and deploying to Firebase projects.

Before using the Firebase CLI, set up a Firebase project.

Install the Firebase CLI

You can install the Firebase CLI using a method that matches your operating system, experience level, and/or use case. Regardless of how you install the CLI, you have access to the same functionality and the firebase command.

Windows

You can install the Firebase CLI for Windows using one of the following options:

Option Description Recommended for...
standalone binary Download the standalone binary for the CLI. Then, you can access the executable to open a shell where you can run the firebase command. New developers

Developers not using or unfamiliar with Node.js
npm Use npm (the Node Package Manager) to install the CLI and enable the globally available firebase command. Developers using Node.js

standalone binary

You can download and run the binary for the Firebase CLI.

  1. Download the Firebase CLI binary for Windows.

  2. Access the binary to open a shell where you can run the firebase command.

  3. Continue to sign in and test the CLI.

npm

You can use npm (the Node Package Manager) to install the Firebase CLI.

  1. Install Node.js using nvm-windows (the Node Version Manager). Installing Node.js automatically installs the npm command tools.

  2. Install the Firebase CLI via npm by running:

    npm install -g firebase-tools

    This command enables the globally available firebase command.

  3. Continue to sign in and test the CLI.

Mac OS or Linux

You can install the Firebase CLI for Mac OS or Linux using one of the following options:

Option Description Recommended for...
automatic install script Run a single command that automatically detects your operating system, downloads the latest CLI release, then enables the globally available firebase command. New developers

Developers not using or unfamiliar with Node.js

Automated deploys in a CI/CD environment
standalone binary Download the standalone binary for the CLI. Then, you can configure and run the binary to suit your workflow. Fully customizable workflows using the CLI
npm Use npm (the Node Package Manager) to install the CLI and enable the globally available firebase command. Developers using Node.js

auto install script

If you're using Mac OS or Linux, you can install the Firebase CLI using the automatic install script.

  1. Run the following cURL command:

    curl -sL firebase.tools | bash

    This script automatically detects your operating system, downloads the latest Firebase CLI release, then enables the globally available firebase command.

  2. Continue to sign in and test the CLI.

For more examples and details about the automatic install script, refer to the script's source code at firebase.tools.

standalone binary

You can download and run the binary for the Firebase CLI that's specific for your OS.

  1. Download the Firebase CLI binary for your OS: Mac OS | Linux

  2. (Optional) Set up the globally available firebase command:

    1. Make the binary executable by running chmod +x ./firebase_tools.
    2. Add the binary's path to your PATH.
  3. Continue to sign in and test the CLI.

npm

You can use npm (the Node Package Manager) to install the Firebase CLI.

  1. Install Node.js using nvm (the Node Version Manager). Installing Node.js automatically installs the npm command tools.

  2. Install the Firebase CLI via npm by running:

    npm install -g firebase-tools

    This command enables the globally available firebase command.

  3. Continue to sign in and test the CLI.

Sign in and test your Firebase CLI

After installing the CLI, you must authenticate. Then you can confirm authentication by listing your Firebase projects.

  1. Sign into Firebase using your Google account:

    firebase login

    This command connects your local machine to Firebase and grants you access to your Firebase projects.

  2. Test that the CLI is properly installed and accessing your account by listing your Firebase projects:

    firebase list

    The displayed list should be the same as the Firebase projects listed in the Firebase console.

Update to the latest CLI version

Generally, you want to use the most up-to-date Firebase CLI version.

How you update the CLI version depends on your operating system and how you installed the CLI.

Windows

Mac OS

  • automatic install script: Run curl -sL firebase.tools | bash
  • standalone binary: Download the new version, then replace it on your system
  • npm: Run npm install -g firebase-tools

Linux

  • automatic install script: Run curl -sL firebase.tools | bash
  • standalone binary: Download the new version, then replace it on your system
  • npm: Run npm install -g firebase-tools

Use the CLI with CI systems

The Firebase CLI requires a browser to complete authentication, but the CLI is fully compatible with CI and other headless environments.

  1. On a machine with a browser, install the Firebase CLI.

  2. Start the sign in process by running:

    firebase login:ci
  3. Visit the URL provided, then sign in using a Google account.

  4. Print a new refresh token. The current CLI session will not be affected.

  5. Store the output token in a secure but accessible way in your CI system.

  6. Use this token when running firebase commands; you have two options:

    • Store the token as the environment variable FIREBASE_TOKEN. Your system will automatically use the token.

    • Run all firebase commands with the --token <token> flag in your CI system.
      The order of precedence for token loading is flag, environment variable, desired Firebase project.

Initialize a Firebase project

Many common tasks performed using the CLI, such as deploying to a Firebase project, require a project directory. You establish a project directory using the firebase init command. A project directory is usually the same directory as your source control root, and after running firebase init, the directory contains a firebase.json configuration file.

To initialize a new Firebase project, run the following command from within your app's directory:

firebase init

The firebase init command steps you through setting up your project directory and some Firebase products. During project initialization, the Firebase CLI asks you to:

  • Select desired Firebase products then prompts you to set configurations for specific files for the selected products.

    To set up a specific Firebase product for your project, refer to that product's documentation for setup information (for example, Hosting). Note that you can always run firebase init later to set up more Firebase products.

  • Select a default Firebase project.

    This step associates the current project directory with a Firebase project so that project-specific commands (like firebase deploy) run against the appropriate Firebase project.

    It's also possible to associate multiple Firebase projects (such as a staging project and a production project) with the same project directory.

At the end of initialization, Firebase automatically creates and adds two files to the root of your local app directory:

  • A firebase.json configuration file that lists your project configuration.

  • A .firebaserc file that stores your project aliases.

The firebase.json file

The firebase init command creates a firebase.json configuration file in the root of your project directory.

The firebase.json file is required to deploy assets with the Firebase CLI because it specifies which files and settings from your project directory are deployed to your Firebase project. Since some settings can be defined in either your project directory or the Firebase console, make sure that you resolve any potential deployment conflicts.

You can configure most Firebase Hosting options directly in the firebase.json file. However, for other Firebase services that can be deployed with the Firebase CLI, the firebase init command creates specific files where you can define settings for those services, such as an index.js file for Cloud Functions. You can also set up predeploy or postdeploy hooks in the firebase.json file.

The following is an example firebase.json file with default settings if you select Firebase Hosting, Cloud Firestore, and Cloud Functions for Firebase during initialization.

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ]
  }
}

Serve and test your Firebase project locally

You can view and test your Firebase project on locally hosted URLs before deploying to production. If you only want to test select features, you can use a comma-separated list in a flag on the firebase serve command.

Run the following command from the root of your local project directory if you want to either:

firebase serve --only hosting

Run any of the following commands from your project directory to emulate your project using local HTTP functions.

  • To emulate HTTP functions and hosting for testing on local URLs, use either of the following commands:

    firebase serve
    firebase serve --only functions,hosting // uses a flag
  • To emulate HTTP functions only, use the following command:

    firebase serve --only functions

By default, firebase serve only responds to requests from localhost. This means that you'll be able to access your hosted content from your computer's web browser but not from other devices on your network. If you'd like to test from other local devices, use the --host flag:

firebase serve --host 0.0.0.0  // accepts requests to any host

Deploy to a Firebase project

The Firebase CLI manages deployment of code and assets to your Firebase project, including:

  • New releases of your Firebase Hosting sites
  • New, updated, or existing Cloud Functions for Firebase
  • Rules for Firebase Realtime Database
  • Rules for Cloud Storage for Firebase
  • Rules for Cloud Firestore
  • Indexes for Cloud Firestore

To deploy to a Firebase project, run the following command from your project directory:

firebase deploy

By default, firebase deploy creates a release for all deployable resources in your project directory. To deploy specific Firebase services or features, use partial deployment.

Note that to deploy resources from a project directory, the project directory must have a firebase.json file. This file was automatically created for you by the firebase init command.

You can optionally add a comment to each of your deployments. This comment will display with the other deployment information on your project's Firebase Hosting page. For example:

firebase deploy -m "Deploying the best new feature ever."

Deployment conflicts for security rules

For Firebase Realtime Database, Cloud Storage for Firebase, and Cloud Firestore, you can define security rules either in your local project directory or in the Firebase console.

Another option to avoid deployment conflicts is to use partial deployment and only define rules in the Firebase console.

Deployment quotas

It's possible (though unlikely) that you might exceed a quota that limits the rate or volume of your Firebase deployment operations. For example, when deploying very large numbers of functions, you might receive an HTTP 429 Quota error message. To solve such issues, try using partial deployment or requesting quota increases for specific Firebase services. For example, the quota called Write requests per 100 seconds per user might help to resolve the Cloud Functions 429 error cited above.

Roll back a deployment

You can roll back a Firebase Hosting deployment from your project's