Ubuntu Java Environment variables

Source: Internet
Author: User

Method 1: Modify the/etc/profile file
All user shells have permission to use these environment variables
<1> execute command at Shell Terminal: vi/etc/profile
<2> add at 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 System
Method 2: Modify the. bashrc file
If you need to give a user permission to use these environment variables, you only need to modify the. BASHRC on the home directory of their individual users. Instead of giving all user permissions like the first method.
<1> execute command at Shell Terminal: VI/HOME/USERNAME/.BASHRC
<2> add at 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> Re-Login
Method 3: Modify directly under the shell
Used for temporary use under the shell, which is not valid for a shell
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: (colons) instead of; (semicolons) to separate paths

Second, the test environment configuration
After the configuration is complete, you can test it.
<1> in DOS or terminal input java-version, and then output display, display is the current system JRE of the highest version
<2> in DOS or terminal input javac, if prompted, indicating that the compilation environment has been configured successfully
Note:<1> success simply indicates the success of the operating environment, generally as long as the JRE is installed OK
<2> success shows that the configuration of the running environment is successful, then the basic Java programming can be done.

environment variable configuration file

There are several files in Ubuntu that can set environment variables
1./etc/profile: The first file that is used when the operating system customizes the user environment when logging on, this file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time.
3, ~/.bash_profile: The third file to use when logging in is the. profile file, which each user can use to enter shell information dedicated to their own use when When the user logs on, the file is executed only once! By default, he sets some environments to change the amount of game, executing the users '. bashrc files. /ETC/BASHRC: Executes this file for each user running the bash shell. When the bash shell is opened, the file is read.
4, ~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log on and every time you open a new shell.

Priority of several environment variables

1>2>3


Set Persistent environment variable

1. In the environment variable configuration, delete the. Three lines in bash_profile about the definition of. BASHRC, The environment variable is then configured in the. BASHRC
2. Select the Java environment to use: Update-alternatives–config java
3. To make the environment variable that you just modified take effect: source. BASHRC
4. View environment variables: env

can be placed in/ETC/BASH/BASHRC, This is the system level

Ubuntu Java Environment variables

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.