3. Create the file /etc/profile.d/development.sh and copy the following content to the file.
export JAVA_HOME=/usr/local/development/jdk1.7.0_04 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
4. Restart the computer and use the command java -version to check whether the JDK is installed successfully.
Tip 1: Use development.sh to set environment variables
There are many ways to set JDK environment variables on the Internet, all of which are to modify /etc/environment, /etc/profile, ~/, bash_profile and other files.
In fact, if we open /etc/profile , we can find such a piece of code at the end:
if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i be done unset i be
That is to say, at the end of /etc/profile execution, it will automatically execute all readable files in the /etc/profile.d directory. This is the reason why we put the work of setting JDK environment variables in /etc/profile.d/development.sh , so we don't need to modify the content of /etc/profile that comes with the operating system , which is convenient for system transplantation.
Tip 2: Put development.sh in /usr/local/profile.d
My system /usr/local mount point is a separate disk partition, the purpose of this is to facilitate system maintenance. In addition to storing the installed software in the /usr/local directory, you can actually put configuration files under this directory, such as development.sh above , so that you do not need to redo this file when reinstalling the system. So, you can create a new directory /usr/local/profile.d and then copy development.sh to this new directory. As for how to put it under /etc/profile.d , I think a symbolic link can be used.
cd /ect/profile.d sudo ln -s /usr/local/profile.d/development.sh