This question already has an answer here:

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?

marked as duplicate by jasonwryan, Anthon, Jakuje, Jeff Schaller, garethTheRed Mar 22 '16 at 20:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Please don't post screenshots of text, paste the actual text... – jasonwryan Mar 22 '16 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 '17 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 – Routhinator Jun 28 at 17:10
up vote 8 down vote accepted

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-1.8.0.71-2.b15.el7_2.x86_64"' >> $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.

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

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