'export' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
3 min

banner

# 'export' is not recognized as an internal or external command

The error "'export' is not recognized as an internal or external command, operable program or batch file" occurs when we use the export command on Windows, in a CMD shell.

To solve the error, use the set command to set environment variables.

export is not recognized as internal or external command

shell
'export' is not recognized as an internal or external command, operable program or batch file The term 'export' is not recognized as the name of a cmdlet, function, script file, or operable program.

The set and setx commands are the Windows equivalent of the Unix export command in CMD.

cmd
# ๐Ÿ‘‡๏ธ set an environment variable set DB_URL=example.com # ๐Ÿ‘‡๏ธ print an environment variable's value set DB_URL echo %DB_URL%

set environment variable

If you use PowerShell, you would use the $env: command.

PowerShell
# ๐Ÿ‘‡๏ธ set an environment variable $env:POST_CODE="abc123" # ๐Ÿ‘‡๏ธ print an environment variable's value $env:POST_CODE

powershell set environment variable

However, it is much more intuitive to use CMD to set environment variables, so the following examples use CMD.

Note that environment variables in Windows are NOT case-sensitive.

You can use the set command to print the values of all environment variables.

cmd
set

You can unset an environment variable by setting it to nothing after the equal sign.

cmd
# ๐Ÿ‘‡๏ธ set an environment variable set DB_URL=example.com # ๐Ÿ‘‡๏ธ print an environment variable's value set DB_URL # ๐Ÿ‘‡๏ธ unset an environment variable set DB_URL= # ๐Ÿ‘‡๏ธ "Environment variable DB_URL not defined" set DB_URL

You can enclose a variable in percent signs to evaluate its value.

cmd
set DB_PORT=1234 set DB_URL=example.com:%DB_PORT% # ๐Ÿ‘‡๏ธ "DB_URL=example.com:1234" set DB_URL echo %DB_URL%

using variables when setting env-vars

Note that the set command doesn't set environment variables permanently.

If you close the command prompt and reopen it, the environment variable will be undefined.

The set command:

  • modifies the environment variables in the current shell only, and not the other active shells.
  • the modified variables are available in the current shell session but are temporary and get removed if you restart your shell.

The setx command:

  • modifies the environment variables for future shells permanently.
  • the changes are not reflected in currently active shell sessions.
  • you have to close and reopen the shell to be able to access the updated environment variables.

# Using setx to set environment values permanently

Here is an example of using setx to permanently set environment values.

cmd
setx DB_URL example.com # ๐Ÿ‘‡๏ธ it's still not defined set DB_URL

setx environment variables

Instead of separating the variable name and its value with an equal sign, they're separated with a space when using setx.

Notice that the environment variable is not available immediately after being set using setx.

However, if I close the shell and reopen it, the DB_URL variable is available.

cmd
# ๐Ÿ‘‡๏ธ New shell session (DB_URL=example.com) set DB_URL # ๐Ÿ‘‡๏ธ DB_URL=example.com echo %DB_URL%

reopen shell display env vars

An alternative way to set and edit environment variables permanently is to use "Control Panel".

# Using Control Panel to set environment values permanently

To use Control Panel to set environment values permanently:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "System variables" section, click on "New".

system variables click new

  1. In the "New system variable" window, enter a name and a value for the environment variable.

new system variable

  1. Click on "OK" twice to confirm the changes.

  2. Close your Command prompt application and then reopen it.

Note that you must restart your Command prompt shell for the changes to take effect.

Open a new Command prompt window and display the value of your environment variable.

cmd
echo %TEST_VAR% set TEST_VAR

display env var value

If you want to display the environment variable in PowerShell, you would use the $env: syntax.

PowerShell
$env:TEST_VAR

This approach also sets environment variables permanently.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev