Skip to content
MAC FINDER WORKFLOW

How to Create a .env File on Mac (Terminal, VS Code & Finder)

Step-by-step guide to creating a .env file on macOS using Terminal, VS Code, or Finder — without hidden-file confusion, .env.txt extension traps, or macOS dot-file warnings.

NF
✓
Oddmac EditorialCORE TEAM

macOS Finder & Workflow Engineering

5 min read

Quickest Way: Create a .env File on Mac (30 Seconds)

  1. 1Open Terminal: press Cmd + Space, type 'Terminal', hit Enter.
  2. 2Navigate to your project folder: cd ~/path/to/my-project
  3. 3Create the file: touch .env
  4. 4Verify it was created: ls -la (you'll see .env in the list)
  5. 5Open it to add variables: open -e .env (or code .env for VS Code)
Critical Shortcut for Mac Developers

In macOS Finder, press Command + Shift + . (period) to toggle the visibility of hidden dotfiles like .env, .gitignore, and .zshrc. Use this if your .env disappears after you create it.

bash
Terminal commands to create and verify a .env file on Mac
# Navigate to your project folder
cd ~/Development/my-app

# Create the .env file
touch .env

# Optional: Add boilerplate variables
echo 'PORT=3000' >> .env
echo 'NODE_ENV=development' >> .env

# Verify it exists (the -a flag shows hidden files)
ls -la | grep .env

What Is a .env File and Why Does macOS Treat It Differently?

A .env file stores local environment variables that your application reads at runtime. Because it starts with a period, macOS treats it as a system hidden file:

  • Hidden by Default: The moment you create a file starting with '.', Finder hides it unless hidden files are toggled on (Cmd + Shift + .).
  • macOS System Prompt: If you attempt to rename a file to '.env' in Finder, macOS displays a warning that names beginning with a dot are reserved for the system. You must click Use Dot to proceed.
  • The .env.txt Trap: TextEdit often automatically attaches '.txt' to the end of plain text files, resulting in '.env.txt' which your application cannot read.

Method 1: Creating a .env File Using Terminal

  1. 1Open Terminal (press Cmd + Space, type 'Terminal', and hit Enter).
  2. 2Change directory to your project: cd ~/Development/my-project
  3. 3Run: touch .env
  4. 4To verify it exists, run: ls -la (you will see .env in the listing).
bash
Terminal commands to create and verify a .env file
# Navigate to your project folder
cd ~/Development/my-app

# Create the .env file
touch .env

# Optional: Add boilerplate variables
echo 'PORT=3000' >> .env
RECOMMENDED MAC TOOL

Want to create files directly from Finder instead?

Create .env and developer config files in Finder with one right-click.

Try OddMac New File →

Method 2: Creating a .env File in VS Code on Mac

  1. 1Open your project folder in VS Code (File > Open Folder).
  2. 2In the Explorer panel (left sidebar), right-click your project root folder.
  3. 3Select 'New File' from the context menu.
  4. 4Type exactly: .env and press Enter.
  5. 5VS Code creates a clean .env file with no hidden extension — ready to use.
VS Code .env Tip

VS Code has built-in .env file syntax highlighting. Install the 'DotENV' extension (by mikestead) for colour-coded variable names, comments, and string values.

Method 3: How to View .env Files in Mac Finder

  1. 1Open Finder and navigate to your project folder.
  2. 2Press Cmd + Shift + . (the period key) to toggle hidden file visibility.
  3. 3Hidden files, including .env, .gitignore, and .DS_Store, will appear greyed out.
  4. 4Press Cmd + Shift + . again to hide them when done.
Finder Hidden File Warning

Be careful editing hidden system files while dotfiles are visible. Accidentally deleting .DS_Store, .zshrc, or .ssh files can cause unexpected macOS behavior.

Method 4: Creating a .env File Directly in Finder with OddMac

OddMac New File bypasses macOS dotfile warnings and creates clean, properly formatted configuration files:

  • Zero Prompt Friction: Bypasses the 'reserved for the system' dialog box.
  • No Accidental Extension: Never creates '.env.txt' or '.env.rtf'.
  • Pre-Populated Templates: Can automatically include standard variable placeholders (like PORT, NODE_ENV, and DATABASE_URL).
dotenv
Safe standard .env boilerplate template
# Example Local Environment Configuration
PORT=3000
NODE_ENV=development
DATABASE_URL=postgres://localhost:5432/mydb
API_KEY=your_api_key_here

Frequently Asked Questions

Why did my .env file disappear in Finder after I created it?

Files starting with a period are hidden by default in macOS. Press Command + Shift + . (period) in Finder to toggle hidden files and reveal your .env file.

How do I fix a file that was saved as .env.txt?

In Finder, press Cmd + Shift + . to show hidden files. Select the .env.txt file, press Enter/Return to rename it, delete '.txt' from the end, and press Enter. When macOS asks if you want to use '.', click 'Use Dot'.

How do I create a .env file on Mac without Terminal?

Open VS Code, right-click your project folder in the Explorer panel, select 'New File', and type .env. Alternatively, use OddMac New File — right-click in Finder > New File > Developer > .env.

How do I view .env files in Mac Finder?

Press Command + Shift + . (period) in any Finder window to toggle visibility of all hidden dotfiles including .env, .gitignore, and .zshrc. Press the same shortcut again to hide them.

Should I commit my .env file to Git?

No. .env files typically contain local configuration and sensitive credentials. You should add .env to your .gitignore file and commit a sample .env.example instead.

How do I create a .env file on Mac without an extension?

Use Terminal: run 'touch .env' in your project directory. This creates a plain file with no extension. Avoid TextEdit for creating .env files — it will add a .txt extension automatically.

macOS Native · Free to start

Ready to create files directly in Finder?

Add a native New File action to your Mac right-click context menu and ⌥⌘N shortcut. Create Word, Excel, Markdown, and developer dotfiles in two clicks.

Right-Click AnywhereDesktop & all folders
Office TemplatesWord, Excel, Markdown
100% OfflineZero cloud telemetry
Lifetime PurchaseBuy once, keep forever
macOS 12+ · Apple Silicon & Intel (.dmg)Instant drag-and-drop install14-day money-back guarantee