It's not a secret anymore!*
The moose likes Linux / UNIX and the fly likes Setting JAVA_HOME and override the default Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Setting JAVA_HOME and override the default" Watch "Setting JAVA_HOME and override the default" New topic
Author

Setting JAVA_HOME and override the default

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

I wanted to set the JAVA_HOME globally, so I edited the /etc/profile and added the following:



But when I do which java, it still points to /usr/bin/java. How to override that and ask my Raspberry to use the Java version that I want? Should I reboot? I did a source /etc/profile. Isn't that enough?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
You should add your new Java installation to the beginning of the PATH.
It should work whenever you open a new terminal.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Campbell Ritchie wrote:You should add your new Java installation to the beginning of the PATH.
It should work whenever you open a new terminal.


I did the following and I do not see the /usr/bin/java in the PATH. From where is it pulling it?



Yes, I did add it to the beginning of the path and that did the trick!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
There is a similar file somewhere else; I can't remember where. Probably in /etc. I have looked and can't find it on my machine.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Joe Harry wrote: . . .
pi@Menne ~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/softwares/jdk1.7.0_45/bin
When you use which, it finds a “java” in /usr/bin, so that is /usr/bin/java. The which app reports whichever it finds first, and then stops looking. The default java installation is usually in /usr/bin.
Yes, I did add it to the beginning of the path and that did the trick!
Success!
 
 
subject: Setting JAVA_HOME and override the default
 
Similar Threads
Installing Java / Eclipse / Tomcat / Maven on Ubuntu 9.10
Problems with Java Home in VMBox
Installin Java on Linux
Start exec in current directory from Java
setting PATH variable and linux