Practical Operation Log: Install JDK in Linux

Source: Internet
Author: User

Ten years later, computers are becoming more and more popular. Many people have been applying computers, and the most essential part of the computer is the operating system. We often see Microsoft and Linux. However, Linux is developing very rapidly and is catching up with Microsoft. Here we will introduce the knowledge of Linux, so that you can learn how to use Linux. Today I will talk about installing JDK in Linux to configure environment variables. I hope you will remember to install JDK in Linux to configure environment variables.

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:

 
 
  1. [root@LinuxServer rpm]# chmod 755 j2sdk-1_4_2_06-linux-i586-rpm.bin  
  2. [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.

 
 
  1. Sun Microsystems, Inc.  
  2. Binary Code License Agreement  
  3. for the  
  4. JAVATM 2 SOFTWARE DEVELOPMENT KIT (J2SDK), STANDARD  
  5. EDITION, VERSION 1.4.2_X  
  6. …  
  7. Do you agree to the above license terms? [yes or no]yes  
  8. Unpacking...  
  9. Checksumming...  
  10. 0  
  11. 0  
  12. Extracting...  
  13. UnZipSFX 5.40 of 28 November 1998, by Info-ZIP (Zip-Bugs@lists.wku.edu).  
  14. inflating: j2sdk-1_4_2_06-linux-i586.rpm    
  15. 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;

 
 
  1. [root@LinuxServer rpm]#rpm –ivh j2sdk-1_4_2_06-linux-i586.rpm  
  2. Preparing...                ########################################### [100%]  
  3. 1:j2sdk                ########################################### [100%]  

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

 
 
  1. [root@LinuxServer rpm]# export JAVA_HOME=/usr/java/j2sdk1.4.2_06  
  2. [root@LinuxServer rpm]# export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
  3. [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.

 
 
  1. [root@LinuxServer rpm]#vi .bashrc  
  2. set JAVA_HOME=/usr/java/j2sdk1.4.2_06  
  3. export JAVA_HOME  
  4. set PATH=$PATH:$JAVA_HOME/bin  
  5. export PATH  
  6. set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
  7. 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, we will verify whether the variable settings take effect. Before verification, we will log out and then log on again );

 
 
  1. [root@LinuxServer rpm]# echo $JAVA_HOME  
  2. /usr/java/j2sdk1.4.2_06/  
  3. [root@LinuxServer rpm]# echo $CLASSPATH  
  4. /usr/java/j2sdk1.4.2_06/lib/dt.jar:/usr/java/j2sdk1.4.2_06/lib/tools.jar  
  5. [root@LinuxServer rpm]# echo $PATH  
  6. /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  
  7. [root@LinuxServer rpm]# -version  
  8. JAVA version "1.4.2_06"  
  9. JAVA(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)  
  10. JAVA HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)JAVA  

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

 
 
  1. [root@LinuxServer rpm]#vi test.java  
  2. class test   
  3. {  
  4.         public static void main(String[] args)   
  5.         {  
  6.                System.out.println("Hello World!");  
  7.         }  
  8. }  

Save and exit. Compile and execute the command below;

 
 
  1. [root@LinuxServer text]# javac test.java  
  2. [root@LinuxServer text]# test  
  3. Hello World!JAVA  

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,

 
 
  1. [root@LinuxServer root]# vi /home/longware/.bashrc  
  2. set JAVA_HOME=/usr/java/j2sdk1.4.2_06  
  3. export JAVA_HOME  
  4. set PATH=$PATH:$JAVA_HOME/bin  
  5. export PATH  
  6. set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
  7. export CLASSPATH  

7. Now, JDK installation on Linux is complete. This completes the installation of JDK environment variables in Linux.

  1. How to change the root password in linux single-user mode
  2. Partitioning solution for Ubuntu Linux
  3. Managing peripheral mounting disks for installation of common Linux software packages
  4. How to Implement shortcut keys in Linux Bash
  5. Linux Security Settings

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.