# direnv
Source: https://www.jetify.com/docs/docs/devbox/ide-configuration/direnv/index



## direnv[​](#direnv "Direct link to direnv")

***

[direnv](https://direnv.net) is an open source environment management tool that allows setting
unique environment variables per directory in your file system. This guide covers how to configure
direnv to seamlessly work with a devbox project.

### Prerequisites[​](#prerequisites "Direct link to Prerequisites")

* Install direnv and hook it to your shell. Follow
  [this guide](https://direnv.net/#basic-installation) if you haven't done it.

### Setting up Devbox Shell and direnv[​](#setting-up-devbox-shell-and-direnv "Direct link to Setting up Devbox Shell and direnv")

#### New Project[​](#new-project "Direct link to New Project")

If you have direnv installed, Devbox will generate an .envrc file when you run
`devbox generate direnv` and enables it by running `direnv allow` in the background:

````bash theme={null}
➜  devbox generate direnvSuccess: generated .envrc fileSuccess: ran `direnv allow`direnv: loading ~/src/docs/devbox/.envrcdirenv: using devbox
```bash

This will generate a `.envrc` file in your project directory that contains `devbox.json`. Run
`direnv allow` to activate your shell upon directory navigation. Run `direnv revoke` to stop.
Changes to `devbox.json` automatically trigger direnv to reset the environment. The generated
`.envrc` file doesn't need any further configuration. Just having the generated file along with an
installed direnv and Devbox is enough to make direnv integrate with Devbox.

#### Existing Project[​](#existing-project "Direct link to Existing Project")

For an existing project, you can add a `.envrc` file by running `devbox generate direnv`:

```bash
➜  devbox generate direnvSuccess: generated .envrc fileSuccess: ran `direnv allow`direnv: loading ~/src/docs/devbox/.envrcdirenv: using devbox
````

The generated `.envrc` file doesn't need any further configuration. Just having the generated file
along with installed direnv and Devbox, is enough to make direnv integration with Devbox work.

#### Adding Custom Env Variables or Env Files to your Direnv Config[​](#adding-custom-env-variables-or-env-files-to-your-direnv-config "Direct link to Adding Custom Env Variables or Env Files to your Direnv Config")

In some cases, you may want to override certain environment variables in your Devbox config when
running it locally. You can add custom environment variables from the command line or from a file
using the `--env` and `--env-file` flags.

If you would like to add custom environment variables to your direnv config, you can do so by
passing the `--env` flag to `devbox generate direnv`. This flag takes a comma-separated list of
key-value pairs, where the key is the name of the environment variable and the value is the value of
the environment variable. For example, if you wanted to add a `MY_CUSTOM_ENV_VAR` environment
variable with a value of `my-custom-value`, you would run the following command:

````bash theme={null}
devbox generate direnv --env MY_CUSTOM_ENV_VAR=my-value
```bash

The resulting .envrc will have the following:

```bash