0

I am using Kali linux:

lsb_release -a

"
Distributor ID: Kali
Description:    Kali GNU/Linux Rolling
Release:        2021.2
Codename:       kali-rolling
"

i set env variable

export DB_USER=something

it work but when I close the tab, it does not recognize anymore. I am setting env variable for my django project. When I set on "pycharm" terminal, it sets it.

   printenv  DB_USER

But when I close pyhcarm, printenv DB_USER does not show any value.

I set it on terminal using one of the tabs. Again, it sets it but when I close the that specific terminal, it does not recognize that env value anymore.

When I checked zshenv file:

 nano /etc/zsh/zshenv

I have this on this file

if [[ -z "$PATH" || "$PATH" == "/bin:/usr/bin" ]]
then
        export PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
fi

the only env variable zsh has PATH. but when i run env command i see a big list of env variables but they are not in "zshenv".

2 Answers 2

0

Each terminal, whether the system terminal, the Pycharm terminal, or anything else, is a different shell session and different environment. What you set in one isn't going to be there in another.

If you want it to be available across sessions, then you'll need to edit the file/etc/zsh/zprofile, etc/zsh/profile, or /etc/zsh/zshenv and add export DB_USER=something. That will source it at login for zsh which is the shell that you are using. Depending on what you are doing, it's best to use the latter init script so that it is sourced for any shell init.

2
  • Nasir, I updated my question based on your answer. i had a little brain left, I am about to lose it :)
    – Yilmaz
    Oct 8, 2021 at 23:54
  • @Yilmaz If you set the variable in /etc/zsh/zshenv or ~/zshrc and then open a new terminal, is the variable then set there? Oct 9, 2021 at 12:31
0

When you set the environment variable the way you have, you are only setting it for the specific session. To set them across all terminal sessions, in your case you should append the following line to the .zshrc located in your home directory(or in /root if you want it for the root account):

export DB_USER=something

For the second part of your question, the path variable is common across all sessions, but the list of env variables you are seeing upon running the env command are all initialized when the terminal session begins, for example, the $USER variable which refers to the user running the session or the $PWD variable which refers to the current working directory. As you can infer, these variables are specific to each instance and are thus defined for individual sessions unlike the path variable, which is common for all instances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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