setting persistent environment variables

2019-11-10

 | 

~1 min read

 | 

112 words

To make an environment variable available in Bash or Zsh, save the environment to .bashrc or zshrc respectively.

To set the variable, open the respective .rc file:

$ vim ~/.bashrc

Then edit the .bashrc:

# The rest of the .bashrc file…
export VARIABLE_NAME=variable-value

Save, quit, and reload your terminal.

You should now be able to access the environmental variable by name. For example:

$ echo ${VARIABLE_NAME}
variable-value

Related: If you’re using environment variables in scripts (e.g., an NPM install from a private registry) and you get an error:

Failed to replace env in config: ${AUTH_TOKEN}

It’s worth verifying that the variable AUTH_TOKEN is exported.


Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!