From the course: Data Pipeline Automation with GitHub Actions Using R and Python

Setting an environment variable

- [Instructor] In this video, we will learn how to store the EIA_API_KEY as an environment variable on the Mac operating system. We will use the terminal to set the environment variable. There are a couple of ways to store environment variables in MacOS. We will use the .zshenv file, which as its name implies, it is designated file to store environment variables, which will be available to any application upon their launch. Let's now on the terminal open the .zshenv using Vim. I'm in the root folder, and the .zshenv file should be located under the root folder. So let's do Vim .zshenv, and here we go. And as you can see, the file is empty. To add the environment variable, click I to switch from the view to insert mode. As you can see, I clicked I, and now this is indicated I'm in insert mode. Now, let's set a variable by calling the variable EIA_API_KEY. I'm using all uppercase. You can choose either way. And let's assign the value. I copy/paste the value of my API key, and I will put it over here. Now, before we go ahead and save the file, let's add export command before to make sure that this will be available to any application. Export, type here export, space, and we are ready to save the file. To save the file, we first need to exit insert mode by clicking escape. Now, click column and type W to wright and Q quit. Note that by default, the terminal sourced the .zshenv file during the terminal launch. So any changes made afterward won't be automatically sourced. So for example, if you try to print the variable with the echo command, let's type echo, dollar sign, and EIA_API_KEY, it's empty. So either you can close the terminal or to source this file, and you will be able to see the file. So let's test it. Source .zshenv, and let's try again to print. And as you can see, now, the variable is available. And if you open a new terminal window and try to run again, it should be there. Last but not least, the process in Linux-based OS should be similar. Be aware that for Windows OS, the process of saving environment variables might be a little bit different, but the way you're going to load it will be the same.

Contents