36

In Oracle Enterprise Linux when I type java I am getting

bash: java: command not found

I have installed Java 1.6 and I have the following

sudo update-alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
 + 2           /usr/java/jre1.6.0_24/bin/java

How can I resolve this issue?

Thanks

5
  • when you ran update-alternatives --config java, did you select 2? what happened after you select 2 , then ran java command? do you still get the error, java: command not found ? Commented Jun 28, 2012 at 4:10
  • @Jasonw I did select 2 by typing 2 and after that I am still getting java: command not found Commented Jun 28, 2012 at 4:13
  • 1
    if you do ls -l /etc/alternatives/java, it should symlink to /usr/java/jre1.6.0_24/bin/java . Then you need to check which java is called, which java and the path given (e.g. /usr/bin/java) , it should symlink to /etc/alternatives/java Commented Jun 28, 2012 at 4:38
  • @Jasonw I have resolved the issue by the below mentioned solution by devsundar. Thanks anyway. Commented Jun 28, 2012 at 5:34
  • 1
    yes, that configuration is per user basis. The one with alternative is applicable to system wide. But if you are happy with the solution, that's great! :) Commented Jun 28, 2012 at 5:49

8 Answers 8

63

You can add one of the Java path to PATH variable using the following command.

export PATH=$PATH:/usr/java/jre1.6.0_24/bin/

You can add this line to .bashrc file in your home directory. Adding this to .bashrc will ensure everytime you open bash it will be PATH variable is updated.

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

1 Comment

You can also put it in /etc/profile.d/path.sh on ubuntu15x
3

I found the best way for me was to download unzip then symlink your new usr/java/jre-version/bin/java to your main bin as java.

Comments

3

I use the following script to update the default alternative after install jdk.

#!/bin/bash
export JAVA_BIN_DIR=/usr/java/default/bin # replace with your installed directory
cd ${JAVA_BIN_DIR}
a=(java javac javadoc javah javap javaws)
for exe in ${a[@]}; do
    sudo update-alternatives --install "/usr/bin/${exe}" "${exe}" "${JAVA_BIN_DIR}/${exe}" 1
    sudo update-alternatives --set ${exe} ${JAVA_BIN_DIR}/${exe}
done

Comments

2

I had these choices:

-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
 + 2           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   3           /home/ec2-user/local/java/jre1.7.0_25/bin/java

When I chose 3, it didn't work. When I chose 2, it did work.

1 Comment

Hi and welcome to Stack Overflow, this site isn't a forum, it's a question and answer site and your other answer is a question. Please don't do this, thanks!
2

just run this command

sudo apt install default-jre

Comments

2

When you use:

$ sudo update-alternatives --config java

You can create a link to the java executable file in /etc/alternatives/java.
But if you don't see the OpenJDK you just installed, you can create the link directly with:

$ sudo ln -sf /usr/java/jre1.6.0_24/bin/java /etc/alternatives/java
$ sudo update-alternatives --install /usr/bin/java java /usr/java/jre1.6.0_24/bin/java 1

Then you can test it to prove that it works:

$ java -version

2 Comments

Welcome to Stack Overflow! "We're a little bit different from other sites." Your answer could be improved with additional supporting information. If possible, please edit your post to add further details, such as explanations or documentation, so that others can understand how to solve the problem. You can find more information in How do I write a good answer? - "Brevity is acceptable, but fuller explanations are better." It might be helpful to review some highly upvoted answers as examples to follow. Thanks!
Also, I've fixed your formatting, but please see How do I format my posts using Markdown or HTML? and the Markdown help. Helpful Hint: You can click "Edit" under any question or answer to see how it was formatted.
1
  1. Execute: vi ~/.bashrc OR vi ~/.bash_profile

(if above command will not allow to update the .bashrc file then you can open this file in notepad by writing command at terminal i.e. "leafpad ~/.bashrc")

  1. add line : export JAVA_HOME=/usr/java/jre1.6.0_24
  2. save the file (by using shift + Z + Z)
  3. source ~/.bashrc OR source ~/.bash_profile
  4. Execute : echo $JAVA_HOME (Output should print the path)

1 Comment

Question was Command "java -version" not working Not echo $JAVA_HOME
0

I was having the same problem on my ec2 machine. Below these 2 commands helped me to fix the issue.

sudo yum update

sudo yum install java-11-amazon-corretto

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.