flutterflutter-doctor

Flutter won't install as Powershell is not in PATH


[4:27:20 PM] [General] [Info] Flutter is not initialized, running 'flutter doctor' to force...
[4:27:20 PM] [General] [Info] (PROC 14560) Logging data for process...
[4:27:21 PM] [General] [Info] (PROC 14560) Error: PowerShell executable not found.                        
       Either pwsh.exe or PowerShell.exe must be in your PATH.
[4:27:21 PM] [General] [Info] (PROC 14560) exited (1, null)

What is this error and how can I add PowerShell.exe to my PATH?


Solution

  • I'll break it down into two parts: what the error is, and how to fix it

    Error Meaning

    First of all, what exactly are Environment Variables? Quoting Wikipedia:

    An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs.

    With this in mind, why am I mentioning environment variables? Because as your error states, you need to modify your PATH, which happens to be a common environment variable.

    The PATH environment variable stores a collection of directory paths to tell the system where to search, for instance when you call a program name from a terminal.

    Flutter requires Powershell in order to install properly, and uses the command Powershell.exe (referring back to the PATH environment variable) which is typically added to the PATH environment variable by default so it knows where to find and run Powershell. However, in your case, it appears Powershell.exe is not in your PATH, thus the error is produced.

    Adding Powershell to PATH

    To add powershell.exe to your path, open the Edit environment variables for your account app built into Windows (you can access it in the Start menu), select the Path user variable, press Edit..., press New, then enter in C:Windows\System32\WindowsPowerShell\v1.0. Then press Ok on both windows opened and that should add Powershell to your path. You should then be able to (after reloading the terminal) run flutter or whatever you were trying to do earlier.

    Step-by-step if that giant paragraph was hard to read:

    1. Open Edit environment variables for your account (accessible by the Start menu)
    2. Select the Path user variable (under User variables for {your user})
    3. Press the Edit... button under that menu
    4. In the new window that pops up, press New
    5. Enter in C:Windows\System32\WindowsPowerShell\v1.0 and press Ok
    6. Press the Ok button (on the other window) to save your changes
    7. Now (after reloading the terminal) you should be able to use Flutter