Java on PATH is ignored (Ubuntu/Bash) [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
In Ubuntu I have added the following to my ~/.bashrc
export JAVA_HOME=/home/user/tools/jdk-11.0.4
export PATH=${PATH}:${JAVA_HOME}/bin
export PATH=/home/user/tools/apache-maven-3.6.1/bin:$PATH
But when I run (after a reboot):
$ which java
/usr/bin/java
$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~19.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
Why is it still picking up java 8 from /usr/bin/java?

The locations in the PATH environment variable are searched in order, and the first match for an executable is returned. Since you added JAVA_HOME at the end of the PATH, the global version of java is found first (as /usr/bin comes before JAVA_HOME).
Try this order instead (in the second line of your code above):
export PATH=${JAVA_HOME}/bin:${PATH}
BTW, it is not necessary to reboot each time you change ~/.bashrc. You can just open a new shell terminal.

Related

how to upgrade my MAC OS X to use newer Java compiler? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
This is probably an easy question, but I could not find a clear answer to it by searching on stack overflow. I will delete this thread if its a duplicate. I am on a OS X Yosemite version 10.10.5, and my System.Preferences->java-> general shows that I have version 8 update 66 (build 1.8.0_66-b17). However some code fails due to use of old java compiler.
$javac -version (javac 1.6.0_65)
java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
How can I let my projects use the newest java compiler? (preferably as a systems default)?
After downloading the right jdk/jre #java.com, in your home directory (aka /home/<your name account>), add these lines to file .bash_profile (create file if don't exist and don't forget to replace <version> and change path if needed) :
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk<version>.jdk/Contents/Home
hope this will help you
Download the JDK from Oracle: http://www.oracle.com/technetwork/java/javase/downloads/ . Make sure you get the OSX version. It has its own installer so installation should be pretty straight forward.

"java" command is getting executed but not "javac" command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
My question looks similar to java-comand-works-but-not-javac but its different from the way that I deliberately had removed java bin directory from "path" variable and "JAVA_HOME" so that "java" and "javac" shouldn't be executed without giving full path to "javac" or "java".But still "java" is getting executed. For "javac" it is throwing 'javac' is not recognized as an internal or external command,
operable program or batch file.
But for "java" it is showing C:\Users\Nandi_Gaurav>java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)
I want to know the reason. I am using "Windows-7" .
If the problem is that java running when you don't expect it to1, open up a cmd window and execute:
C:\USERS\Nandi_Gaurav\Documents>where java
C:\Windows\System32\java.exe
You'll almost certainly see that there's one installed in the Windows system directory.
That's why it's still executing even though you think you've removed it from the path.
If you really want to get rid of it, either delete it (assuming it's still available in the JRE/JDK directory) or rename it to something like nojava.exe.
Whatever you do, don't remove c:\windows\system32 from your path, that'll cause all sorts of issues :-)
1 Your problem may also be that javac is not running, in which case the JDK may not be installed. However, based on your question, that doesn't seem to be the issue - you're more concerned about things running when you've tried to disable them, rather than with things not running when they should be.
Java may be executed from the JRE that is installed in another path of your system.
Javac is part of the JDK, so you should install it, and set the appropriate paths.
You need to install Java Development Kit (JDK) which provides javac to compile your java code. You have the Java Runtime Environment (JRE) which is mainly for running java programs.
This question may help: javac : command not found
I think your 'Path'-variable is only used for javac.
Java-configuration in windows can be found here:
Explanation on java.com
Most probable issue could be that you are using JRE instead of JDK.
When you download java you can get it either as jre(Java Runtime Environment) or jdk(Java Development Kit) .
If you just want to run java programs on a machine , install JRE.
if you want to develop , compile and run a java program install JDK.
Both can be downloaded from oracle.Link for JDK 1.6
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR

JRE/java command not found [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm trying to install JRE on Ubuntu 13.10. I followed this guide. When I run "java -version" it says "command not found"...
This is the result of "sudo find / -name java"
/var/lib/dpkg/alternatives/java
/usr/lib/jvm/java-7-oracle/bin/java
/usr/lib/jvm/java-7-oracle/jre/bin/java
/usr/lib/ure/share/java
/usr/local/java
/usr/local/java/jre1.7.0_51/bin/java
/usr/bin/java
/usr/java
Basically command not found happens when you didn't set up the PATH of installed java.
This guide here covers more about how to install java on a ubuntu machine completely, but here I'm just going to present how to setup your java runnable:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_51/bin/java" 1
sudo chmod a+x /usr/bin/java
and then
sudo update-alternatives --config java
Choose the one that has /usr/local/java/jre1.7.0_51/bin/java in the options.
You need to set your Java bin full path /jre1.7.0_51/bin to the PATH variable in your Shell window.
Like this
export PATH:$PATH:/jre1.7.0_51/bin
You can check the existing PATH by typing echo $PATH in your Shell window.

Install Oracle JRE 1.6 on JDK 1.5 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have Oracle JDK and JRE 1.5 installed ubuntu LTS. I want to keep JDK 1.5 and install Oracle JRE as 1.6. please let me know the steps or any clear source where I can get this done
A nice way to do this is by using the webupd8 PPA
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer
To switch which version is used when you type java (or javac etc..) use sudo update-alternatives --config java (or javac of course)

Java on Windows 7 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I've installed java(jre) on window 7. But I am not able to run java from command prompt .
I've set my JRE_HOME to "c:\Program Files (x86)\Java\jre6 " in Environment variables.But still it's not working.kindly help..
Make sure, that the bin folder of your JRE is added to the PATH variable. JAVA_HOME is irrelevant here.
JAVA_HOME is a convention - some tools use that environment variable to pick the location of the right java version. They use it to construct a path like this:
%JAVA_HOME%/bin/java -version
(that should work, by the way)
Add the location of the bin directory to the front of your PATH environment variable.
The simplest way to get a default Java is to go to http://java.com and let it install what it feels like. This will be available in your PATH.
Use this command at cmd (assuming java is installed at "C:\Program Files\Java" and version is 1.6.0):
set path=;"C:\Program Files\Java\jdk1.6.0\bin\";

Categories