Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Export Command Not Found Windows: Fix It Fast

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The export command is a Unix shell built-in, so it does not exist in Windows Command Prompt or PowerShell. To set an environment variable in Windows, use set in Command Prompt or $env:NAME = "value" in PowerShell. If you are following a Linux or macOS tutorial, you are likely in the wrong shell or need to use the Windows equivalent. This guide explains the exact commands and how to make them persistent.

What You'll Need

  • A Windows PC with Command Prompt or PowerShell (both are built in).
  • Administrator rights if you need to set system-wide variables.
  • Basic familiarity with typing commands.

Step-by-Step

  1. Open the correct terminal. Press Win+R, type cmd and press Enter for Command Prompt, or type powershell for PowerShell. You can also search for them in the Start menu. Menu labels can differ slightly by Windows version.
  2. Set a temporary variable in Command Prompt. Type set MYVAR=hello and press Enter. This variable lasts only for the current Command Prompt window. To check it, type echo %MYVAR%.
  3. Set a temporary variable in PowerShell. Type $env:MYVAR = "hello" and press Enter. Check it with echo $env:MYVAR. This also lasts only for the current PowerShell session.
  4. Make a variable persistent for your user account. Open Settings > System > About > Advanced system settings (or search for "environment variables" in the Start menu). In the System Properties window, click Environment Variables. Under User variables, click New, enter the variable name and value, then click OK. Close and reopen your terminal for the change to take effect.
  5. Make a variable system-wide (all users). In the same Environment Variables window, under System variables, click New and add the name and value. You need administrator rights. Click OK on all windows. Restart any open terminals or apps that need the new variable.
  6. Use the variable in a script. In a batch file (.bat), use %MYVAR%. In a PowerShell script (.ps1), use $env:MYVAR. If you need the variable only inside the script, you can also use $MYVAR = "hello" without the env: prefix, but that is a PowerShell variable, not an environment variable.
  7. Remove a temporary variable. In Command Prompt, type set MYVAR= (with nothing after the equals sign). In PowerShell, type Remove-Item Env:MYVAR. For persistent variables, delete them in the Environment Variables window.

Common Mistakes

  • Typing export in Command Prompt or PowerShell. It will always fail because it is not a Windows command. Use set or $env: instead.
  • Forgetting the percent signs or dollar sign. In Command Prompt, read a variable with %NAME%, not $NAME. In PowerShell, use $env:NAME.
  • Expecting set to persist. set only affects the current window. Use the Environment Variables dialog for permanent changes.
  • Not reopening the terminal. Persistent variables are read at process start, so open a new Command Prompt or PowerShell window after changing them.
  • Mixing up user and system variables. User variables apply only to your account; system variables apply to all users. Choose the right section.
  • Using the wrong syntax in scripts. Batch files use %VAR%, PowerShell scripts use $env:VAR. Mixing them causes empty values.

Tips

  • Use set without arguments in Command Prompt to list all current environment variables, or Get-ChildItem Env: in PowerShell.
  • Quote values that contain spaces, e.g. set PATH=%PATH%;C:\My Folder in Command Prompt or $env:PATH += ";C:\My Folder" in PowerShell.
  • For one-off commands, you can set a variable and run a program in the same line: set MYVAR=hello && myprogram.exe in Command Prompt, or $env:MYVAR="hello"; myprogram.exe in PowerShell.
  • If you are following a Linux tutorial, look for the Windows equivalent or use Windows Subsystem for Linux (WSL) where export works. WSL is an official Microsoft feature.
  • Be careful when editing the PATH variable; a mistake can break command resolution. Copy the current value somewhere safe before changing it.

Troubleshooting

  • Still getting "export is not recognized". You are in Command Prompt or PowerShell. Switch to a Unix-like environment such as WSL, or use the Windows commands above.
  • Variable is empty after setting it persistently. Close and reopen the terminal. If it still fails, check that you added it under the correct user or system section and that there are no typos.
  • Command Prompt shows %MYVAR% literally. You are probably in PowerShell, where % is not used for variables. Use $env:MYVAR.
  • PowerShell shows $env:MYVAR literally. You are in Command Prompt. Use %MYVAR%.
  • Changes do not apply to already running apps. Restart the app or sign out and back in. Some services may need a full restart.
  • You cannot edit system variables. You need administrator rights. Right-click the terminal or Settings and choose "Run as administrator" where available.

Frequently Asked Questions

Why does export work on Linux but not Windows?

export is a built-in command of Unix shells like Bash. Windows Command Prompt and PowerShell use different syntax and do not include it.

Can I use export in Windows Subsystem for Linux?

Yes. Inside a WSL Linux distribution, export works as it does on Linux. It affects only that WSL session unless you add it to your shell profile.

How do I set an environment variable permanently in Windows?

Use the Environment Variables dialog in System Properties, or run setx in Command Prompt (for example setx MYVAR hello). setx writes to your user environment and affects new terminals, not the current one.

What is the difference between set and setx?

set sets a variable for the current Command Prompt session only. setx creates or modifies a persistent user or system variable, but it does not change the current session.

Do environment variables set in Command Prompt affect PowerShell?

Only if they were set persistently with setx or the Environment Variables dialog. Temporary set variables exist only in that Command Prompt window.

How do I see all environment variables?

In Command Prompt, type set. In PowerShell, type Get-ChildItem Env:. Both list the variables available to the current process.