96

Excited that Firebase's hosting is now out of beta. Trying to get going with with the firebase-tools package and I've successfully installed it:

npm install -g firebase-tools

Trying to run any tool fails with

-bash: firebase: command not found

I've tried putting the following command in my .bash_profile without any luck

export PATH=/usr/local/share/npm/bin:$PATH

Any ideas? Pretty new to the command line in general.

Thanks!

cienki
  • 1,639
  • 1
  • 16
  • 14
  • 1
    Normally, CLIs that come with global packages are symlinked into a directory that is expected to be in your `$PATH` already - perhaps this will help: http://stackoverflow.com/a/22767508/45375 – mklement0 May 14 '14 at 05:16
  • My pleasure; *if* you found that linked answer helpful, you can up-vote it too (disclaimer: I wrote it). – mklement0 May 15 '14 at 03:32
  • Restarting Terminal on Mac did it for me (not just reset, but close and reopen). This is probably because Terminal reads .bash_profile when it starts. If you can read .bash_profile directly with another command that might be better. – intcreator Oct 06 '17 at 04:21
  • It is very likely that ```firebase``` was installed under different version of npm. For example, I was using npm 12.19.0, but firebase was installed to npm 10.10.0. I had to ```nvm use 10.10.0```, then firebase was recognized as command. – Danyu Nov 14 '20 at 19:02
  • put 'sudo' in the start, solved my problem: sudo npm i -g firebase-tools – Diego Venâncio Jul 04 '23 at 14:09

34 Answers34

163

Run code below with terminal,

alias firebase="`npm config get prefix`/bin/firebase"
Durul Dalkanat
  • 7,266
  • 4
  • 35
  • 36
73

Installing firebase-tools globally did the trick for me :

npm install -g firebase-tools
slfan
  • 8,950
  • 115
  • 65
  • 78
rsd96
  • 894
  • 6
  • 6
42

You should add the npm bin folder to your bash PATH variable. To do that, run:

npm get prefix

And it should output something like /home/your-username/npm-global or /home/your-username/npm-packages.

Then in your ~/.bashrc or ~/.bash_profile (if you're in a Mac) file, add:

export PATH="/home/your-username/npm-global/bin:$PATH" # Add npm bin PATH

Note the "/bin" after the npm get prefix result.

WhooNo
  • 911
  • 2
  • 12
  • 28
Bruno Peres
  • 2,980
  • 1
  • 21
  • 19
  • 3
    Adding the `bin` file is a critical step. – Jacob May 03 '17 at 16:29
  • 4
    it's " .npm-global " – arora Jun 12 '18 at 04:54
  • this worked for me, adding to the `~/.bash_profile`. Thanks ! – Shudy Jan 24 '19 at 08:14
  • Also for anyone in Ubuntu, I'm initializing zsh in my .bashrc, make sure you `export PATH=...` before initializing zsh, or you can put it in the .zshrc file aswell if you want. – jmoore255 May 09 '19 at 18:11
  • It's not ".npm-global" for everyone. Always run `npm get prefix` to determine PATH prefix. See this post: https://stackoverflow.com/questions/67134511/bash-firebase-command-not-found – WhooNo May 03 '22 at 19:14
25

@mklement0 That answer looks good, but I'm worried it will be intimidating to someone who is so new to the command line. So I'm going to cherry-pick the most relevant piece of it.

@cienki Run this command to see what you should be putting in that PATH prefix in your .bash_profile file:

npm get prefix
Flortify
  • 619
  • 5
  • 15
  • Thanks @Flortify, I found my npm prefix and was able to put it in my PATH. Another newbie question though: I tried putting it in my .bash_profile but it didn't work when I placed it there. I had to run `export PATH=/Users//npm/bin:$PATH` from the command line when in the directory I'm working out of for it to work. What did I do wrong? Thanks! – cienki May 15 '14 at 00:57
  • @cienki `.bash_profile` is only read when the shell starts. So you can either (1) open a new Terminal window (which will start a new instance of `bash`, which will read `.bash_profile` (in other words: if you logout of your machines tonight, it'll suddenly work right in the morning!), or, if you're impatient, (2) you can invoke `source .bash_profile` on the command line, to read/execute it, which is functionally equivalent to invoking that self-same `export`, manually, on the command line, like you did. Cheers! – Flortify May 15 '14 at 01:58
  • +1; note, however, that the `~/.bash_profile`-related advice is **OSX**-specific (on Linux, it would be `~/.bashrc`). – mklement0 May 15 '14 at 02:42
  • 1
    Good point. The Mac OS X `Terminal.app` starts a login shell for each terminal window/tab. And `bash` runs `.bash_profile` for every login shell. But on Linux, opening a new `xterm` does not create a login shell and therefore only runs `.bashrc`. To smooth out the differences, you usually put a `source .bashrc` inside your `.bash_profile`. – Flortify May 24 '14 at 00:45
  • I follow those steps but have same problem –  Aug 12 '16 at 07:29
  • SIMPLY RUNNING THE COMMAND WITH '--save flag' APPENDED TO THE END OF THE LINE SOLVES THE ISSUE. `npm install -g firebase-tools --save` – Collins USHI Feb 15 '21 at 05:04
  • Try this: https://stackoverflow.com/a/67724810/10124696 – Steven Ogwal May 27 '21 at 15:03
17

On macOS: Use

curl -sL firebase.tools | upgrade=true bash

It worked for me

firebase -V

enter image description here

Steven Ogwal
  • 685
  • 6
  • 8
13

by chance if you are using macOS with m1 chip

arch -x86_64 npm i -g firebase-tools

assuming that you haven't set the PATH

export PATH="`npm config get prefix`/bin:$PATH"

That's all and enjoy

Aung Thiha
  • 131
  • 1
  • 3
10

Using Windows 10, Bash
This worked for me:

  1. npm get prefix // to find Path which for me it was C:\Users\User\AppData\Roaming\npm
  2. search "Environment Variables" which located in "System Properties".
  3. Under "System Variables", find the PATH variable, select it, and click "Edit". Click "New" and add the path found with the "npm get prefix" command earlier (which was for me C:\Users\User\AppData\Roaming\npm) Then click "Ok"
  4. Restart Bash

firebase --version //to check firebase version

RitaSyed
  • 101
  • 1
  • 2
6

Bruno's answer did the trick, I only needed to add a dot at npm-global in Ubuntu in .bashrc:

export PATH="/home/your-username/.npm-global/bin:$PATH" # Add npm bin PATH
redderblock
  • 137
  • 1
  • 10
6

Below command works for me on terminal

curl -sL firebase.tools | upgrade=true bash

This command install firebase tool for me

Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68
6

After installing:
$ npm install -g firebase-tools
$ firebase init
-bash: firebase: command not found
"If you are getting the above output then follow the below steps:"

For Windows Users: type this cmd :
$ npm get prefix
C:\Users\Jeet\AppData\Roaming\npm [this is the location]

Now you have to set in enviorenment variable -> (windows+r) -> sysdm.cpl -> Advanced(tab) -> Environment Variables -> under the System Variables -> click on path -> edit -> C:\Users\Jeet\AppData\Roaming\npm [paste] the above location -> apply - ok - ok.

Restart your bash terminal
Thanks!!!

Prasenjit Mahato
  • 1,174
  • 15
  • 10
4

For Mac OS Sierra:

  1. $ sudo npm install -g firebase-tools
  2. To stop other Node process use $ ps aux | grep node
  3. If needed to upgrade or install emulator - $ npm install -g @google-cloud/functions-emulator
  4. Ready to go $ firebase --version
Mark Cooper
  • 6,738
  • 5
  • 54
  • 92
diayn geogiev
  • 101
  • 1
  • 3
4

For anyone using MacOS Catalina 10.15.2 getting the bash PATH variable fixed the issue for me.

Run:

npm get prefix

Then run:

export PATH=/Users/userid/.npm-global/bin:$PATH

Note: I recently upgraded from my old High Sierra MacBook Pro, and was confused as well.

3

For anyone using nvm the error could arise because you are on a different nvm version than you were on when you first installed firebase tools globally. That's what it was for me. When I restarted webstorm nvm switched to a different version.

Run nvm list to check the version you are on and run nvm use x.x.x to switch to the right version where you installed firebase tools originally.

Chip Allen
  • 280
  • 1
  • 2
  • 12
3

This worked for me on Mac (same thing the others have been posting above, just for Mac):

  1. go to your home folder in Finder (named after your user name, in my case "macbook")

  2. press cmd+shift+dot (will reveal hidden files)

  3. go the .npm-global/bin folder and copy its path (Finder menu -> View -> Show Path Bar, right click on the bin folder in the path bar -> "Copy 'bin' as Pathname")

  4. open Terminal (by default the home folder) and go nano ~/.bash_profile

  5. at the top of the file add export PATH="<cmd+v>:$PATH" (will look similar to this: export PATH="/Users/macbook/.npm-global/bin:$PATH")

  6. save .bash_profile changes and restart Terminal, firebase command should work now

3

if you installing firebase-tools using

yarn global add firebase-tools

i got same error then i got answer and execute this

export PATH="$(yarn global bin):$PATH"

and then i can do firebase login pretty well

red
  • 31
  • 1
3

I am on Linux and installing the package with admin privileges resolved the problem:

sudo npm i -g firebase-tools
Aniruddha
  • 774
  • 1
  • 7
  • 18
2

Simply reinstall node.js. This worked for me and fire command was recognized.

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
  • 1
    up voted because this solution worked for me. I believe the problem started after a Visual Studio update that included Node. – Yogi Nov 30 '19 at 22:42
2

This is for updated mac mac Os Catalina(10.15.1+) & on zsh.

  1. Go to Terminal (vim .zprofile)
  2. add this export PATH="/Users/Your Username/.npm-global/bin:$PATH"

Works for me!

Al Mamun
  • 630
  • 2
  • 8
  • 21
2

You forgot sudo type this

sudo npm install -g firebase-tools

problem solved.

Bbub Mum
  • 11
  • 1
2

I know most answers work for all generic 'command not found' errors. Basically by manually setting PATH variable but there's an easier way for this specific problem relating 'firebase command not found':

Try this cURL command and it will fix this issue for good and will minimise any user errors.

Install the Firebase CLI using the automatic install script Run the following cURL command (Mac or Windows):

curl -sL https://firebase.tools | bash

Source: https://firebase.google.com/docs/cli#install-cli-windows, https://firebase.google.com/docs/cli#install-cli-mac-linux

Upakul
  • 21
  • 3
1

Faced the same issue, am a newbie backend guy. Used npm install firebase-tools It doesn't install and you can't run. I tried looking at the forums and here's what worked for me: sudo npm install -g firebase-tools. Then it asks for Permissions when you firebase login. Am using Ubuntu.

DevangK
  • 11
  • 1
  • 1
1

After trying pretty much everything, only one worked for me (I'm on MacOs Catalina):

Try the following in your terminal:

curl -sL https://firebase.tools | bash
This will check the OS of your machine and then install everything else automatically and properly.

The command is from the official Firebase Documentation.

https://stackoverflow.com/a/60474459/1245341

Nathan
  • 53
  • 6
1

After installing

$ npm install -g firebase-tools

Note the directory where it istalled What I did was locate the directory where firebase was installed. In my case C:\usr\local then I copied the three firebase files. I also went into the node_modules folder and copied the firebase tools folder. Then I went to my app directory in file manager and pasted the firebase files, then created a new node_modules folder and pasted the firebase-tools folder.

Now go to your cmd and run

$ firebase init

It should work

Alalade Samuel
  • 574
  • 5
  • 6
1

I tried a lot of things from here and from other forums, but what ended up working for me (and this is more of a work-around) was to download the binary and then open it and it set up all the firebase stuff for me. However, I found that if I moved it after opening it once, it did not work. So first move it to wherever you want to leave it and then run the .exe.

This allowed me to skip configuring the PATH variable which was nice.

I'm on a Windows 10 Pro Education. Hope this helps someone who has a similar struggle.

Ac Hybl
  • 397
  • 3
  • 10
0

Adding to Durul Dalkanat's answer,

Assuming you have executed npm install firebase-tools -g

  1. Firstly get the output of the command of npm get prefix.
  2. Open .bashrc file which is in the home directory and add alias <output of npm get prefix>/bin/firebase at the end of the file.
  3. Run source .bashrc in the home directory.

Enjoy!

The alias of firebase will be the actual firebase path in the main system and this solution should work flawlessly.

Prashanth Wagle
  • 354
  • 5
  • 8
0

if you're windows 8 user, one possible solution is to put the PATH in environment variables manualy...

  1. On the Windows desktop, right-click My Computer.
  2. In the pop-up menu, click Properties.
  3. In the System Properties window, click the Advanced tab, and then click Environment Variables.
  4. In the System Variables window, highlight Path, and click Edit.
  5. In the Edit System Variables window, insert the cursor at the end of the Variable value field.
  6. If the last character is not a semi-colon (;), add one.
  7. After the final semi-colon, type the full path to the file you want to find.

For me it was: C:\Users\ 'username' \AppData\Roaming\npm To get your path put this string in you command line:

$ npm get prefix

Click OK in each open window

Simon
  • 1,754
  • 14
  • 32
0

I tried all the answers above, other SO answers, and GitHub answers but nothing worked. The only thing that worked for me was to save whatever was inside my index.js file temporarily somewhere else, delete the entire cloud functions folder, then reinstall and start everything from the very beginning.

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
0

After many hours trying everything the only thing what helped (on windows) was downloading and installing node again.

Julian
  • 11
  • 1
0

I found a solution.

npm i express firebase-tools

0

If you are admin on your PC, installing firebase and firebase-tools with -g flag should resolve the issue (the path will added to the global PATH variable) but if you are an admin, you may have to add that path yourself.

Seeking help from one of the top answer, issue this command will return the path where firebase is installed

npm config get prefix /bin/firebase

In my case the following is returned.

C:\Users\*user_name*\AppData\Roaming\npm

Copy that path (from first line) and visit this page on how to update path variable (Window + x then visit systems > Advance Settings). Here add a new entry in path and past that path there. Firebase command should work from command prompt every time without the use of alias required.

TheTechGuy
  • 16,560
  • 16
  • 115
  • 136
0

If you are still experiencing difficulties and none of the provided solutions have resolved your issue, it might be worth considering the following:

I consistently encountered the same error message:

firebase: command not found

or

C:\Users\[USER]\AppData\Roaming\npm/node_modules/node/bin/node: No such file or directory 

within the Windows bash environment.

In my case, the problem arose because I failed to properly read the repository instructions for NVM in order to delete all Node.js files. Unfortunately, I had both NVM and Node.js installed simultaneously. Additionally, I deleted the entire

C:\Users\[USER]\AppData\Roaming\npm

and

C:\Users\[USER]\AppData\Roaming\npm-cache 

folders and reinstalled everything.

And then it worked.

dejonda
  • 21
  • 2
0

On your CLI run this command:

alias firebase="`npm config get prefix`/bin/firebase"
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Umer Baba
  • 285
  • 3
  • 4
-1

None of above solutions worked, since I was using nvm for node versions

so instead of npm i -g firebase-tools

Use sudo npm i -g firebase-tools

Done!

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73
-1

npx firebase login worked for me.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 24 '22 at 16:02