Install and uninstall JDK on Linux

Source: Internet
Author: User

Install

1. Go to the http://java.sun.com/j2se/1.4.2/download.html to download a Linux platform JDK, it is recommended to download RPM self-extract format (rpm in self-extracting file, j2sdk-1_4_2_06-linux-i586-rpm.bin );
2. Upload the file to a Linux server and run the following command in shell:

[Root @ linuxserver RPM] # chmod 755 j2sdk-1_4_2_06-linux-i586-rpm.bin
[Root @ linuxserver RPM] #./j2sdk-1_4_2_06-linux-i586-rpm.bin

There will be a piece of Sun Protocol, several times the Space key, when asked whether to agree, you can press Yes.

Sun Microsystems, Inc.
Binary Code License Agreement
For
Javatm 2 software development kit (j2sdk), Standard
Edition, version 1.4.2 _ x
...
Do you agree to the above license terms? [Yes or No] Yes
Unpacking...
Checksumming...
0
0
Extracting...
Unzipsfx 5.40 of 28 November 1998, by Info-zip (Zip-Bugs@lists.wku.edu ).
Inflating: j2sdk-1_4_2_06-linux-i586.rpm
Done.

3. The program will automatically generate a j2sdk-1_4_2_06-linux-i586.rpm file, which is the main package, to install below;

[Root @ linuxserver RPM] # rpm-IVH j2sdk-1_4_2_06-linux-i586.rpm
Preparing... ######################################## ### [100%]
1: j2sdk ####################################### #### [100%]

Additional: if it is in the format of tar.gz, decompress it directly, put it in the usr/Java directory, and set the following environment variables.

4. Set Environment Variables
Usually, you prefer to use the Export command to directly set it in shell.

[Root @ linuxserver RPM] # export java_home =/usr/Java/j2sdk1.4.2 _ 06
[Root @ linuxserver RPM] # export classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
[Root @ linuxserver RPM] # export Path = $ path: $ java_home/bin

Of course, this setting of environment variables takes effect only for the current shell. If you log on from another shell, you cannot use the variable you just set. So the best way is to modify the. bashrc file.

[Root @ linuxserver RPM] # vi. bashrc
Set java_home =/usr/Java/j2sdk1.4.2 _ 06
Export java_home
Set Path = $ path: $ java_home/bin
Export path
Set classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export classpath

Of course, you can also change the/etc/profile. However, this setting is not recommended because it will take effect for your shell and affect system security. Next, verify whether the variable settings take effect (log out before verification, and then log on again );

[Root @ linuxserver RPM] # echo $ java_home
/Usr/Java/j2sdk1.4.2 _ 06/
[Root @ linuxserver RPM] # echo $ classpath
/Usr/Java/j2sdk1.4.2 _ 06/lib/dt. jar:/usr/Java/j2sdk1.4.2 _ 06/lib/tools. Jar
[Root @ linuxserver RPM] # echo $ path
/Usr/Java/j2sdk1.4.2 _ 06/bin/:/usr/Kerberos/sbin:/usr/Kerberos/bin:/usr/local/sbin:/usr/local/bin: /sbin:/bin:/usr/sbin:/usr/bin:/usr/x11r6/bin:/root/bin
[Root @ linuxserver RPM] # Java-version
Java version "1.4.2 _ 06"
Java (TM) 2 Runtime Environment, Standard Edition (build 1.4.2 _ 06-b03)
Java hotspot (TM) Client VM (build 1.4.2 _ 06-b03, mixed mode)

5. Set the environment to OK to see if JDK works normally. Let's write a test file test. java.

[Root @ linuxserver RPM] # VI test. Java
Class Test
{
Public static void main (string [] ARGs)
{
System. Out. println ("Hello world! ");
}
}

Save and exit. Compile and execute the command below;

[Root @ linuxserver text] # javac test. Java
[Root @ linuxserver text] # Java Test
Hello world!

OK. The operation is normal.
6. To allow a user to run Java commands, modify the bash initialization file.
For example, to grant longware the permission to run Java commands,

[Root @ linuxserver root] # vi/home/longware/. bashrc
Set java_home =/usr/Java/j2sdk1.4.2 _ 06
Export java_home
Set Path = $ path: $ java_home/bin
Export path
Set classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export classpath

7. Now, JDK installation on Linux is complete.

Uninstall

Uninstall default:

Log on to the system as the root user and open a terminal input.
# Rpm-Qa | grep gcj

The displayed content contains the following two lines:

# Java-1.4.2-gcj-compat-1.4.2.0-27jpp
# Java-1.4.2-gcj-compat-devel-l.4.2.0-27jpp
Uninstall
# Rpm e java-1.4.2-gcj-compat-devel-l.4.2.0-27jpp
# Rpm e java-1.4.2-gcj-compat-l.4.2.0-27jpp

Run rpm-e to uninstall other self-installed JDK. <javaxxxxx>

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.