• Post Reply Bookmark Topic Watch Topic
  • New Topic

"Overriding" Java command for a local jdk  RSS feed

 
Rafael Ito
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everyone!

I'm having a big time problem here. I'm accessing remotely a cluster (by SSH) to run some pretty big amount of data. To run all that data I'm using a program called Trinity (it's for RNA sequencing).

Thing is: The Java that is actually installed on that cluster is 1.4, and Trinity requires at least 1.6. Trinity uses Java internally.

Unfortunately, I don't have admin rights on this machine, so I need to run a more recent version of java locally on some folder, in a way that when I call the "java" command on terminal (i.e when Trinity calls for java), the OS will look for my local java, and not the "official" one.

On my desktop Ubuntu machine, I tried this:

- I downloaded version 1.8 of JDK and I tried, somehow, "override" de "java" command of the terminal (at least locally) by going to a random folder by terminal and typing "export JAVA_HOME=/home/rafael/Applications/jdk1.8.0_25/bin"
- I also tried "export JAVA_HOME=/home/rafael/Applications/jdk1.8.0_25/bin/java"
- Unfortunately, every time I used the commando "java -version", it returned me 1.6, which is the actual version that is currently installed on my desktop machine, and not my local one.

Would you please explain to me what am I doing wrong?

Thanks in advance!

 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAVA_HOME is used by the JDK tools, not by terminal shell. What you want to do is tell the terminal shell which java executable to use, and to do that


Update: Sorry, I had included the "java" in PATH by mistake. It should just be the /bin directory. Thanks to Tim for showing the correct path.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

If you are using the Bash shell, another way to do that is to edit the .bashrc file in your ~ directory by adding exactly the same line. you should update that file whenever you download a new JDK.
 
Tim Holloway
Saloon Keeper
Posts: 18799
74
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Rafael!

JAVA_HOME is not part of the Java spec or implementation, it's a convention used by many - but not all - Java products for things like defining a JVM to a run script.

Ordinarily, it's sufficient to do one of the following:

1. Explicitly specify the execution path of the Java executable that you wish to use on the execution command line. The location of the other JVM files is inferred relative to that point. So, for example:

/usr/java/jre-6.3.1u375/bin/java -jar /opt/myapp/lib/runme.jar

(the Java version in question is fictitious, but the command syntax is real).

2. Add the desired JDK/JRE's primary bin directory to the PATH of the executing user's environment, either via a sourced script or from an environment spec such as the $HOME/.bashrc file:

export PATH=/usr/java/jre-6.3.1u375/bin/;$PATH

Which is what I usually do.

Since you're using Ubuntu, however, there's a third possibility.

There's this horrible cryptic subsystem available in Debian/Ubuntu and Red Hat Linux distros called "alternatives". It's designed to allow different users to use different applications (from a small set of pre-defined applications, including Java) while not mandating that the same app be used by all users on the system. I suggest you do a search on "linux alternatives java" and read the docs that you find, because frankly, I've never really gotten comfortable with it and prefer to simply use brute force (options 1 and 2 above).
 
Rafael Ito
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked like a charm!

Thank you so much, guys!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!