Java - JDK Update information - java

I need to update Java version
java version "1.4.2"
I don't want change version of my jdk, so if I update java, will JDK update too?
EDIT
#UnholySheep
You mean you want to update the JRE (runtime environment)? That is
indeed separate from the JDK

java -version will update only if you point the java environment variable to the new JDK/JRE installation.
You can have multiple JDK installations and switch between them whenever you like. For the current JDK in use you just have to set (On Windows) the JAVA_HOME environment variable to point to the correct JDK folder you intend to use at the moment.
Of course, this is only helpful for use in the command line. If you are using an IDE it's even simpler, you can choose/switch the JDK you want to use on every Java Project from the Project Settings.
For Linux, you can change the current JDK in use like this:
export $JAVA_HOME=/urs/lib/jvm/jdk1.8.0_144/jre
export PATH=$JAVA_HOME/bin:$PATH
sudo update-alternatives --config java

if you want to upgrade your Java version in your Linux system
then you can go with
sudo upgrade java

Related

Switching Java 11 for Java 8 on the server

So I've seen a bunch of tutorials on switching from Java 8 to Java 11, but I actually need to do the opposite. And I am doing it on a server, so I can use only bash.
I am pretty clueless of how to do it. Any help?
You can run this command and chose version java:
sudo update-alternatives --config java
This is what I do on my Debian system:
alias j8='export JAVA_HOME=/usr/lib/jvm/bellsoft-java8-full-amd64;export PATH=$JAVA_HOME/bin:$PATH'
This will ensure all executables are of the same version, and is a lot easier than update-alternatives, even if it did work (see my comments below another answer) or update-java-alternatives and is less error-prone
I use this tool SdkMan Install, SkMan manual
skd list java
print the versions of java available, and you can install it with comands like
sdk install java 8.0.292.hs-adpt
After you install a java version with sdkman set the java Home with
export JAVA_HOME=~/.sdkman/candidates/java/current
export PATH=$JAVA_HOME/bin:$PATH
you can install many java versions as you want and set your default version with
sdk default java 8.0.292.hs-adpt
If you use maven or gradle install them from sdkman, because in this way autodetects the version switching.
If you want to switch java versions only for specific projects check the env and .sdkmanrc part in the manual. It switches versions when you cd into a directory and go back to default when you cd out.

Multiple Java JDK versions, Aptana Studio 3, Mac OS

I am having trouble running Aptana Studio 3 on a Mac where multiple versions of JDK are installed (i.e., jdk1.8.0_271.jdk and jdk-11.0.2.jdk). Aptana requires JDK 8, and when only it is in the Library/Java/JavaVirtualMachines will Aptana run, otherwise, I get startup fatal errors. I need Open JDK 11 for another application and it runs with both JDKs installed. I tried to set JDK 8 as the default in a .bash_profile using the following, but for some reason (probably an obvious one that answers this question) Aptana doesn't recognize the default setting and only runs when I remove the jdk-11.0.2.jdk from JavaVirtualMachines. I know there is a version control package jenv, but I don't have it installed, and not sure it would fix the problem anyway. Appreciate any pointers on how to resolve this, if I can/should add a shell to the package contents of Aptana, proper mods on the commands below, etc. Running Mac Mojave 10.14.6. Thanks.
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8*)
export JAVA_11_HOME=$(/usr/libexec/java_home -v11.*)
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java11='export JAVA_HOME=$JAVA_11_HOME'
#default java8
export JAVA_HOME=$JAVA_8_HOME
macOS picks the most recent version of JDK. You have few options here:
remove files (backup) of JDKs that you don't want to use
/Library/Java/JavaVirtualMachines/${JDK_VERSION}/Contents/Info.plist
make sure to setup Terminal session for using give version
# inside ~/.zshrc put
export JAVA_HOME=$(/usr/libexec/java_home -v ${VERSION_OF_YOUR_CHOICE})
export PATH=${JAVA_HOME}/bin:${PATH}
use some tool to maintain JDK versions
As you already mentioned, you can use some existing tool (e.g. jenv)

How do I install an earlier version of Java SDK on OSX

I have the Java 1.8.0_45 SDK installed on OSX Yosemite (10.10.4), but because of a bug in this release I need to go back to 1.8.0_25
I have downloaded and installed the earlier version (1.8.0_25) but even after a reboot java -versionstill shows 1.8.0_45.
I don't really understand where Java resides on OSX, but how can I get my system back so it uses 1.8.0_25
Try and add this to your ~/.bashrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
You can have multiple JRE/JDK's installed, by changing this path, you can specify which one you use each time you open a new shell.
Here is what I use in my .bashrc
JAVA_VERSION=7
JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
tmp="JAVA_${JAVA_VERSION}_HOME"
export JAVA_HOME=${!tmp}
export PATH=${!j}/bin:$PATH
Here, you can simply change the 7 to an 8.
This will change the JAVA_HOME, and append the bin directory to your path for general use from the command line.
note you may beed to change your java home's according to the specific release versions installed on your machine.
Ah found it, suprisingly easy:
macbook:JavaVirtualMachines paul$ cd /Library/Java/JavaVirtualMachines
macbook:JavaVirtualMachines paul$ ls
jdk1.7.0_40.jdk jdk1.7.0_45.jdk jdk1.8.0.jdk jdk1.8.0_05.jdk jdk1.8.0_20.jdk jdk1.8.0_25.jdk jdk1.8.0_45.jdk
macbook:JavaVirtualMachines paul$ sudo rm -fr jdk1.8.0_45

find rpm name from a executable

I am using redhat 6.5. By default JRE is installed with this OS. I want to find the rpm name of the jre installed in my machine.
ie) input should be executable and the output will be the rpm name
which java
/usr/bin/java
expected output:
command to find the rpm name.
jre-1.7.0_80-fcs.x86_64
here java --version shows version 1.5. But i want to use oracle jre instead of the default one. After installing oracle jre still the default version of jres is used but i want to remove the default version of jre from OS.
Any help will be appreciated.
The solution to you problem is , after installing the oracle version of java you have to use alternatives command to point to you default java, like follows:
# alternatives --config java
and select the default version there.
Now check the version of java with java --version

Running Ant with JDK 1.6 on Mac OS X

I am having a problem running Ant with JDK 1.6 on Mac OS X. Even though Java application versions is set to Java SE 6 in OS X's Java Preference, executing java -version in Terminal also shows java version "1.6.0_07", Ant still seems to use JDK 1.5 to be using JDK 1.5 as it does not see JDK 1.6 classes when compiling my code.
I understand that Ant relies on JAVA_HOME environment variable to specify which JDK to use. However, I do not quite understand how this variable can be set on Mac OS X.
Hence, my question is how to make Ant runs with JDK 1.6 on Mac OS X. If the correct way is still to set JAVA_HOME environment variable, how to set the variable on OS X.
The JAVA_HOME environment variable is set in your home directory's .profile file. (/Users/ejel/.profile ?) Edit it and set it to what you want it to be. E.g.:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
From this point onward, every time you open a new terminal window it will have JAVA_HOME set to this new value. It will not have changed with any existing open windows.
If you are truly aghast to putting this in the profile, or if it conflicts with other software, the export statement could always be run in the terminal manually or go into a script (eg: setj6ev.sh) that is run once before you start running ant tasks.
I've added the line
export JAVA_HOME=`/usr/libexec/java_home`
To my .zshrc file, it seems to do the trick (.bash_profile or whatever if you use bash).
Ted, using the Java Preferences app doesn't change the CurrentJDK symlink in /System/Library/Frameworks/JavaVM.framework/Versions, which is what Ant will use if the JAVA_HOME environment variable isn't set. Thus, you can either change that symlink manually or set the JAVA_HOME environment variable, but if you do neither, then Ant won't use the correct JDK.
You can see the version of the jdk that Ant is using by issuing an <echo message="${ant.java.version}"/> in your build.xml file.
Explicitly setting the JAVA_HOME variable in your .profile/.bashrc/.zshrc isn't actually the recommended way to do it on the mac. There are programs that I've seen get hosed up with an explicitly set JAVA_HOME to a particular version (grails 1.1 with some spring resources for example).
The correct way to set the version of Java that you want to use is to use the /Application/Utilities/Java Preferences.app application.
In there, you drag the version of java that you want to use to the top. This will enable that version for all applications (both those run from the command line and those launched through GUI processes).
You can test the current version by running this from the command line:
java -version
I don't actually like the way that the mac handles the entire set of java symlinked directories and files. It's not obvious and people often screw it up.
See the apple developer page on this for more details.
I try everything, and only one thing works for me : unlink CurrentJDK, and link to 1.6 :
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo unlink CurrentJDK
sudo ln -sF "1.6" CurrentJDK
Finally I get :
java -version
java version "1.6.0_22"
I hope this help.
You may need to open a new command prompt instance so that the shell can pick up any changes to the environment variables.

Categories

Resources