78

I'm trying to install flutterfire_cli in my root project, so I typed this command:

FirebaseFirestore firestore = FirebaseFirestore.instance;

After that, this is the console session (PowerShell):

cd C:\Users\PC\Desktop\eventually
dart pub global activate flutterfire_cli

Output:

Package flutterfire_cli is currently active at version 0.1.1+2.
Resolving dependencies...
The package flutterfire_cli is already activated at newest available version.
To recompile executables, first run `global deactivate flutterfire_cli`.
Installed executable flutterfire.
Warning: Pub installs executables into C:\Users\PC\AppData\Local\Pub\Cache\bin, which is not on your path.
You can fix that by adding that directory to your system's "Path" environment variable.
A web search for "configure windows path" will show you how.
Activated flutterfire_cli 0.1.1+2.

To fix the warning, I added C:\Users\PC\AppData\Local\Pub\Cache\bin to my Path environment variable in the system variables environment. (But it does not work, I'm still getting the warning)

Next, I'm trying to generate the firebase_options.dart file as the documentation says using this command:

flutterfire configure

But I'm getting an error in the console (PowerShell):

cd C:\Users\PC\Desktop\eventually
flutterfire configure

Output:

flutterfire : The term 'flutterfire' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ flutterfire configure
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (flutterfire:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

What am I missing? Why am I getting this error even if the Firebase CLI is already installed on my machine?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mr.Penguin
  • 1,166
  • 1
  • 8
  • 24

19 Answers19

166

Go through this doc very carefully: https://firebase.flutter.dev/docs/cli/

Step 1: Install Firebase CLI

Step 2: Install FlutterFire CLI with this command dart pub global activate flutterfire_cli

While doing this you must notice the following warning

Warning: Pub installs executables into C:\Users\PC\AppData\Local\Pub\Cache\bin, which is not on your path. You can fix that by adding that directory to your system's "Path" environment variable. A web search for "configure windows path" will show you how.

This means you need to add C:\Users\*username*\AppData\Local\Pub\Cache\bin into your System's environment path.

For MacOS run: export PATH="$PATH":"$HOME/.pub-cache/bin"

Step 3: Now flutterfire configure should work.

If still not working play with Firebase commands

Ahmad Khan
  • 757
  • 9
  • 22
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
61

For Mac -> Execute this command:

export PATH="$PATH":"$HOME/.pub-cache/bin"

Yusuf
  • 771
  • 1
  • 6
  • 8
28

Three 3 steps for getting it work on Windows:

  1. Run this command:

    dart pub global activate flutterfire_cli

  2. Type env into Windows search and open Edit the system environment variables --> Environment variables --> System variables( the one on the bottom of the window) --> Double click on Path --> New and enter this:

    C:\Users\PutHereYourUsername\AppData\Local\Pub\Cache\bin

  3. flutterfire configure command should work now - close and open again command prompt or other terminal. Sometimes there is a problem with other editors and terminals where flutterfire configure still does not work. In that case open Command Prompt and it works there for sure.

Elmar
  • 2,235
  • 24
  • 22
17

As for me, I have done everything correctly and the command works if I run in the Windows command prompt, but it fails to work if I type the command inside the VS code terminal.

So I just killed the terminal and opened it again, then it works.

Or, you can try restarting your machine.

  • 2
    You're right; killing the terminal and opening a new one fixed it, after I also added "C:\Users\PC\AppData\Local\Pub\Cache\bin" to path. Also, the installation of the official Firebase CLI is required, it can be found at https://firebase.google.com/docs/cli#install_the_firebase_cli – davidn Jan 10 '22 at 15:20
  • It appears that installing the Firebase CLI binary file does not work, you have to use the npm command which requires node installed. Check out https://stackoverflow.com/questions/70410843/firebasecommandexception-an-error-occured-on-the-firebase-cli-when-attempting-t – davidn Jan 10 '22 at 16:42
  • 1
    I had to restart vsCode for it to work, kinda weird but thanks for the tip – Yasine Romdhane Mar 16 '22 at 01:06
12

Even after adding C:\Users\PC\AppData\Local\Pub\Cache\bin to the path for me flutterfire would not work from the command line, the reason being that it actually instally a flutterfire.bat file.

So I use flutterfire.bat in the command line as of now and that is working.

Ali Nasserzadeh
  • 1,365
  • 7
  • 15
9

For Linux/Ubuntu run this command in the terminal,

export PATH="$PATH":"$HOME/.pub-cache/bin"

Which you will also notice in the terminal when you run the command ↓.

dart pub global activate flutterfire_cli

Munsif Ali
  • 1,839
  • 1
  • 8
  • 22
5
  1. Make sure you are your project directory
  2. run this export PATH="$PATH":"$HOME/.pub-cache/bin"

enter image description here

4

Windows: https://stackoverflow.com/a/70325312/11731185

Mac:

  1. Open Terminal and run:

    dart pub global activate flutterfire_cli
    export PATH="$PATH":"$HOME/.pub-cache/bin"
    
  2. Run: flutterfire --version

  3. If you get a version number, flutterfire has been installed successfully

Ali Solanki
  • 640
  • 7
  • 16
2

For Linux/Ubuntu you should do the following:

  1. Open your .bashrc file using the command "sudo nano ~/.bashrc"
  2. Add export PATH="$PATH":"$HOME/.pub-cache/bin" to the end of the file.
  3. Final you can source the file using "source ~/.bashrc"
  4. It should now be able to recognize the file.
1

for macOS Monterey edit ~/.zprofile instead .zshrc

bl4ckr0se
  • 606
  • 8
  • 15
1

This was the hack i used to solve mine. I copied and pasted the C:\Users\PC\AppData\Local\Pub\Cache\bin in my folder search bar to enter the folder, note I could not find any folder called AppData, but when I pasted it on the folder search it did take me to the bin folder.

In the bin folder, you will find a file called flutterfire.bat. Copy and paste the flutterfire.bat file in the root of your project and then run the .\flutterfire configure command. Please do note the dot (.) and forward-slash (\). You need to add it to work.

Darkhorse
  • 186
  • 2
  • 7
1

for mac m1 , add export PATH="$PATH":"$HOME/.pub-cache/bin" at the top of users/username/.profile , works on (monterey)

abdalmonem
  • 1,367
  • 1
  • 10
  • 19
1

For me, even after I installed everything correctly, restarting my IDE(VSCode) did the trick.

Faisal
  • 113
  • 1
  • 10
0

Flutter command not found Here is very easy instructions for adding something to your path on Mac, It solved my issues with Flutter and Flutterfire.

0

The export PATH="$PATH":"$HOME/.pub-cache/bin" did not work on my Debian machine!

I removed the first line #!/usr/bin/env sh from $HOME/.pub-cache/bin/flutterfire file and the flutterfire command worked properly.

Mohammad Fasha
  • 188
  • 1
  • 9
0

it will not work in GitBash or vsCode terminal , you have to open windows cmd and run it .(after settng up path as already mentioned above)

Ashish168
  • 162
  • 4
  • 14
0

I have had this issue in windows for several hours and I want to share my solution. I downloaded the standalone binary and put it in the parent of my root folder. I then duplicated the .exe and renamed it to firebase.exe and moved it into my flutter project folder. In VSCode I activated the firebase-tools-instant-win.exe to use as my shell (firebase login etc...) In the shell you cd flutter_project\ and then you can run your dart pub global activate flutterfire_cli and flutterfire configure.

Final Structure Outline

  • Repository
    • flutter_project
      • flutter files
      • firebase.exe (duplicated exe)
    • flutter_project_2
    • flutter_project_3
    • firebase-tools-instant-win.exe (use this shell)

I also have added C:\Users\<user>\AppData\Local\Pub\Cache\bin to system env variable: PATH Hope this helps someone... This was a very frustrating problem to solve.

-4

Use command prompt.. not the vsc terminal

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
eeee
  • 17
-4

if you followed the right answer and still not working, you need to restart your computer