# Set environment variables based on user - for example, use $HOME

**URL:** https://discourse.jupyter.org/t/set-environment-variables-based-on-user-for-example-use-home/24800
**Category:** JupyterHub
**Created:** [March 26, 2024, 10:41am UTC](https://discourse.jupyter.org/t/set-environment-variables-based-on-user-for-example-use-home/24800 "2024-03-26T10:41:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vsessink](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/vsessink/32/12886_2.png) [@vsessink](https://discourse.jupyter.org/u/vsessink)
#### Post date: [March 26, 2024, 10:41am UTC](https://discourse.jupyter.org/t/set-environment-variables-based-on-user-for-example-use-home/24800/1 "2024-03-26T10:41:20Z")

</div>

Hi, I’m a Jupyterhub newbie. I’m setting up a jupyterhub and I’d like to set a user dependent variable, one that depends on $HOME.

I now have changed `jupyterhub_config.py` to include:

```auto
def homeproj(instance):
  import os
  return os.path.expanduser('~' + instance.user.name + '/proj')

c.Spawner.environment = { "PROJ_LIB":homeproj }

```

This works. Is this the “right” way to do this? Or are there better/easier ways?

---

<div class="post-metadata">

### Author: ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)
#### Post date: [March 26, 2024, 12:10pm UTC](https://discourse.jupyter.org/t/set-environment-variables-based-on-user-for-example-use-home/24800/2 "2024-03-26T12:10:50Z")

</div>

Assuming `os.path.expanduser('~' + instance.user.name + '/proj')` returns the correct value that approach looks fine to me. `c.Spawner.environment` is designed to take callables to suport dynamic environment values:

> **[Spawners](https://jupyterhub.readthedocs.io/en/stable/reference/api/spawner.html#jupyterhub.spawner.Spawner.environment)**
>
> Module: jupyterhub.spawner: Contains base Spawner class & default implementation Spawner: LocalProcessSpawner:
