16

I'd like to print all environment variables set on my Heroku server. How can I do that with command line only?

5 Answers 5

28

Ok, I found the way:

heroku config
4
  • 3
    AFAICT this is not actually "all environment variables". Just those set via the config mechanism. Apr 30, 2021 at 9:25
  • Hm, I didn't know. So, could you share how to print actually all of them? Apr 30, 2021 at 13:07
  • 1
    I have no idea, sorry! I came here trying to find out! May 1, 2021 at 17:05
  • This shouldn't be the accepted solution but one of the ones below
    – zardilior
    Aug 24, 2022 at 18:55
13

The heroku run command runs a one-off process inside a Heroku dyno. The unix command that prints environment variables is printenv (manual page). Thus

heroku run -a app-name printenv

is the command you are looking for.

2
  • I wanted to confirm one-off commands were receiving environment parameters from the command line, so this one was useful: heroku run -a appname --env FOO=bar printenv Feb 1, 2022 at 18:50
  • I did run only the command printenv in the web console (More -> Run console) and all environment variables were listed.
    – hiroorih
    Mar 27 at 12:28
5

step 1 : list your apps

heroku apps

Copy the name of your app

step 2 : view config variables of this app

heroku config -a acme-web
2

Append --json to get the output as JSON.

heroku config -a acme-web --json
1

Append -s to get the output in shell format, to paste directly to a .env file, for example.

heroku config -a your-app -s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.