/* Code-Comments */

Setting Persistent Environment Variables

November 10, 2019

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.


Stephen Weiss

Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!