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.
setx commands are the Windows equivalent of the Unix
command in CMD.
# 👇️ set 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
# 👇️ set environment variable $env:POST_CODE="abc123" # 👇️ print 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.
You can unset an environment variable by setting it to nothing after the equal sign.
# 👇️ set environment variable set DB_URL=example.com # 👇️ print an environment variable's value set DB_URL # 👇️ unset 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.
setxto set environment values permanently
Here 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
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
This approach also sets environment variables permanently.
You can learn more about the related topics by checking out the following tutorials: