How to install Firebase CLI for Flutter application

Firebase CLI (command line interface) is a powerful tool provided by Firebase that allows developers to interact with Firebase services from the command line. It simplifies the management and deployment of Firebase resources, making it easier to integrate Firebase services into your Flutter applications.

Installation guide

You can follow the instructions given below to install Firebase CLI.

  1. Install Node.js.

  2. Install Firebase CLI using npm.

  3. Install FlutterFire CLI, especially for Flutter applications.

  4. Login to Firebase and test CLI.

Install Node.js

To begin the installation process, you need to install Node.js, which includes npm (node package manager). Npm is required to install and run Firebase CLI and FlutterFire CLI.

Windows & macOS

  • Visit the official Node.js website.

  • Download the Node.js installer suitable for your Windows or macOS version.

  • Now run the installer, and you can follow the on-screen instructions to complete the installation.

Linux

To install Node.js on Linux, you can run the following commands on the terminal.

sudo apt update
sudo apt install nodejs npm

After installation is complete, verify by checking the installed version of node.js by using the following command.

node -v
npm -v

The Firebase CLI requires Node.js v16.13.0 or later.

Install Firebase CLI using npm

Once Node.js is installed, you can install Firebase CLI using npm. Follow the commands below in your terminal.

npm install -g firebase-tools

This command installs Firebase CLI globally on your system, making it accessible from any directory using firebase keyword.

Question

After running the above command, I saw this error npm ERR! Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/firebase-tools' What do I do?

Show Answer

Install FlutterFire CLI

After installing Firebase CLI, you can install FlutterFire CLI, specifically designed for Flutter apps using Firebase services. Follow the commands below in your terminal or command prompt.

dart pub global activate flutterfire_cli

After running the above command, the flutterfire command will be available globally.

Question

After running the above command, I saw this error flutterfire: command not found' What do I do?

Show Answer

Login to Firebase and test CLI

After Installation is completed, you have to log in to the Firebase console so that you can manage your projects from CLI using the following command.

firebase login

This command will open a web page where you will provide your credentials to connect to localhost on your machine.

If you are working on a remote machine where accessing localhost is impossible, include the "--no-localhost" flag when running the command.

You can verify that your CLI is working fine by using the following command.

firebase projects:list

This command should list the same projects available at the Firebase console.

Conclusion

You can efficiently utilize Firebase services through the command line, improving your development process, and unlocking the full potential of Firebase features in your Flutter applications.

Copyright ©2024 Educative, Inc. All rights reserved