I have installed wsl2,and then installed jdk 17. Now I want to configure JAVA_HOME.
When I do:
$ which java
/usr/bin/java
$ whereis java
java: /usr/bin/java
But I don't see any java folder in /usr/bin.
Instead, I found java in /usr/lib/jvm:
$ pwd
/usr/lib/jvm
$ ls
java-1.17.0-openjdk-amd64 java-17-openjdk-amd64
Why so?
Because java isn't a folder, it's a binary, and probably a link to one of the binaries in jvm directory. You can check where the Java application points to by using ls -al /usr/bin/java
JAVA_HOME shouldn't point to the Java binary, but to one of the directories you've listed in the second example, so something like JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64.
I'd recommend having a look at jenv btw, it helps a lot in switching JDKs should you need it.
Related
I have a centOS7 server, and want to have JDK1.6_15 on it.
I update the /etc/profile scripts to have JAVA_HOME variable correct.
The PATH is also updated with JAVA_HOME in first place.
But, when I launch "java -version" command, I have JDK1.8 OpenJDK displayed !
When I launch the "alternatives --config java" command, I have only :
java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre/bin/java)
So I force things with :
alternatives --install /usr/bin/java java /opt/jdk1.6.0_15/bin/java 1
alternatives --install /usr/bin/javac javac /opt/jdk1.6.0_15/bin/javac 1
It's ok now, but, it seems not really correct to me to do this, it's weird no ?
Is there a way to install properly with yum the OpenJDK1.6 but precisely 1.6.0_15 version, not another ?
Finally, we couldn't do another way, it's the right way, so I let the things like they are
I guess I have messed up big time with my java installation and am now not able to correct this.
Ok, so first, /usr/libexec/java_home -V tells me
Matching Java Virtual Machines (1):
15, x86_64: "Java SE 15" /Library/Java/JavaVirtualMachines/jdk-15.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-15.jdk/Contents/Home
Secondly, Java home is set up properly.
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-15.jdk/Contents/Home
But when I do, java -version, it says
java -version
-bash: /opt/anaconda3/bin/java: No such file or directory
Don't know why it is going to /opt/anaconda3/ directory.
Another thing, I read that /usr/bin/java points to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
and if I want to use the new java version, I need to replace the /usr/bin/java symlink so that it points to /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java instead using,
sudo rm /usr/bin/java
sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin
But, apparently I cannot remove the symlink
rm: /usr/bin/java: Operation not permitted
What should be the approach now?
Windows 7 64-bit, with 64-bit JDK. Cordova plugman 1.4.2-dev. Using cygwin bash as a shell, but I don't see why that would affect anything.
$ echo $JAVA_HOME
"c:\Program Files\Java\jdk1.8.0_25"
$ echo $ANDROID_HOME
C:\Users\admin\AppData\Local\Android\Sdk
$ ls "c:\Program Files\Java\jdk1.8.0_25"
bin include lib release
COPYRIGHT javafx-src.zip LICENSE THIRDPARTYLICENSEREADME.txt
db jre README.html THIRDPARTYLICENSEREADME-JAVAFX.txt
$ ./main.js install --platform android --project ../myproject/ --plugin phonegap-facebook-plugin-gtg --variable APP_ID="1155264567919069" --variable APP_NAME="Voice Test"
Fetching plugin "phonegap-facebook-plugin-gtg" via npm
Installing "phonegap-facebook-plugin" for android
Failed to install 'phonegap-facebook-plugin':CordovaError: Failed to run "javac -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: "c:\Program Files\Java\jdk1.8.0_25"
I've also tried using JAVA_HOME without the quotes. What's going on?
#cubrr gave the correct answer in the comments. The error message being produced by Cordova is extremely misleading: the problem isn't that JAVA_HOME was incorrect, but that javac wasn't on my path. This was made all the more confusing by the fact that java was on my path, so when I checked it gave correct results. This is because the Oracle installer adds a directory to your path (c:\ProgramData\Oracle\Java\javapath) that contains links to java.exe and related programs but not the relevant JDK programs.
1) set > system variables > path to
`;C:\Program Files\Java\jdk1.8.0_xxx\bin;`
2) create new JAVA_HOME path with the value
C:\Program Files\Java\jdk1.8.0_xxx
now check javac version by issuing command at CMD
javac -version
*** don't touch the oracle - "C:\ProgramData\Oracle\Java\javapath;" path
If you are running windows 10, you need to restart your computer after changing the path and other variables. Possibly also on earlier windows versions.
I'm trying to compile a jar on my mac using 1.8 as a target release, but javac fails with the message "invalid target release".
When I run javac -version it gives me "javac 1.6.0_29".
I have the 1.8 jdk installed under "/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk", but even when I run /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/javac -version it gives me "javac 1.6.0_29".
Sym linking the CurrentJDK folder in "/System/Library/Frameworks/JavaVM.framework/Versions/" to the jdk folder in Library didn't change anything. Neither did sym linking the javac inside /usr/bin to the javac in my jdk folder.
Any ideas how to get javac to use my 1.8 version ?
Thank you very much!
UPDATE
My path variables output the following:
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin:/opt/X11/bin:/usr/local/git/bin:/Developer/Tools/Panda3D
echo $JAVA_HOME (since I set it already in order to get javac to work)
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/
Preprending /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/ to the $PATH variable didn't change the output for javac -version either.
UPDATE 2
Other question: What does javac do? Is it executing its code directly or depending on other binaries in the system? If so the link for them could be broken. Otherwise I wonder why executing the binary inside my 1.8 jdk folder gives me the version 1.6.
The proper Debian/Ubuntu way to configure which javac is pointed to by /usr/bin/javac is to use the update-alternatives command. You can do it interactively, and select from a list of available options:
sudo update-alternatives --config javac
and for java:
sudo update-alternatives --config java
In addition to what #Zakaria said, this command will show you all Java packages installed on the system, e.g.:
$ update-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64
This one an overview of the Java tools and which version will be used, e.g.:
$ update-alternatives --get-selections | grep java
...
java manual /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
javac auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
javadoc auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc
...
As shown above here java would run from version 8, and javac from version 7.
If you want to update selections for all of the Java tools in one go try the following replacing the package name with one of your choice:
$ sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
Verify that this has actually worked. If it didn't or partially did you have to resort to a semi-manual way, for example:
$ for i in $(update-alternatives --get-selections | grep java | awk '{system("basename "$3)}'); do sudo update-alternatives --config $i; done
where does the /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK link refer to?
Make sure it refers to the proper JDK
/Library/Java/JavaVirtualMachines/jdk{major}.{minor}.{macro[_update]}.jdk
Please check that both JAVA_HOME and PATH environment variables point to the 1.8 folder and have no link to the 1.6 java folder, especially the PATH.
Check:
echo %PATH%
Set:
export PATH="java8 folder":$PATH
or check this page: Set environment variables on Mac OS X Lion
Do the following steps
In the Windows Search bar, type "environment".
In your environment variables (account), create a variable called JAVA_HOME. Set it to C:\Program Files\Java\jdk1.8.0_65 (or wherever your JDK is).
In your system environment variables, edit PATH. Put this at the beginning of the PATH value: %JAVA_HOME%\bin;
Press OK.
Exit any command windows you are in.
Launch a command window. Type javac -version.
you should get this response: javac 1.8.0_65
I am not sure why "which java" and "whereis java" paths are not correct. I tried to edit ~/.bash_profile and /etc/environment but did not help. The desired path is what is seen in "echo $JAVA_HOME" below but the same is not reflected in "which java"
Below is what I get in CentOS 6.4:
which java
/usr/bin/java
java -version
java version "1.7.0_45"
JAVA(TM) SE Runtime Environment (build 1.7.0_45-b18)
JAVA HotSpot (TM) 64-bit Server VM (build 24.45-b08, mixed mode)
whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java
echo $JAVA_HOME
/usr/java/jdk1.7.0_45/jre => desired shows correct when echo $JAVA_HOME
Run alternatives --config java to pick the Java version you want to use as default. It will print out a list of installed Javas to choose from.
which java, however, will always print out /usr/bin/java. This doesn't mean it's set wrong! Observe:
$ ls -l `which java`
lrwxrwxrwx 1 root root 22 Oct 19 11:49 /usr/bin/java -> /etc/alternatives/java
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 35 Oct 19 11:49 /etc/alternatives/java -> /usr/lib/jvm/jre-1.5.0-gcj/bin/java
If you use alternatives to change the path to IcedTea, ls -l /etc/alternatives/java will reflect that.
Your PATH (and nothing else) determines which directories to look for commands. This is the same in Linux, Solaris, and DOS.
When you do a which {command} it find the first directory you can execute the command in.
When you update your PATH in .bashrc, you have to source it again to change your current settings.
Sometimes alternatives does not work in a single command by selecting the desired version of java. I am not sure of the precise reason for this though..
I fell victim to such a scenario.
The auto-pilot failed, we must fly manual now..
In any of below two files in your unix installation add following variables and a call to a shell script (I have provided below) -
~/.bashrc
export JAVA_HOME=/opt/jdk1.8.0_141
export PATH=$JAVA_HOME/bin:$PATH
sudo bash /appl/common/toFixJava.sh
OR
/etc/profile
export JAVA_HOME=/opt/jdk1.8.0_141
export PATH=$JAVA_HOME/bin:$PATH
sudo bash /appl/common/toFixJava.sh
The script below referenced above sets the rest of java modules to utilize the java you want to use -
toFixJava.sh
altrs="java javac jre jarsigner javadoc javafxpackager javah javap java-rmi.cgi javaws jcmd jconsole jcontrol jdb jhat jinfo jmap jmc jmc.ini jps jrunscript jsadebugd jstack jstat jstatd jvisualvm keytool appletviewer apt ControlPanel extcheck idlj native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc"
for each in $altrs
do
alternatives --install /usr/bin/$each $each /opt/jdk1.8.0_141/bin/$each <desired installation index number, e.g. 2>
alternatives --set $each /opt/jdk1.8.0_141/bin/$each
done
Please do let know if this doesn't work for you. I will help you solve alternatively!