Last updated: Apr 4, 2024
Reading timeยท3 min

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 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.
# ๐๏ธ set an environment variable set DB_URL=example.com # ๐๏ธ print an environment variable's value set DB_URL echo %DB_URL%

If you use PowerShell, you would use the $env: command.
# ๐๏ธ set an environment variable $env:POST_CODE="abc123" # ๐๏ธ print an environment variable's value $env:POST_CODE

However, it is much more intuitive to use CMD to set environment variables, so the following examples use CMD.
You can use the set command to print the values of all environment variables.
set
You can unset an environment variable by setting it to nothing after the equal sign.
# ๐๏ธ 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.
set DB_PORT=1234 set DB_URL=example.com:%DB_PORT% # ๐๏ธ "DB_URL=example.com:1234" set DB_URL echo %DB_URL%

Note that the set command doesn't set environment variables permanently.
The set command:
The setx command:
setx to set environment values permanentlyHere is an example of using setx to permanently set environment values.
setx DB_URL example.com # ๐๏ธ it's still not defined set DB_URL

Instead of separating the variable name and its value with an equal sign,
they're separated with a space when using setx.
setx.However, if I close the shell and reopen it, the DB_URL variable is available.
# ๐๏ธ New shell session (DB_URL=example.com) set DB_URL # ๐๏ธ DB_URL=example.com echo %DB_URL%

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




Click on "OK" twice to confirm the changes.
Close your Command prompt application and then reopen it.
Open a new Command prompt window and display the value of your environment variable.
echo %TEST_VAR% set TEST_VAR

If you want to display the environment variable in PowerShell, you would use the
$env: syntax.
$env:TEST_VAR
This approach also sets environment variables permanently.
You can learn more about the related topics by checking out the following tutorials: