Java environment variable configuration in linux

Source: Internet
Author: User
Java environment variable configuration in linux-general Linux technology-Linux programming and kernel information. For details, see the following. 1. Download JDK

Address: http://java.sun.com/javase/downloads/index.jsp

If Platform is selected for Linux, there are two options: Linux RPM in self-extracting file and Linux self-extracting file. I chose the second one.

2. Install JDK

Modify jdk permission to execute

# Chmod 755 jdk-6u6-linux-i586.bin

#./Jdk-6u6-linux-i586.bin

Follow the prompts to install the jdk1.6.0 _ 06 folder (

If you select the first rpm package, it will be installed in the/usr/java/directory by default.) You can copy it to your favorite directory, I put it under/usr/local.

3. Configure Environment Variables

This is the most critical step and must be configured with caution.

Edit/etc/profile

# Vi/etc/profile

Add the following lines:

JAVA_HOME =/usr/local/jdk1.6.0 _ 06

CLASSPATH =.: $ JAVA_HOME/lib/tools. jar: $ JAVA_HOME/jre/lib/rt. jar

PATH = $ JAVA_HOME/bin: $ PATH: $ HOME/bin: $ JAVA_HOME/jre/bin

Modify the export line and add: JAVA_HOME CLASSPATH.

Export JAVA_HOME CLASSPATH PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

During configuration, note that PATH = must be followed by: $ PATH. Otherwise, the PATH environment variable does not retain the original value, so that the Linux system cannot log on normally.

In addition, CLASSPATH =. The equal sign must be followed by a vertex. Otherwise, java. lang. ClassNotFoundException may occur.

4. Check Configuration

Log out of the environment to make the environment variable take effect (or execute the source/etc/profile command)

# Java

# Javac

# Java-version

If java and javac run, the java environment variable is successfully configured. Let's write a test file test. java.

# 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] # javatest

Hello World!

Working properly, OK.

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.