Skip to content

Instantly share code, notes, and snippets.

@rmtuckerphx
Last active November 3, 2025 07:36
Show Gist options
  • Save rmtuckerphx/4ace28c1605300462340ffa7b7001c6d to your computer and use it in GitHub Desktop.
Save rmtuckerphx/4ace28c1605300462340ffa7b7001c6d to your computer and use it in GitHub Desktop.
Steps to install direnv on Windows

direnv on Windows

Overview

In JavaScript projects, I used to use dotenv so that I could put local environment variables in a .env file for local development. But dotenv requires you to add code to your project. With direnv, you can put local env vars in a .envrc file and those env vars are loaded automatically in the shell.

Steps to install

For these steps, it is assummed that you have installed Git Bash on Windows. I also use VSCode as my editor.

  1. Create a folder such as c:\tools to put the direnv.exe file and add it to the Windows PATH
  2. Go to https://github.com/direnv/direnv/releases to find the latest release of direnv.
  3. Click on direnv.windows-amd64.exe to download the file
  4. Copy the file to c:\tools and rename to direnv.exe
  5. Open the Git Bash terminal and execute $ echo ~ to find the location in Windows of the user's home directory
  6. If a .bashrc file doesn't exist in the user's home directory, create one
  7. Follow the instructions at https://direnv.net/docs/hook.html#bash and add the following text to .bashrc: eval "$(direnv hook bash)"
  8. In your node project directory, create a file: .envrc with key and values as follows:
export KEY1=value1
export KEY2="value2"
  1. From a Git Bash terminal open to the same location as the .envrc file, enter the command: direnv allow
$ direnv allow
direnv: loading /c/dev/myproject/.envrc
direnv: export +KEY1 +KEY2
  1. To test that the values are loaded:
$ echo $KEY1
value1

$ echo $KEY2
value2

NOTE: after a change to the .envrc, you must again execute direnv allow

@g-hamilton
Copy link

Create a folder such as c:\tools to put the direnv.exe file and add it to the Windows PATH

Can you please advise exactly how to complete this step, assuming I follow the same file and folder structure in your example?

I can't figure out how to get the PATH setup correctly.

My .bashrc file includes only the line:

eval "$(direnv hook bash)"

.. and when I start a new Git Bash terminal I get the error:

bash: direnv: command not found

@majidaldo
Copy link

Create a folder such as c:\tools to put the direnv.exe file and add it to the Windows PATH

Can you please advise exactly how to complete this step, assuming I follow the same file and folder structure in your example?

I can't figure out how to get the PATH setup correctly.

My .bashrc file includes only the line:

eval "$(direnv hook bash)"

.. and when I start a new Git Bash terminal I get the error:

bash: direnv: command not found

winget install direnv

@W1M0R
Copy link

W1M0R commented May 30, 2024

This solution suffers from the path name mangling issue as described here: direnv/direnv#343

@daveromsey
Copy link

I ran into this issue as well and found a solution that has worked!

Instead of adding eval $(direnv hook bash) to your .bashrc, try the following snippet:

export _unmangle_direnv_names='PATH'
_unmangle_direnv_paths() {
    for k in $_unmangle_direnv_names; do
        eval "$k=\"\$(/usr/bin/cygpath -p \"\$$k\")\""
    done
}
eval "$(direnv hook bash | sed -e 's@export bash)@export bash)\
_unmangle_direnv_paths@')"

All credit to Tony Garnock-Jones

Source post with more context: https://eighty-twenty.org/2024/01/04/direnv-path-unmangling-on-windows#:~:text=Instead%20of%20adding,_unmangle_direnv_paths%40%27)%22

@danieloemenike
Copy link

For anyone having difficulty installing direnv on windows. Just use Winget. It worked smoothly for me.
From Command Prompt, just run the command "winget install direnv"
Accept the conditions and it will install automatically afterwards.
Then open a new terminal and check the version with "direnv --version"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment