env: Usage, Options & Common CI Errors
env shows the current environment or launches a command with variables set or cleared.
env both inspects the environment and runs a command under a controlled one. In CI it is the way to set a variable for just one command, and to clear the environment for hermetic runs.
What it does
With no arguments env prints the environment. Given VAR=value pairs and a command, it runs that command with those variables added or overridden. With -i it starts from an empty environment.
Common usage
env # print all variables
env | sort | grep CI_
NODE_ENV=production env node app.js # set for one command
env -i PATH=/usr/bin sh -c 'echo $HOME' # clean environment
env VAR=val ./script.shOptions
| Item | What it does |
|---|---|
| VAR=value | Set/override a variable for the command |
| -i / --ignore-environment | Start with an empty environment |
| -u NAME / --unset | Remove a variable |
| -C <dir> / --chdir | Change directory first (GNU) |
| (no args) | Print the current environment |
Common errors in CI
env: "node": No such file or directory - common from a #!/usr/bin/env node shebang when node is not on PATH; ensure the tool is installed and PATH is set. With -i you wipe PATH too, so the command may not be found unless you re-add PATH=. env does not expand quotes the way the shell does; remember it sets variables only for the single command it launches, not the rest of the script (use export for that).