This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 9344
    
    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: 37874
    
  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: 9344
    
    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: 37874
    
  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: 37874
    
  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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting JAVA_HOME and override the default
 
Similar Threads
Problems with Java Home in VMBox
Installin Java on Linux
Start exec in current directory from Java
setting PATH variable and linux
Installing Java / Eclipse / Tomcat / Maven on Ubuntu 9.10