# Setting environment variables in a ray cluster

**URL:** <https://discuss.ray.io/t/setting-environment-variables-in-a-ray-cluster/1108>\
**Category:** Uncategorized\
**Created:** [March 3, 2021, 7:40pm UTC](https://discuss.ray.io/t/setting-environment-variables-in-a-ray-cluster/1108 "2021-03-03T19:40:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [March 3, 2021, 7:40pm UTC](https://discuss.ray.io/t/setting-environment-variables-in-a-ray-cluster/1108/1 "2021-03-03T19:40:34Z")

</div>

I would like to set an environment variable in my ray cluster to be available to the head and all worker nodes. How can that be done?

So after I do ray up cluster.yaml I would like to be able to do a ray attach cluster.yaml and do an echo $VAR and see my value.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [March 3, 2021, 8:19pm UTC](https://discuss.ray.io/t/setting-environment-variables-in-a-ray-cluster/1108/2 "2021-03-03T20:19:09Z")

</div>

So I managed to make this work by using env in the cluster.yaml for both worker and head node types. the only problem is is that value of the variable needs to be hardcoded in the yaml. Although this is fine for regular environment variables for sensitive values it would be nice if there was a way to pass those values by variable name. Is there anything like that supported currently?

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [March 3, 2021, 10:27pm UTC](https://discuss.ray.io/t/setting-environment-variables-in-a-ray-cluster/1108/3 "2021-03-03T22:27:54Z")

</div>

You should be able to provide `override_environment_variables` to `ray.remote`: [API and Package Reference — Ray v2.0.0.dev0](https://docs.ray.io/en/master/package-ref.html#ray-remote)

cc @architkulkarni

---

<div class="post-metadata">

**Author:** ![olly-writes-code](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/olly-writes-code/32/6649_2.png) [@olly-writes-code](https://discuss.ray.io/u/olly-writes-code)\
**Post date:** [October 17, 2024, 10:43pm UTC](https://discuss.ray.io/t/setting-environment-variables-in-a-ray-cluster/1108/4 "2024-10-17T22:43:51Z")

</div>

I have the same question as @doru1004; the provided link seems 404.

I don’t want to have to put any sensitive environment variables in the config file. I’d prefer to commit the config file and inject the environment variables when running `ray up config.yaml`. Something like how docker does it would slick. `docker run -e myhost='localhost'`
