Setting environment variables
First, modify the/etc/profile file
This method is recommended when this machine is used only as a development, because all users ' shells have the right to use these environment variables when this configuration is used, which may pose a security issue to the system.
Open/etc/profile with a text editor and add at the end of the profile file:
Java_home=/usr/share/jdk1.5.0_05
Path=Javahome/bin:Javahome/bin:path
Classpath=.:Javahome/lib/dt.jar:Javahome/lib/dt.jar:java_home/lib/tools.jar
Export Java_home
Export PATH
Export CLASSPATH
You can log in again.
Ii.. Modify the. bashrc file
This approach is more secure, it can control the permissions that use these environment variables to the user level, and if you need to use these environment variables for a user right, you only need to modify the. bashrc file in the home directory of their individual users.
Open the. bashrc file in the user directory with a text editor, and at the end of the. bashrc file, add:
Set java_home=/usr/share/jdk1.5.0_05
Export Java_home
Set path=Javahome/bin:Javahome/bin:path
Export PATH
Set classpath=.:Javahome/lib/dt.jar:Javahome/lib/dt.jar:java_home/lib/tools.jar
Export CLASSPATH
Log in again.
Third, set the variable directly under the shell
This method is not recommended because the setting is not valid for a different shell. This method is only temporary use, in the future to use the time again to set up, more trouble.
Simply execute the following command at the shell Terminal:
Export java_home=/usr/share/jdk1.5.0_05
Export path=Javahome/bin:Javahome/bin:path
Export classpath=.: J A V A H O M E / L I b / D T . J a R : " > Javahome/lib/dt.jar: javahome/lib/dt.jar:java_home/lib/tools.jar
Note:
1. To add /usr/share/jdk1.5.0_05jdk change to the JDK installation directory
2. linux with the colon ":" to separate the path
3. P A T H / " > path/ path/classpath / $JAVA _home is used to refer to the value of the original environment variable when setting the environment variable, especially be careful not to overwrite the original value.
Current directory in 4. classpath "." Can't throw it away. The
5. export is to export these three variables as global variables. The
6. case must be strictly differentiated. After testing, the second method does not take effect in the ubuntu16.10 version, use the first method.
If you still get an error when installing eclipse or some other IDE, it's possible that there may be other versions of the JDK in your system, and you'll have to change the default JDK version of the system.
Setting the JDK environment variable (Linux edition)