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.
Set up or update the CLI
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
To download and run the binary for the Firebase CLI, follow these steps:
Download the Firebase CLI binary for Windows.
Access the binary to open a shell where you can run the
firebasecommand.Continue to sign in and test the CLI.
npm
To use npm (the Node Package Manager) to install the
Firebase CLI, follow these steps:
Install Node.js using nvm-windows (the Node Version Manager). Installing Node.js automatically installs the
npmcommand tools.Install the Firebase CLI via
npmby running the following command:npm install -g firebase-tools
This command enables the globally available
firebasecommand.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
To install the Firebase CLI using the automatic install script, follow these steps:
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
firebasecommand.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
To download and run the binary for the Firebase CLI that's specific for your OS, follow these steps:
Download the Firebase CLI binary for your OS: Mac OS | Linux
(Optional) Set up the globally available
firebasecommand.- Make the binary executable by running
chmod +x ./firebase_tools. - Add the binary's path to your PATH.
- Make the binary executable by running
Continue to sign in and test the CLI.
npm
To use npm (the Node Package Manager) to install the Firebase CLI,
follow these steps:
Install Node.js using nvm (the Node Version Manager).
Installing Node.js automatically installs thenpmcommand tools.Install the Firebase CLI via
npmby running the following command:npm install -g firebase-tools
This command enables the globally available
firebasecommand.Continue to sign in and test the CLI.
Sign in and test the Firebase CLI
After installing the CLI, you must authenticate. Then you can confirm authentication by listing your Firebase projects.
Sign into Firebase using your Google account by running the following command:
firebase login
This command connects your local machine to Firebase and grants you access to your Firebase projects.
Test that the CLI is properly installed and accessing your account by listing your Firebase projects. Run the following command:
firebase projects: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
- standalone binary: Download the new version, then replace it on your system
- npm: Run
npm install -g firebase-tools
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.
On a machine with a browser, install the Firebase CLI.
Start the signin process by running the following command:
firebase login:ci
Visit the URL provided, then sign in using a Google account.
Print a new refresh token. The current CLI session will not be affected.
Store the output token in a secure but accessible way in your CI system.
Use this token when running
firebasecommands. You can use either of the following two options:Store the token as the environment variable FIREBASE_TOKEN. Your system will automatically use the token.
Run all
firebasecommands 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 complete the following tasks:
Select desired Firebase products to set up in your Firebase project.
This step prompts you to set configurations for specific files for the selected products. For more details on these configurations, refer to the specific product's documentation (for example, Hosting). Note that you can always run
firebase initlater 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 the following two files at the root of your local app directory:
A
firebase.jsonconfiguration file that lists your project configuration.A
.firebasercfile 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"
]
}
}
Manage project aliases
You can associate multiple Firebase projects with the same project directory.
For example, you might want to use one Firebase project for staging and another
for production. By using different project environments, you can verify changes
before deploying to production. The firebase use command allows you to switch
between aliases as well as create new aliases.
Add a project alias
When you select a Firebase project during project
initialization, the project is automatically
assigned the alias of default. However, to allow project-specific commands to
run against a different Firebase project but still use the same project
directory, run the following command from within your project directory:
firebase use --add
This command prompts you to select another Firebase project and assign the
project as alias. Alias assignments are written to a .firebaserc file inside
your project directory.
Use project aliases
To use assigned Firebase project aliases, run any of the following commands from within your project directory.
| Command | Description |
|---|---|
firebase use |
View a list of currently defined aliases for your project directory |
firebase use \ |
Directs all commands to run against the specified Firebase project.
The CLI uses this project as the currently "active project". |
firebase use --clear |
Directs all commands to run against the Firebase project assigned the
default alias.
The CLI uses this project as the currently "active project". Running this command is the same as running
|
firebase use \ |
Removes an alias from your project directory. |
You can override what's being used as the currently active project by passing
the --project flag with any CLI command. As an example: You can set your
CLI to run against a Firebase project that you've assigned the staging
alias. If you want to run a single command against the Firebase project that
you've assigned the prod alias, then you can run, for example,
.
Source control and project aliases
In general, you should check your .firebaserc file into source control to
allow your team to share project aliases. However, for open source projects or
starter templates, you should generally not check in your .firebaserc file.
If you have a development project that's for your use only, you can either pass
the --project flag with each command or run
firebase use project_id without assigning an alias to
the Firebase project.
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 do either of the following tasks:
- View the static content for your Firebase-hosted app.
- Use Cloud Functions to generate dynamic content for Firebase Hosting and you want to use your production (deployed) HTTP functions to emulate Hosting on a local URL.
firebase serve --only hosting
Emulate your project using local HTTP functions
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
Test from other local devices
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, like so:
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
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."
When you use the firebase deploy command, be aware of the following:
To deploy resources from a project directory, the project directory must have a
firebase.jsonfile. This file is automatically created for you by thefirebase initcommand.By default,
firebase deploycreates a release for all deployable resources in your project directory. To deploy specific Firebase services or features, use partial deployment.
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 Firebase Hosting page by selecting the Rollback action for the desired release.
It's not currently possible to roll back releases of security rules for Firebase Realtime Database, Cloud Storage for Firebase, or Cloud Firestore.
Deploy specific Firebase services
If you only want to deploy specific Firebase services or features, you can use a
comma-separated list in a flag on the firebase deploy command. For example,
the following command deploys Firebase Hosting content and
Cloud Storage security rules.
firebase deploy --only hosting,storage
The following table lists the services and features available for partial
deployment. The names in the flags correspond to the keys in your
firebase.json configuration file.
| Flag syntax | Service or feature deployed |
|---|---|
--only hosting |
Firebase Hosting content |
--only database |
Firebase Realtime Database rules |
--only storage |
Cloud Storage for Firebase rules |
--only firestore |
Cloud Firestore rules and indexes |
--only firestore:rules |
Cloud Firestore rules |
--only firestore:indexes |
Cloud Firestore indexes |
--only functions |
Cloud Functions for Firebase (more specific versions of this flag are possible) |
Deploy specific functions
When deploying functions, you can target specific functions. For example:
firebase deploy --only functions:function1
firebase deploy --only functions:function1,functions:function2
Another option is to group functions into export groups in your
/functions/index.js file. Grouping functions allows you to deploy multiple
functions using a single command.
For example, you can write the following functions to define a groupA and a
groupB:
var functions = require('firebase-functions');
exports.groupA = {
function1: functions.https.onRequest(...),
function2: functions.database.ref('\path').onWrite(...)
}
exports.groupB = require('./groupB');
In this example, a separate functions/groupB.js file contains additional
functions that specifically define the functions in groupB. For example:
var functions = require('firebase-functions');
exports.function3 = functions.storage.object().onChange(...);
exports.function4 = functions.analytics.event('in_app_purchase').onLog(...);
In this example, you can deploy all the groupA functions by running the
following command from your project directory:
firebase deploy --only functions:groupA
Or you can target a specific function within a group by running the following command:
firebase deploy --only functions:groupA.function1,groupB.function4
Delete functions
The Firebase CLI supports the following commands and options for deleting previously deployed functions:
Deletes all functions that match the specified name in all regions:
firebase functions:delete function1-name
Deletes a specified function running in a non-default region:
firebase functions:delete function1-name --region region-name
Deletes more than one function:
firebase functions:delete function1-name function2-name
Deletes a specified functions group:
firebase functions:delete group-name
Bypasses the confirmation prompt:
firebase functions:delete function1-name --force
Set up predeploy and postdeploy scripted tasks
You can connect shell scripts to the firebase deploy command to perform
predeploy or postdeploy tasks. For example, a predeploy script could
transpile TypeScript code into JavaScript, and a postdeploy hook could notify
administrators of new site content deploys to Firebase Hosting.
To set up predeploy or postdeploy hooks, add bash scripts to your
firebase.json configuration file. You can define
brief scripts directly in the firebase.json file, or you can reference other
files that are in your project directory.
For example, the following script is the firebase.json expression for a
postdeploy task that sends a Slack message upon successful deployment to
Firebase Hosting.
"hosting": {
// ...
"postdeploy": "./messageSlack.sh 'Just deployed to Firebase Hosting'",
"public": "public"
}
The messageSlack.sh script file resides in the project directory and looks
like this:
curl -X POST -H 'Content-type: application/json' --data '{"text":"$1"}'
\https://Slack-Webhook-URL
You can set up predeploy and postdeploy hooks for any of the
assets that you can deploy. Note that running firebase deploy
triggers all the predeploy and postdeploy tasks defined in your
firebase.json file. To run only those tasks associated with a specific
Firebase service, use partial deployment commands.
Both predeploy and postdeploy hooks print the standard output and error
streams of the scripts to the terminal. For failure cases, note the following:
- If a predeploy hook fails to complete as expected, deployment is canceled.
- If deployment fails for any reason, postdeploy hooks are not triggered.
Environment variables
Within scripts running in the predeploy and postdeploy hooks, the following environment variables are available:
$GCLOUD_PROJECT: The active project's project ID$PROJECT_DIR: The root directory containing thefirebase.jsonfile$RESOURCE_DIR: (Forhostingandfunctionsscripts only) The location of the directory that contains the Hosting or Cloud Functions resources to be deployed
Manage multiple Realtime Database instances
If a single project has
multiple Firebase Realtime Database instances,
use the --instance instance-name option to interact with
a non-default database instance,
instance-name.firebaseio.com.
The following commands support the --instance option:
database:getdatabase:profiledatabase:pushdatabase:removedatabase:setdatabase:update
Command reference
CLI administrative commands
| Command | Description |
|---|---|
| help | Displays help information about the CLI or specific commands. |
| init | Associates and sets up a new Firebase project in the current directory.
This command creates a
firebase.json
configuration file in the current directory. |
| list | Deprecated. Instead, use
projects:list.Lists all the Firebase projects to which you have access. |
| login | Authenticates the CLI to your Firebase account. Requires access to a web browser. |
| login:ci | Generates an authentication token for use in non-interactive environments. |
| logout | Signs out the CLI from your Firebase account. |
| open | Opens a browser to relevant project resources. |
| projects:list | Lists all the Firebase projects to which you have access. |
| use | Sets the active Firebase project for the CLI. Manages project aliases. |
Project management commands
| Command | Description |
|---|---|
| apps:create | Creates a new Firebase App in the active project. |
| apps:list | Lists the registered Firebase Apps in the active project. |
| apps:sdkconfig | Prints the Google services configuration of a Firebase App. |
| projects:addfirebase | Adds Firebase resources to an existing Google Cloud Platform (GCP) project. |
| projects:create | Creates a new Google Cloud Platform (GCP) project, then adds Firebase resources to the new project. |
| projects:list | Lists all the Firebase projects to which you have access. |
| setup:web | Deprecated. Instead, use apps:sdkconfig and
specify web as the platform argument.Prints the Google services configuration of a Firebase Web App. |
Deployment and local development
These commands let you deploy and interact with your Firebase Hosting site.
| Command | Description |
|---|---|
| deploy | Deploys code and assets from your project directory to the active
project. For Firebase Hosting, a
firebase.json
configuration file is required.
|
| serve | Starts a local web server with your Firebase Hosting configuration.
For Firebase Hosting, a
firebase.json
configuration file is required. |
App Distribution commands
| Command | Description |
|---|---|
| appdistribution:distribute \ --app firebase-app-id |
Makes the build available to testers. |
Authentication (user management) commands
| Command | Description |
|---|---|
| auth:export | Exports the active project's user accounts to a JSON or CSV file. For more details, refer to the auth:import and auth:export page. |
| auth:import | Imports the user accounts from a JSON or CSV file into the active project. For more details, refer to the auth:import and auth:export page. |
Cloud Firestore commands
| Command | Description |
|---|---|
| firestore:delete | Deletes documents in the active project's database. Using the CLI, you can recursively delete all the documents in a collection. |
Cloud Functions for Firebase commands
| Command | Description |
|---|---|
| functions:config:clone | Clones another project's environment into the active Firebase project. |
| functions:config:get | Retrieves existing configuration values of the active project's Cloud Functions. |
| functions:config:set | Stores runtime configuration values of the active project's Cloud Functions. |
| functions:config:unset | Removes values from the active project's runtime configuration. |
| functions:log | Reads logs from deployed Cloud Functions. |
For more information, refer to the environment configuration documentation.
Extensions commands
| Command | Description |
|---|---|
| ext | Displays information on how to use Firebase Extensions commands. Lists the extensions installed in the active project. |
| ext:configure \ extension-instance-id |
Launches the workflow to reconfigure the parameter values of an installed extension. |
| ext:info \ extension-name |
Prints detailed information about an official Firebase extension. |
| ext:install \ extension-name |
Launches the workflow to install an official Firebase extension into your Firebase project. |
| ext:list | Lists all the extensions installed in a Firebase project. Prints the Extension Instance ID for each extension. |
| ext:uninstall \ extension-instance-id |
Uninstalls an extension from your Firebase project. |
| ext:update \ extension-instance-id |
Launches the workflow to update an installed extension to the latest version. |
Hosting commands
| Command | Description |
|---|---|
| hosting:disable | Stops serving Firebase Hosting traffic for the active Firebase project. Your project's Hosting URL will display a "Site Not Found" message after running this command. |
Realtime Database commands
| Command | Description |
|---|---|
| database:get | Fetches data from the active project's database and displays it as JSON. Supports querying on indexed data. |
| database:profile | Builds a profile of operations on the active project's database. For more details, refer to Realtime Database operation types. |
| database:push | Pushes new data to a list at a specified location in the active project's database. Takes input from a file, STDIN, or a command-line argument. |
| database:remove | Deletes all data at a specified location in the active project's database. |
| database:set | Replaces all data at a specified location in the active project's database. Takes input from a file, STDIN, or a command-line argument. |
| database:update | Performs a partial update at a specified location in the active project's database. Takes input from a file, STDIN, or a command-line argument. |