Please excuse what appears to be a question answered before, but if I read 10 different posts I find 20 different responses.
I just installed Fedora 25. I am going to be learning Java development and need to set up my environment. I will be using openjdk and have installed java-1.8.0-openjdk-devel. I will also be using Maven.
Now I need to set my $PATH
and $JAVA_HOME
variables.
I tried the answer found here (Fedora OpenJDK Set JAVA_HOME)
but after adding to my .bashrc
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and then testing, I get what appears to me to be the wrong answer because I do not think there should be a /jre/ on the end
> echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-1.b14.fc25.x86_64/jre/
So can I please ask what I should set JAVA_HOME to so that I do not need to update it with every openjdk update?
After that I think PATH is just
export PATH=$JAVA_HOME/bin:$PATH
this seems like such a straightforward thing to do yet it seems to me there is much confusion. thx
PS also, is .bashrc even the correct place? because I see here (https://askubuntu.com/questions/175514/how-to-set-java-home-for-java) that /etc/environment would be more appropriate) thx
I suggest create an alias command, modifying bashrc and set JAVA_HOME
into bash_profile, this:
Create command in the bashrc:
alias set-java='sudo alternatives --config java;export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::");source ~/.bash_profile'
Save and execute: source ~/.bashrc
Create generic JAVA_HOME
in bash_profile:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
PATH=$JAVA_HOME/bin:$PATH
Execute the alias command