Install and uninstall JDK in Linux

Source: Internet
Author: User
Tags echo command

From: http://www.cnblogs.com/hbycool/articles/1672010.html

Install JDK Linux Step 1. First download JDK (jdk-1_5_0_02-linux-i586.rpm) from the Internet, recommended sun official website www.sun.com, download and put in the/home directory, of course, other places also.

Go to the installation directory

 

# Cd/home

# Cp jdk-1_5_0_02-linux-i586.rpm/usr/local

# Cd/usr/local

 

 

Add executable permissions to all users

 

 

# Chmod + x jdk-1_5_0_02-linux-i586.rpm.bin

#./Jdk-1_5_0_02-linux-i586.rpm.bin

 

 

The file jdk-1_5_0_02-linux-i586.rpm is generated, and executable permissions are also added to all users

 

# Chmod + x jdk-1_5_0_02-linux-i586.rpm

 

 

Installer

 

# Rpm-IVH jdk-1_5_0_02-linux-i586.rpm

 

 

If the installation protocol is displayed, simply accept it.

 

 

 

Install JDK in Linux Step 2. Set environment variables.

 

# Vi/etc/profile

 

 

Method 1:

Add at the end

 

# Set Java environment

Java_home =/usr/Java/jdk-1_5_0_02

Classpath =.: $ java_home/lib. Tools. Jar

Path = $ java_home/bin: $ path

Export java_home classpath path

 

Method 2:

(Valid)

Export java_home =/usr/Java/jdk1.5.0 _ 10/

 
# Note: append the bin directory of the newly added JDK to the beginning of $ path. In this way, when multiple JDK versions are installed in the system, the program will first search for the JDK version at the beginning.
 
Export Path = $ java_home/bin: $ path
 
Export classpath =.: $ java_home/lib/tools. jar: $ java_home/lib/dt. jar: $ classpath
 
After saving/etc/profile, do not forget to execute the following command to make changes to environment variables take effect immediately.
 
Code:
 
Source/etc/profile
 
If an error is reported when you run the preceding command, check whether the text you added in/etc/profile is incorrect.
 
Finally, check whether the environment variable changes take effect:
 
Code:
 
Java-version

Save and exit.

To enable JDK to be used by all users, you can:

 

VI/etc/profile. d/Java. Sh

 

 

Enter the following content in the new java. Sh file:

 

# Set Java environment

Java_home =/usr/Java/jdk-1_5_0_02

Classpath =.: $ java_home/lib/tools. Jar

Path = $ java_home/bin: $ path

Export java_home classpath path

 

 

Save and exit, and then assign permissions to Java. sh:

 

Chmod 755/etc/profile. d/Java. Sh

 

So the best way is to modify the. bashrc file.

 

Code

[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

 

 

Usually, you prefer to use the Export command to directly set it in shell.

 

Code

[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

 

Another way is

Sudo gedit/etc/environment
Write the following two lines in the Text Editor:

Classpath =.:/usr/Java/jdk-1_5_0_02/lib
Java_home =/usr/Java/jdk-1_5_0_02/

 

Install JDK in Linux Step 3. Use the echo command on the terminal to check the environment variable settings.

# Echo $ java_home

# Echo $ classpath

# Echo $ path

4. Check whether JDK is successfully installed.

# Java-version

If you see the JVM version and related information, the installation is successful!

 

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 following command:

 

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

 

To allow a user to run Java commands, modify the bash initialization file.
For example, longware has the permission to run Java commands.

 

Code

[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

========================================================== ======================================

Uninstall JDK

 

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 of information:
# 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>

 

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.