How to install Java in Linux

Source: Internet
Author: User
My system is rh9, the installation of the selected full installation, and then from the Internet under a j2sdk-1_4_2_05-linux-i586-rpm.bin, after installation
Use Java-version
I found that it was built on Linux.
Bytes -----------------------------------------------------------------------------------
Java version "1.3.1"
Jdkgcj 0.2.3 (http://www.arklinux.org/projects/jdkgcj)
Gcj (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Copyright (c) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is no
Warranty; not even for merchantability or fitness for a particle purpose.
Bytes -----------------------------------------------------------------------------------
What should I do ???
 
---------------------------------------------------------------
 
1. Install JDK
 
Download JDK directly from Sun: The http://java.sun.com/j2se/1.4.2/download.html provides two downloads:
 
1. rpm in self-extracting file (j2sdk-1_4_2_04-linux-i586.bin, 32.77 MB) This is a self-extracting file, installed on Linux as follows:
 
# Chmod U + X./j2sdk-1_4_2_04-linux-i586.bin
 
#./J2sdk-1_4_2_04-linux-i586.bin
 
After entering YES as prompted, JDK is decompressed to The./j2sdk1.4.2 _ 04 directory. In order to be consistent with the JDK installation path in the following 2, we will perform the following operations to establish the installation path under/usr/Java and test the file to this path:
 
# Mkdir/usr/Java
 
# Cp-Fr./j2sdk1.4.2 _ 04/usr/Java
 

 
2. rpm in self-extracting file (j2sdk-1_4_2_04-linux-i586-rpm.bin, 32.77 MB) This is also a self-extracting file, but the extracted file is a j2sdk-1_4_2_04-linux-i586-rpm package, run the RPM command to install it on Linux. The installation is as follows:
 
# Chmod U + X./j2sdk-1_4_2_04-linux-i586-rpm.bin
 
#./J2sdk-1_4_2_04-linux-i586-rpm.bin
 
# Rpm-IVH j2sdk-1_4_2_04-linux-i586-rpm
 
The installation software automatically installs JDK in the/usr/Java/j2sdk1.4.2 _ 04 directory.
 
2. Configure Environment Variables
 
1. Modify user environment variables
 
Assume that the Java User is kunp. Edit the user's. bashrc file to set environment variables.
 
# Vi/home/kunp/. bashrc
 
Add the following to the. bashrc file:
 
Export java_home =/usr/Java/j2sdk1.4.2 _ 04
Export classpath = $ classpath: $ java_home/lib: $ java_home/JRE/lib
Export Path = $ java_home/bin: $ java_home/JRE/bin: $ path: $ homr/bin
 
2. Modify the environment variables of all users
 
# Vi/etc/profile
 
Add:
 
Export java_home =/usr/Java/j2sdk1.4.2 _ 04
Export classpath = $ classpath: $ java_home/lib: $ java_home/JRE/lib
Export Path = $ java_home/bin: $ java_home/JRE/bin: $ path: $ homr/bin
 
Be sure to add $ classpath to the classpath path: Because I didn't add this stuff before, I always reported an error when interpreting and executing the class file.
 
Now let's see if Java is fully installed. Compile the most powerful Java file:
 
Hellodate. Java
 
-----------------------------------------
 
// Hellodate. Java
Import java. util. date;
 
Public class hellodate {
Public static void main (string [] ARGs ){
System. Out. println ("Hello, it's :");
System. Out. println (new date ());
}
}
 
------------------------------------------
 
Compile and execute the file under the kunp User:
 
# Su-kunp
 
$ Javac hellodate. Java
$ Java hellodate
Hello, it's:
Thu Jun 10 14:21:21 CST 2004
 

 
OK. The Java environment has been set up. Start to write your Java program.
Related Article

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.