Setting environment variables allows you to reference sensitive data, like passwords and API keys in an application, without making them publicly visible online or in a public repository.
Example:
1 2 |
user_name: "my_actual_username" password: "my_actual_password" |
becomes…
1 2 |
user_name: ENV["USERNAME_VARIABLE"] password: ENV["PASSWORD_VARIABLE"] |
To do this, first check to make sure you are using a bash shell:
1 |
echo $SHELL |
Then edit your “~/.bashrc” file and add:
1 2 |
export YOUR_USERNAME="yourusername" export YOUR_PASSWORD="yourpassword" |
Save the file and you’re all set. You will have to open a new shell or restart your terminal to continue.