I have been trying to set environment variables that would be saved upon reboot, but without success.

When I set variables using the export or setenv command, as root or any other user, it gets saved on the session until reboot. After reboot, the variables are lost.

In particular, I need to set $JAVA_HOME.

So I do like this

enter image description here

but nothing is working as I indicated.

What am I doing wrong?

  • 2
    Please don't post screenshots of text, paste the actual text...
    – jasonwryan
    Mar 22, 2016 at 18:08
  • 1
    I would argue that this is not a duplicate, the referenced question is not specifically for EL 7 type distros.
    – simon
    Oct 30, 2017 at 8:30
  • @jasonwryan @Anthon This is not a duplicate questions. User environment variables and system wide env vars like the OP is trying to set are different concepts. The linked question references .bashrc and methods that only work for a single user. This question requires a system-wide method such as the one suggested by @tagwint Jun 28, 2018 at 17:10

2 Answers 2


Depending on your shell, there usually has to be a .<shellnamehere>rc file where you can store these variables that you want persisting across logout and reboot events. .bashrc is where you do it if your shell choice is bash

EDIT: in the terminal, run command

env | grep SHELL

if you see SHELL=bash then, run this command:

echo 'export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-"' >> $HOME/.bashrc

this last command have some assumptions. If your SHELL doesn't come up as bash come back here and report what you get. After a logout and login back if you don't see your variable already set, again come back and report what error messages you see, if any.

  • 1
    Your solution is a perfect one. Thank you! Mar 22, 2016 at 18:36

If it is about setting JAVA_HOME system-wide, /etc/profile.d/ would be a good choice.

echo export JAVA_HOME="put path to java home here">/etc/profile.d/javaenv.sh
chmod 0755 /etc/profile.d/javaenv.sh

on your next logon you'll have it

  • 1
    This one is useful so services will have it available as well :)
    – Alfabravo
    Aug 28, 2019 at 19:16

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