1

I have downloaded jdk-7u9-linux-i586.rpm from oracle. Then I installed it in my Ubuntu 12.04 LTS. Then I set the environment path as :

 export JAVA_HOME=/usr/java/<the jdk directory I cant recall now>
 export PATH={$PATH}:{$JAVA_HOME}/bin

Then I checked by echo $PATH and echo $JAVA_HOME. Now it is showing correct paths.

BUT THE PROBLEM IS : IF I TRY java IN THE CONSOLE IT IS SHOWING UNRECOGNIZED COMMAND ERROR.

Please help me.

6
  • Sorry, it it usr/java/<java directory>/bin. and it is there for sure, I have checked. Commented Nov 19, 2012 at 14:10
  • shouting wouldn't get you answers any faster than they usually do. Commented Nov 19, 2012 at 14:11
  • try: export PATH=$PATH:$JAVA_HOME/bin but before that try $JAVA_HOME/bin/java -version Commented Nov 19, 2012 at 14:12
  • what is the output ` ls -l $JAVA_HOME/bin/java`? Commented Nov 19, 2012 at 14:13
  • It will help you !! cyberciti.biz/faq/linux-unix-set-java_home-path-variable Commented Nov 19, 2012 at 14:13

3 Answers 3

2

You changed your PATH, but did you re-source and refresh your PATH cache ? (see here for more details, and check section 3)

e.g.

$ vi ~/.profile
$ . ~/.profile
$ echo $PATH # is this right ?

and a possible hash

$ hash
Sign up to request clarification or add additional context in comments.

1 Comment

Everytime I echo $PATH, I get the path to my jdk's bin directory. But "java" does not work directly.
1

If you simply call export in a shell, you will set the variables exactly for this one environment. If you want those variables to be there for all shell environments, add them to your ~/.bashrc or your ~/.profile files.

EDIT: I think, using a RedHat-specific packages (.rpm) on Ubuntu may be a cause of your issue - this is a rather wild guess though. You could either remove your current installation and try a different package, or better yet, install java using your regular packgage manager:

sudo add-apt-repository ppa:webupd8team/java 
apt-get update 
sudo apt-get install oracle-java7-installer

3 Comments

I get the actual path to the bin directory of jdk if I echo $PATH. But the executable does not work directly, works only if I specify the full path. Ex. : /usr/java/<jdk path>/bin/java
@AryasindhuSahu this is very strange. I cannot image how this could happen. As you seem to have double-checked the path in question, I would reinstall the JDK using a regular package manager and try again.
I could have installed it from console also, but I needed a copy of the jdk for future requirements. So I downloaded that.
0

Finally I got it.
It was all my mistake. I have set the PATH variable in the /etc/environment file and it was set wrongly. I set it upto jdk folder and not /bin after that.

After changing it to bin, I logged out and logged in again.
Now it is working fine.

Sorry guys for wasting your time and efforts.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.