Skip to main content

How to set an environment variable on MacOS

What is an environment variable?

When to use an environment variable?

How to delete an environment variable?

unset ENV_KEY

How to create, view, and access an environment variable

Create an ENV

To create an ENV be sure to use the export command in the terminal.

export ENV_KEY="env_value"

View ENVs

In the terminal, type the command printenv. A list of avaliable commands will appear.

Output

SHLVL=1
OLDPWD=/Users/username
ZSH=/Users/username/.oh-my-zsh
...
ENV_KEY=env_value

Read an ENV

echo ENV_KEY

Output

env_value

What is a Env File?

Steps:

1. View avaliable environment