JDK environment variable settings in Linux

Source: Internet
Author: User

Method 1: Modify the/etc/profile file
All users' shells have the right to use these environment variables.
<1> execute the command on the shell terminal: VI/etc/profile
<2> Add the following content to the end of the profile file:
Java_home =/usr/lib/JVM/Java-6-sun-1.6.0.15
Path = $ java_home/bin: $ path
Classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export java_home, path, classpath
<3> restart the system.
Method 2: Modify the. bashrc File
If you want to grant a user the permission to use these environment variables, you only need to modify the. bashrc in the home directory of the user, unlike the first method to grant permissions to all users.
<1> execute the command on the shell terminal: VI/home/username/. bashrc
<2> Add the following content to the end of the. bashrc file:
Set java_home =/usr/lib/JVM/Java-6-sun-1.6.0.15
Export java_home
Set Path = $ java_home/bin: $ path
Export path
Set classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export classpath
<3> log on again
Method 3: directly modify it in Shell
Used for temporary use in shell. Changing a shell is invalid.
Export java_home =/opt/jdk1.5.0 _ 02
Export classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export Path = $ java_home/bin: $ path
Note: Linux uses: (colon) instead of (semicolon) to separate paths.
 
Ii. test environment Configuration
After completing the above configuration, you can perform the test.
<1> input the Java-version in DOS or terminal, and then the output shows the highest version of the current system JRE.
<2> enter javac in DOS or terminal. If a prompt is displayed, the compiling environment is configured successfully.
Note: <1> success indicates that the running environment is successful. Generally, you only need to install JRE.
<2> If the running environment is successfully configured, you can perform basic Java programming.

Environment variable configuration file

The following files can be used to set environment variables in Ubuntu:
/Etc/profile: The first file used by the operating system to customize the user environment during login. This file sets environment information for each user in the system. When the user logs on for the first time, the file is executed.
,/Etc/environment: the second file used by the operating system during logon. Before the System reads your own profile, it sets the environment variable of the Environment File.
,~ /. Bash_profile: The third file used for logon is. profile file. Each user can use this file to enter the shell information dedicated to their own use. When the user logs on, this file is only executed once! By default, it sets some environments to change the game volume and execute the user's. bashrc file. /Etc/bashrc: execute this file for every user running bash shell. When bash shell is opened, the file is read.
,~ /. Bashrc: This file contains the bash information dedicated to your bash shell. This file is read when you log on and every time you open a new shell.

Priority of several Environment Variables
> 2> 3

Set permanent Environment Variables
In the. environment variable configuration, you must first Delete the three rows in. bash_profile about. bashrc definition, and then configure the environment variable in. bashrc.
. Select the Java environment to use: Update-alternatives-config Java
. To make the modified environment variable take effect: source. bashrc
. View the environment variable: ENV

It can be stored in/etc/bash/bashrc, which is a system-level

From: http://tompig.iteye.com/blog/1114887

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.