You’re on the **home stretch** of your environment setup, and the final step is crucial yet surprisingly easy—as long as you avoid a couple of common pitfalls. This step involves creating a simple file that will secure your sensitive information, like API keys, keeping them out of your source code control (like Git). This practice ensures your secrets are safe.

We’re talking about the .env file.

This article will guide you through creating this file on both Mac and PC.


What is a .env File and Why Do I Need It?

A .env file (short for “environment”) is a common and simple way to store configuration variables—especially sensitive ones, or “secrets”—that your project needs to access. By convention, files named .env are automatically ignored by Git (when a standard .gitignore file is present). This means your API keys and other secrets stay on your local machine and never get accidentally pushed to a public repository.


Step 1: Creating the .env File (Mac)

On a Mac, you’ll use the terminal to navigate to your project’s root directory (the LM_engineering folder you set up previously).

1. Navigate to your Project Root:

cd /path/to/your/projects/LM_engineering

(Replace /path/to/your/projects/ with your actual path.)

2. Create and Edit the File using nano:

We’ll use the command-line text editor nano to create the file.

nano .env

⚠️ The Fussy Rule: The name of the file must be exactly .env. It cannot be mykeys.env, env.txt, or anything else. It is literally a period followed by the letters env.

3. Add Your API Key:

Inside the empty nano editor window, you will add the following line, replacing the placeholder text with your actual OpenAI API key:

OPENAI_API_KEY=scmproj-blahblahblah
  • NO SPACES: Do not have any spaces before or after the equals sign (=).
  • The Mangle Check: Be extremely careful when pasting your key. If you copied it from certain note-taking apps (like Mac’s Notes app), sometimes hyphens (-) can be replaced by long dashes, which will break the key. Always double-check that your key is pasted correctly.

4. Save and Exit:

  • Press Control+O (or Command+O on some Mac setups) to write out/save the file. Press Enter to confirm the filename.
  • Press Control+X to exit the nano editor.

Mac Tip: Seeing Hidden Files

You might not see the .env file when you do a standard directory listing (ls). This is because any file starting with a dot (.) is considered a hidden file on a Mac.

To see all hidden files, use the -a flag:

ls -a

You should now see the .env file listed! You can verify its contents using:

cat .env

Step 2: Creating the .env File (PC/Windows)

On a PC, we’ll use the standard Notepad application, which is a bit simpler than the command line for this specific task.

1. Open Notepad:

Press the Windows key + R to open the Run dialog. Type notepad and press Enter or click OK.

2. Add Your API Key:

In the new Notepad window, add the same line you did for the Mac setup, replacing the placeholder with your actual API key:

OPENAI_API_KEY=scmproj-blahblahblah

3. Save the File (The Trick):

This is where the Windows-specific gotcha is.

  1. Go to File > Save As…
  2. Navigate to your LM_engineering project folder.
  3. Look for the “Save as type” dropdown menu. You must change this from “Text Documents (\*.txt)” to “All Files (\*.\*)”.
  4. In the “File name” field, type .env (literally a period followed by env).
  5. Click Save.

By changing the “Save as type” to “All Files,” you ensure Notepad saves the file with the exact name .env and doesn’t secretly add a .txt extension to it.


Congratulations! You’re Ready

You have successfully created your .env file and secured your API key. This completes your core environment setup!

You are now finally ready to access your environment variables and start running your LLM engineering labs. Congratulations! (Tentative congratulations, at least—let’s make sure it works perfectly in the first lab!)

Leave a Reply

Your email address will not be published. Required fields are marked *