LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Changing default version of Java? (https://www.linuxquestions.org/questions/linux-newbie-8/changing-default-version-of-java-645846/)

Yig 05-30-2008 10:56 AM

Changing default version of Java?
 
Hi,

I just installed the latest JDK RPM on my machine (CentOS 5) but Java 1.4.2 is still the default version. I tested running java -version and got 1.4.2.

What do I need to change so that 1.6 is the new default?

Thanks!

TB0ne 05-30-2008 11:41 AM

Quote:

Originally Posted by Yig (Post 3169383)
Hi,

I just installed the latest JDK RPM on my machine (CentOS 5) but Java 1.4.2 is still the default version. I tested running java -version and got 1.4.2.

What do I need to change so that 1.6 is the new default?

Thanks!

Check the symbolic link for your java directory. Look at the docs, but doing a "which java" at the command line will give you a good start. The /usr/java directory (at least on my system), goes to /usr/java-1.6.xx/whatever. If I upgrade, and the next version goes into /usr/java-1.99/whatever, I just move the symbolic link.

rickh 05-30-2008 12:42 PM

Is the "alternatives" system something that is Debian-only?

In Debian...
# update-alternatives --config java
...fixes it in a flash.

Yig 05-30-2008 01:28 PM

Quote:

Originally Posted by TB0ne (Post 3169426)
Check the symbolic link for your java directory. Look at the docs, but doing a "which java" at the command line will give you a good start. The /usr/java directory (at least on my system), goes to /usr/java-1.6.xx/whatever. If I upgrade, and the next version goes into /usr/java-1.99/whatever, I just move the symbolic link.

Let me see...

which java returned

/usr/bin/java


And that file is question is java -> /etc/alternatives/java

The RPM was installed in /usr/java. And I see the following in that directory:

default -> /usr/java/latest
jdk1.6.0_06
latest -> /usr/java/jdk1.6.0_06

The actual java command is in /usr/java/jdk1.6.0_06/jre/bin so how do I change the link to it?

mnabil 02-13-2012 06:11 PM

Just in case someone needs this...
 
in /etc/alternatives folder modify the java link to the following (adapt to your java folder location)
sudo ln -T /usr/java/jdk1.7.0/bin/java java
nothing to do in /usr/bin

Fivalo 02-23-2012 12:23 PM

Error changing the link
 
Hi

I have changed the link /etc/aternatives/java to the bin directory to the Sunīs Virtual Machine, and Iīm having this error when I type java -version :


[root@mn alternatives]# java -version
java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory

Anybody has an idea what is wrong

Thanks

EDDY1 02-23-2012 01:03 PM

You should open a new thread & tell us what distro & how you installed.

Fivalo 02-23-2012 01:26 PM

Resolved
 
Hi

I have found the solution, that is the following:


Chose an installation destination directory. Create the parent directory, if necessary, and change into it.
# mkdir -p /opt && cd /opt
Obtain the insanely large shell package from SUN. Pay close attention to 32/64 bit. You do not want the version with rpm in the file name. Typically, you want the 64-bit version these days. Save it in a location so you can access it in the next step.
Run the shell expander. Follow its prompts
# /bin/sh /path/to/jdk-6u20-linux-x64.bin
Run the alternatives program to tell the system about the existence of your new installation:
# alternatives --install /usr/bin/java java /opt/jdk1.6.0_20/bin/java 2
Run the alternatives program again, to chose the new installation
# alternatives --config java
Verify that you are getting the right version of Java
$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)


Thanks

EDDY1 02-23-2012 01:31 PM

The new version of java is 1.7.0, so if you use google chrome 1.6.0 will not work

sumitkm 04-05-2012 11:26 PM

Worked like a charm
 
Quote:

Originally Posted by Fivalo (Post 4610306)
Hi

I have found the solution, that is the following:


Chose an installation destination directory. Create the parent directory, if necessary, and change into it.
# mkdir -p /opt && cd /opt
Obtain the insanely large shell package from SUN. Pay close attention to 32/64 bit. You do not want the version with rpm in the file name. Typically, you want the 64-bit version these days. Save it in a location so you can access it in the next step.
Run the shell expander. Follow its prompts
# /bin/sh /path/to/jdk-6u20-linux-x64.bin
Run the alternatives program to tell the system about the existence of your new installation:
# alternatives --install /usr/bin/java java /opt/jdk1.6.0_20/bin/java 2
Run the alternatives program again, to chose the new installation
# alternatives --config java
Verify that you are getting the right version of Java
$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)


Thanks

Thanks a ton , worked like a charm on RHEL 5.
I had three java installations and on the last step

alternatives --config java

I was asked to pick the number.

For a Linux noob like me, your steps were a big help!

Geremia 12-15-2012 12:08 PM

$java_home
 
Can't one just set the JAVA_HOME environment variable?

Shadow_7 12-15-2012 02:29 PM

You can set LD_LIBRARY_PATH before running an application that uses java. I just added the path to a custom .conf file in /etc/ld.so.conf.d/ and ran ldconfig. Although more or less for the browser plugin that doesn't use openGL if you don't tell java where java is located. And LD is more for the libraries and not the applications. And then there's the pulseaudio issue where you have to pretty much install and configure pulseaudio to use the supplied distro package without audio related quirks.


All times are GMT -5. The time now is 03:26 PM.