__ __ _ _____ _
| \/ | | | __ \ | |
| \ / | | _| | | | ___ | |_ ___ _ ____ __
| |\/| | |/ / | | |/ _ \| __/ _ \ '_ \ \ / /
| | | | <| |__| | (_) | || __/ | | \ V /
|_| |_|_|\_\_____/ \___/ \__\___|_| |_|\_/
Simplify Your .env Files – One Variable at a Time!
MkDotenv is a lightweight and efficient tool for managing your .env files. Whether you're adding, updating, or replacing environment variables, MkDotenv makes it easy and hassle-free.
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 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 --versionmkdotenv <variable_name> <variable_value>
This will output to stdout the contents of a .env file with the variable <variable_name> having <variable_value> instead of the original one.
If no .env file exists it will just output the <variable_name> having the <variable_value>.
mkdotenv DB_HOST 127.0.0.1
This will output:
DB_HOST=127.0.0.1
If a .env file exists with values:
DB_HOST=example.com
DB_USER=xxx
The final output would be:
DB_HOST=127.0.0.1
DB_USER=xxx
Instead of outputing the .env value you can use the --output-file argument in order to write the contents upon a file.
Also you can use the parameter --input-file in order to select which file to read upon, if omited .env file is used.
Assuming we run the command
mkdotenv --variable-name DB_HOST 127.0.0.1 --input-file=.env.example
This will read the .env.example and output:
DB_HOST=127.0.0.1
mkdotenv --variable-name DB_HOST 127.0.0.1 --output-file=.env.production
This would create a file named .env.production containing:
DB_HOST=127.0.0.1
Assuming we have a file named .env.template containing:
DB_HOST=example.com
DB_USER=xxx
DB_PASSWORD=zzz
And we want to create a file named .env.production containing
DB_HOST=127.0.0.1
DB_USER=xxx
DB_PASSWORD=zzz
We have to run:
mkdotenv --variable-name DB_HOST 127.0.0.1 --input-file .env.template --output-file .env.production
You can provide a .env via a pipe, for that you must provide the value - upon --output-file argument. A common use is to replace multiple variables for example:
mkdotenv --variable-name DB_HOST --variable-value 127.0.0.1 --output-file=- | mkdotenv --variable-name DB_USER --variable-value maiuser --output-file=- | mkdotenv --variable-name DB_PASSWORD --variable-value XXXX --output_file .env.production
Or in case you want to update .env:
mkdotenv --variable-name DB_HOST --variable-value 127.0.0.1 --output-file=- | mkdotenv --variable-name DB_USER --variable-value maiuser --output-file=- | mkdotenv --variable-name DB_PASSWORD --variable-value XXXX --output_file .env
Mkdotenv is also shipped via docker image. Its intention is to use it as a stage for your Dockerfile for example:
FROM pcmagas/mkdotenv AS mkdotenv
FROM debian
COPY --from=mkdotenv /usr/bin/mkdotenv /bin/mkdotenv
Or alpine based images:
FROM pcmagas/mkdotenv AS mkdotenv
FROM alpine
COPY --from=mkdotenv /usr/bin/mkdotenv /bin/mkdotenv
Or temporarily mounting it on a run command:
RUN --mount=type=bind,from=pcmagas/mkdotenv:latest,source=/usr/bin/mkdotenv,target=/bin/mkdotenvYou can also run it as standalone image as well:
docker run pcmagas/mkdotenv mkdotenv --versionIf you want to manipulate a .env file using the docker image. You can use it like this:
cat .env | docker run -i pcmagas/mkdotenv mkdotenv --variable-name DB_HOST --variable-value 127.0.0.1 > .env.newOr if you want multiple variables:
cat .env | docker run -i pcmagas/mkdotenv mkdotenv --variable-name DB_HOST --variable-value 127.0.0.1 | docker run -i pcmagas/mkdotenv mkdotenv --variable-name BIG --variable-value BROTHER > .env.newKeep in mind to use the -i argument upon docker command that enables to read the input via the pipes. If omited the mkdotenv command residing inside the container will not be able to read the contents of .env file piped to it.
If running the pcmagas/mkdotenv image as is the arguments --env-file,--input-file and --input-file will result an unsuccessful execution of mkdotenv.
If a .env file needs to be manipulated either pipe the outputs as shown upon examples above or extend the pcmagas/mkdotenv using a your own Dockerfile providing a necessary volume:
FROM `pcmagas/mkdotenv`
RUN mkdir app
VOLUME app
These do not apply if following the instructions shown into Upon Image building section.
No volumes are provided with this image, also no ports are exposed with docker image as well.