Environment variables are helpful when you need to store API keys or other private information but don't want to risk putting those into a script that would be committed to a public place or use information that would be different for other people who use a script.
Where you store an environment variable depends on what shell software you use.
You can figure that out by running echo $0
in your terminal
Below are instructions for what to do if you're using bash or zsh. If you're using a different shell, I assume you already know how to do this.
- open
~/.bash_profile
- scroll to the bottom of the file
- add your variable in the following format:
export VARIABLE_NAME='variable_value'
for instance:
export US_CENSUS_API_KEY='GBOVbxftRxgBqtQTc0AtnQ'
- save the file
- run
source ~/.bash_profile
in your terminal to load your new settings
- In your terminal, run
echo "export VARIABLE_NAME='variable_value'" >> ~/.bash_profile
for instanceecho "export US_CENSUS_API_KEY='GBOVbxftRxgBqtQTc0AtnQ'" >> ~/.bash_profile
- run
source ~/.bash_profile
in your terminal to load your new settings
- open
~/.zshrc
- scroll to the bottom of the file
- add your variable in the following format:
export VARIABLE_NAME='variable_value'
for instance:
export US_CENSUS_API_KEY='GBOVbxftRxgBqtQTc0AtnQ'
- save the file
- run
~/.zshrc
in your terminal to load your new settings
- In your terminal, run
echo "export VARIABLE_NAME='variable_value'" >> ~/.zshrc
for instanceecho "export US_CENSUS_API_KEY='GBOVbxftRxgBqtQTc0AtnQ'" >> ~/.zshrc
- run
source ~/.zshrc
in your terminal to load your new settings