About

Managing .env files shouldn't be a manual chore. MkDotenv automates the population of your environment variables by resolving secrets from your preferred backends. Just define your requirements in a template, run mkdotenv, and get a ready-to-use .env file for any environment—local, staging, or production.


Setup

Upon windows

Download the exe upon releases page. The exe is ready to run as is cia cmd/powershell:

CMD/Powershell
mkdotenv-windows-amd64.exe -v

Upon MacOs

MacOs Distributions are available either in releases page or via homebrew:

Bash

brew tap pc-magas/mkdotenv
brew install pc-magas/mkdotenv/mkdotenv
mkdotenv --help

Upon Linux

Base on the distribution you run upon you can use the nessesary package manager


sudo add-apt-repository ppa:pcmagas/mkdotenv
sudo apt-get update
sudo apt-get install mkdotenv

sudo dnf install dnf-plugins-core
dnf copr enable pc-magas/mkdotenv 
sudo dnf install mkdotenv

sudo dnf install -y 'dnf-command(copr)'
sudo dnf copr enable pc-magas/mkdotenv 
sudo dnf install -y mkdotenv

sudo zypper install opi
opi copr pc-magas/mkdotenv
sudo zypper install mkdotenv

wget https://github.com/pc-magas/mkdotenv/releases/download/v1.0.1/mkdotenv-1.0.1-r0.apk
apk add mkdotenv-1.0.1-r0.apk
            

export VERSION=v1.0.1
wget -o mkdotenv https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv-linux-amd64 
sudo cp mkdotenv-linux-amd64  /bin/mkdotenv
sudo chmod 755 /bin/mkdotenv

mkdotenv --version

export VERSION=v1.0.1
wget -o mkdotenv https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv-linux-amd64 
cp mkdotenv-linux-amd64  ~/.local/bin/mkdotenv
chmod 755 ~/.local/bin/mkdotenv

mkdotenv --version

Build from source

Step 1: Setup Go and make

Golang is required, for windows and macOs follow oficial instructions. For ubuntu and mint use apt.

Setup Dependencies
sudo apt-get install make golang-1.23*

The make upon MacOs is available via xcode or homebrew.

Step 2: Clone repo

Clone

export VERSION=v1.0.1
git clone --depth 1 --branch ${VERSION} https://github.com/pc-magas/mkdotenv.git 
                

Step 3: Compile

Setup
make
make GO=/usr/lib/go-1.23/bin/go


Quick Usage

Step 1: Create a template file:

Create a `.env.dist` template file containing these:

Template file

#mkdotenv(prod):resolve("web/secret")::keepassx(file="mydb.kpbx",password="XXXXX").PASSWORD
DB_PASSWORD=

Step 2: Create a Keepassx file

  1. Create a Group named web.
  2. Inside that group, create an Entry with the Title secret.
  3. Set the Password field of that entry to your actual secret value.

The final structure should be:

  • web (group)
    • secret (entry)
      • Password: [your_password]
      • Title: secret

Step 3: Generate a .env file

Generate .env

mkdotenv --environment prod

The command above would populate the `DB_PASSWORD` value from the password stored upon keepassx db into a new file named `.env`.