Firebase - Tool Setup
Objectives
- to introduce the Firebase platform
- to set up a sample project and configure the Firebase CLI.
Introduction
Firebase is Google’s mobile computing platform. It provides a variety of services, including user authentication, file storage, and databases that would normally be coded in some sort of remote web application. These services are in such demand that providers such as Google Firebase, Amazon Web Services, and Microsoft Azure have been created to provide these services with minimal custom code, and instead replaced that with a lot of client-side configuration and the use of language-specific libraries to communicate with the services.
AWS, Azure, and Firebase are the biggest names in integrated cloud service. You could use any that you like. In this class, we are using Firebase for a few reasons:
- Firebase services are more streamlined and focused for mobile apps.
- Firebase is easy to use, whereas AWS takes more expertise.
- Firebase is Google, and Google developed Flutter. All Firebase services work with minimal fuss on Flutter.
Installing and configuring Firebase tools
Adding Firebase to our app requires installing and configuring Flutter libraries and setting up a Firebase project in the cloud for your app to use.
You only need to do this step once for each development machine that you use.
- Sign into Firebase using your Google account.
- Install the Firebase Command-Line Interface (CLI):
- For Mac/Linux
Open a Terminal and run the following command. Follow the on-screen instructions:
curl -sL https://firebase.tools | bash
- For Windows on a Personal Machine
- If you already have Node.js v14.18.0 or later installed, go to Step 3.
- Otherwise, download nvm-setup.exe and run it. Follow the prompts using the default settings.
- Open a Command Prompt/Powershell/Terminal and run
nvm install lts
. This will install the latest version of Node.js on your computer. You may need to run the Command Prompt as an Administrator if you have permissions issues. - After installation, you will see a command
Installation complete. If you want to use this version, type nvm use xx.yy.zz
.Type thenvm use xx.yy.zz
command.
- Run the command
npm install -g firebase-tools
- If you already have Node.js v14.18.0 or later installed, go to Step 3.
- For Windows on a Lab Machine
- Download and unzip Node.js. Move the unzipped folder to a permanent location, like your Desktop or Home folder.
- Hit the Windows key and type ‘environment’. Select the “Edit environment variables for your account” option.
- An “Environment Variables” window will pop up. In the top pane, select the ‘Path’ variable and click Edit.
- Click the ‘New’ button then the ‘Browse’ button.
- In the Browse for folder, navigate to the folder where you unzipped Node.js to.
- Open a Command Prompt/Powershell/Terminal and run the command `npm install -g firebase-tools-
- If you get red text with a
SecurityError
, ask the instructor for help. You will need to usePowerShell.exe -ExecutionPolicy Bypass -file C:\<FULL\PATH\TO\YOUR\NODE>\npm.ps1 install -g firebase-tools
.
- If you get red text with a
- For Mac/Linux
Open a Terminal and run the following command. Follow the on-screen instructions:
- In the Terminal (Mac) or Command Prompt (Windows), run
firebase login
. Follow the on-screen instructions and complete the login process in your browser when it pops up. you will see a confirmation message of “Logged in as: your.email@gmail.com”.- If the command cannot be found, try closing and reopening the Terminal/Command Prompt for the Path changes to take effect.
- In the Terminal/Command Prompt, run the command
dart pub global activate flutterfire_cli
- Edit your Path:
- For Windows only:
- Hit the Windows key and type ‘environment’. Select the “Edit environment variables for your account” option.
- Click the “Environment Variables” button at the bottom.
- An “Environment Variables” window will pop up. In the top pane, select the ‘Path’ variable and click Edit.
- Click the ‘New’ button then the ‘Browse’ button.
- In the Browse for folder, go to
This PC/Windows (C:)/*YourLogin* (e.g., laymanl)/AppData/Local/Pub/cache/bin
. Hit “Ok” to close out these screens.
- For Mac/Linux only:
- For Mac: type
nano ~/.zshrc
- For Linux: type
nano ~/.bashrc
- Go to the bottom of the file by pressing your “Page Down” or Down Arrow key repeatedly. Hit Enter to create a new blank line at the end of the file.
- Enter the following exactly:
export PATH="$PATH":"$HOME/.pub-cache/bin"
- Hit Control+X. If asked, hit Y to save changes. Hit Enter to save the file.
- For Mac: type
- For Windows only:
- Close Visual Studio Code if you have it open so that changes will take effect.
Next Steps
You only need to configure the Firebase tools once per development computer that you use.
Now that the tools are ready, continue to Firebase - Per App Configuration to add Firebase to your app.