Install jdk1.6 in RedHat-use alternative to achieve coexistence of multiple versions

Source: Internet
Author: User

The Installation Process in RedHat ES is very simple. Sun downloads the jdk1.6 package, decompress the package, and then RPM installs the package.

After installation, create Java. Sh under etc/profile. d/. The Code is as follows:
  
Java_home =/usr/Java/jdk1.6.0
  
Path = $ path: $ java_home/bin
  
Classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
  
Export java_home path classpath
  
Cancel
  
Log on again

Note: When setting a variable, the variable Separator in RedHat is colon (:) instead of the score in win series.
No;

[Root @ localhost ~] # Echo $ classpath
  
.:/Usr/Java/jdk1.6.0/lib/dt. jar:/usr/Java/jdk1.6.0/lib/tools. Jar
  
[Root @ localhost ~] # Echo $ path
  
/Usr/Kerberos/sbin:/usr/Kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:
  
/Bin:/usr/sbin:/usr/bin:/usr/x11r6/bin:/usr/Java/jdk1.6.0/bin:/root/bin:
  
/Usr/Java/jdk1.6.0/bin
  
[Root @ localhost ~] # Echo $ java_home
  
/Usr/Java/jdk1.6.0

Problem: Unfortunately, the Java-version in the console is 1.4.0.

I have installed other Java versions in my system.

Do you need to uninstall jdk1.4.0 before installing the new JDK version of sun?

Google found that the original RedHat is far less troublesome than the win system. There is an alternative system (Alternatives System) mechanism in RedHat to abstract the locations and trademarks of different software or different versions of the same software, so as to eliminate the need to replace the environment. Update-alternatives is the implementation of this mechanism. Therefore, you can use Update-alternatives to implement the coexistence of two jdks and switch between them as needed.

Update-alternatives -- dispaly Java is preferred. Check the current configuration of the current Java software, especially the priority of the path.

Then we configure the Java software configuration to use the jdk1.6

Update-alternatives -- config Java

If everything goes well, we can see the Java configuration schemes available in the system. However, because the jdk1.6 version is relatively new, my own RedHat cannot be detected, so you need to manually add it using the update-alternatives -- install option and then select the list.

We use the update-alternatives -- install option to grant jdk1.6 the highest level of the new JVM (set to 60) to add the JVM as shown in the list.

# Update-alternatives -- install/usr/bin/Java/usr/Java/jdk1.6.0/JRE/bin/Java 60
-- Slave/usr/share/man/Man1/java.1.gz java.1.gz/usr/lib/JVM/jdk1.6.0/man/Man1/java.1

Then update-alternatives -- config Java to select the added jdk1.6 configuration Scheme

At this time, if you view Java-version in the terminal, you will see the 1.6 words

Note: Update-alternatives essentially uses ln to implement the method of shadow to implement the alternative system.

Therefore, you can use commands to view the image path and learn the details of the image. Take Java as an Example

Terminal # which Java

/Usr/lib/Java

# Ls-l usr/lib/Java

You can get the shadow path. Next, you can see the file used by this command to understand the details of the shadow.

Http://www.lukfor.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.