Firebase CLI (command line interface) is a robust tool provided by Firebase, empowering developers to seamlessly interact with Firebase services directly from the command line. This streamlined approach simplifies resource management and deployment of Firebase elements, greatly enhancing the integration of Firebase services into your Flutter applications. Now we will walk through the steps to install firebase CLI for Flutter:
Installation Guide
Let’s walk through the step-by-step installation process of Firebase CLI.
Install Node.js
To initiate the installation, you must first set up Node.js, which includes npm (Node Package Manager). Npm is a prerequisite for installing and executing Firebase CLI and FlutterFire CLI.
For Windows & macOS:
- Visit the official Node.js website.
- Download the Node.js installer suitable for your Windows or macOS version.
- Run the installer and follow the on-screen instructions to complete the installation.
For Linux:
To install Node.js on Linux, execute the following commands in your terminal:
sudo apt update
sudo apt install nodejs npm
After installation, verify the installed version of Node.js by using these commands:
node -v
npm -v
Please note that Firebase CLI requires Node.js version 16.13.0 or later.
Install Firebase CLI using npm
Once Node.js is successfully installed, you can proceed to install Firebase CLI using npm. Follow the commands provided below in your terminal:
npm install -g firebase-tools
This command installs Firebase CLI globally on your system, allowing you to access it from any directory using the firebase
keyword.
FAQ: Error Message – “npm ERR! Error: EACCES: permission denied, mkdir ‘/usr/lib/node_modules/firebase-tools'”
Answer: If you encounter the error message mentioned above, it signifies a permission issue. To resolve this, you should execute the npm installation command with administrative privileges using sudo
:
sudo npm install -g firebase-tools
Install FlutterFire CLI
After successfully installing Firebase CLI, the next step is to install FlutterFire CLI, specifically tailored for Flutter applications utilizing Firebase services. Execute the following command in your terminal or command prompt:
dart pub global activate flutterfire_cli
Upon running the command above, the flutterfire
command will be accessible globally.
FAQ: Error Message – “flutterfire: command not found”
Answer: If you encounter the error message stating “flutterfire: command not found,” you can rectify it by ensuring that your Dart SDK’s bin directory is included in your system’s PATH. This will enable the system to locate the flutterfire
command.
Login to Firebase and Test CLI
Once the installation process is complete, it’s essential to log in to the Firebase console. This step allows you to manage your projects directly from the command line using the following command:
firebase login
Executing this command will open a web page where you can provide your credentials to establish a connection to localhost on your machine.
If you happen to be working on a remote machine where accessing localhost is not feasible, you can include the “–no-localhost” flag when running the command.
To ensure that your CLI is functioning correctly, use the following command to list the projects available on the Firebase console:
firebase projects:list
This command should display the same projects as those visible on the Firebase console.
Conclusion
By embracing Firebase CLI, you can efficiently harness Firebase services via the command line. This enhances your development workflow and unlocks the full potential of Firebase features within your Flutter applications.
Learn More:
One thought on “How to install Firebase CLI for Flutter application”