__ __ _ _____ _
| \/ | | | __ \ | |
| \ / | | _| | | | ___ | |_ ___ _ ____ __
| |\/| | |/ / | | |/ _ \| __/ _ \ '_ \ \ / /
| | | | <| |__| | (_) | || __/ | | \ V /
|_| |_|_|\_\_____/ \___/ \__\___|_| |_|\_/
Stop Hardcoding Secrets – Use mkdotenv to Build Your Environment!
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.
- Create a
.env.disttemplate file containing these:
#mkdotenv(prod):resolve("web/secret")::keepassx(file="mydb.kpbx",password="XXXXX").PASSWORD
DB_PASSWORD=
- Setup KeePassXC:
- Create a Group named web.
- Inside that group, create an Entry with the Title secret.
- 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
Consult this youtube video on how save a password on keepassx.
- Run
mkdotenv --environment prod
This would populate the DB_PASSWORD value from the password stored upon keepassx db into a new file named .env.
Have a look upon project's docs folder for mote info.
Compilation required to have make and golang installed. Both Go 1.23 and 1.24 supported.
On Linux Mint and Ubuntu, you can run:
sudo apt-get install make golang-1.23*For other linux distros and macOS follow official instructions https://go.dev/doc/install
You can use either xcode or homebrew. Homebrew method is in https://formulae.brew.sh/formula/make
git clone https://github.com/pc-magas/mkdotenv.gitFor a specific version (e.g v0.3.2) you can also do:
export VERSION=v0.3.2
git clone --depth 1 --branch ${VERSION} https://github.com/pc-magas/mkdotenv.gitmakeIn case you use the golang-1.23 package shipped with ubuntu and linux mint, and unable to run go command line into the shell you can also run this command:
make GO=/usr/lib/go-1.23/bin/gosudo make install(If run as root omit sudo)
Once make install is successfully run golang can be uninstalled if desired, it is a build-only requirement.
If cloned this repo and built the tool you can do:
sudo make uninstallOtherwise you can do it manually:
sudo rm -f /usr/bin/mkdotenv
sudo rm -f /usr/local/share/man/man1/mkdotenv.1
sudo rm -f /usr/local/bin/mkdotenv
sudo rm -f /usr/local/share/man/man1/mkdotenv.1 # Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
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 --versionFor environments that do not provide root access use these commands:
# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
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 --versionrm -rf /bin/mkdotenv
If running ubuntu or Linux mint you can use our PPA repository:
sudo add-apt-repository ppa:pcmagas/mkdotenv
sudo apt-get update
sudo apt-get install mkdotenv
Works in Debian, Mint and Ubuntu (or any other Debian-compatible distros)
# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv_${VERSION}_amd64.deb
sudo dpkg -i mkdotenv_${VERSION}_amd64.debAt code above replace ^found_version^ with the version shown at Detect Latest Version.
Uninstalling the package is easy as:
sudo apt-get remove mkdotenvTested on Fedora
# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget https://github.com/pc-magas/mkdotenv/releases/download/v${VERSION}/mkdotenv.rpm
sudo rpm -i mkdotenv-${VERSION}-1.fc41.x86_64.rpmAt code above replace ^found_version^ with the version shown at Detect Latest Version.
App is delivered via corpr you can install it like this:
sudo dnf install dnf-plugins-core
dnf copr enable pc-magas/mkdotenv
sudo dnf install mkdotenvPackages available through corpr
sudo dnf install -y 'dnf-command(copr)'
sudo dnf copr enable pc-magas/mkdotenv
sudo dnf install -y mkdotenv
Fedora Corpr repositories also are available for OpenSuse (both leap and tumbleweed)
sudo zypper install opi
opi copr pc-magas/mkdotenv
sudo zypper install mkdotenv# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget https://github.com/pc-magas/mkdotenv/releases/download/v${VERSION}/mkdotenv-${VERSION}-r0.apkThere's a pending release for alpine linux on official repositories.
Then as root user run:
apk add --allow-untrusted mkdotenv-${VERSION}-r0.apkAt code above replace ^found_version^ with the version shown at Detect Latest Version.
Mkdotenv is shipped via AUR, use yay to install:
yay mkdotenv
Windows builds are provided as standalone binaries without an installer.
Just download the .exe from releases page ( https://github.com/pc-magas/mkdotenv/releases ) and run it through cmd/powershell:
mkdotenv-windows-amd64.exe
Once downloaded it can be renamed as mkdotenv.exe.
macOS binaries for M Series are shipped via homebrew. For intel based releases compile it from source.
brew tap pc-magas/mkdotenv
brew install pc-magas/mkdotenv/mkdotenv
mkdotenv --helpFor intel macs you need to compile from source
Statically-built binaries that can be converted into executable for M series macOS are also shipped as well.
# Replace with your own release on https://github.com/pc-magas/mkdotenv/releases
export VERSION=v0.3.2
wget -o mkdotenv https://github.com/pc-magas/mkdotenv/releases/download/${VERSION}/mkdotenv-darwin-arm64
sudo cp mkdotenv /usr/local/bin/mkdotenv
sudo chmod 755 /usr/local/mkdotenv
mkdotenv --versionFor usage consult ./docs folder:
- Basic Usage: Bassic Usage of mkdotenv
- KeePassX Resolver: Deep dive into KDBX fields.
- Plain Resolver: Standard variable handling.
- Description Language Definition: The full markup language spec.
- Docker Usage: Running MkDotenv in CI/CD.
Furthermore argument usage is documented via man:
man mkdotenv
Or via --help argument:
mkdotenv --help
