Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have never used Ubuntu before. How do I go about setting an environmental variable that points to JDK? I installed it on my Desktop. I typed in "EXPORT JAVA_HOME=~/Desktop/jdk" in the command prompt but it didn't work.

share|improve this question
1  
Commands are case sensitive in Linux. The correct command is export. –  Dennis Jun 30 '13 at 23:04
    
Side note: I would generally try to work with absolute paths (/home/user234822/Desktop/jdk). –  Felix Nov 19 '13 at 13:43

2 Answers 2

In addition to xpt's answer:

JAVA_HOME is used internally for some things by the Java runtime. In order to run java or javac or other commands to start with, you need to add the directory those command are in to your path. For example:

export PATH=$PATH:~/Desktop/jdk/bin
share|improve this answer
    
good catch @Ash. Thanks. –  xpt Jun 30 '13 at 23:32
    
@xpt if it is a good catch, it deserves an upvote. –  terdon Jul 1 '13 at 14:15
    
there you go... –  xpt Jul 1 '13 at 21:24

It should work at least in the command prompt session that you just set. Else your ~/Desktop/jdk might not be the correct setting.

To be cautious, do the following:

  1. Open up a command prompt
  2. Type in export JAVA_HOME=~/Desktop/jdk
  3. Try run java, it should be working by now.

If so, do the following:

  1. Still under the command prompt.
  2. Type `echo "export JAVA_HOME=~/Desktop/jdk" >> ~/.bashrc
  3. Log off and log back in
  4. Open up a command prompt
  5. Try run java, it should be working by now.
  6. Anything else (e.g. eclipse) should also be working by now.

HTH

share|improve this answer
    
I think by default Eclipse uses a JRE that it comes with anyway? –  Ash Jun 30 '13 at 23:01
    
Technically speaking, you should actually have the export in your .bash_profile and have .bash_profile source your .bashrc on login. (.bashrc is generally sourced on spawning a shell - so an update to the file [as you suggest] should mean that a logout/in isn't necessary - just open a new shell, .bash_profile is sourced on login). I approved an edit to correct "EXPORT" to "export", but others must approve before it's updated. –  nerdwaller Jun 30 '13 at 23:16
    
thanks @nerdwaller. Yeah, export incorrectly use as EXPORT might be the reason why OP failed. –  xpt Jun 30 '13 at 23:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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