(1) 如果是仅当前用户生效,就编辑 ~/.bashrc 或 ~/.bash_profile;
(2) 如果是所有用户生效,就编辑 /etc/profile,更好的习惯是在 /etc/profile.d 目录中增加一个 shell 脚本,将内容添加进去.
推荐 /etc/profile.d/ 中增加
It's much better to create a custom.sh shell script in /etc/profile.d/ to make custom changes to your environment, as this will prevent the need for merging in future updates.(from /etc/profile)增加如下内容:
JAVA_HOME=/opt/jdk1.6.0_26 PATH=$PATH:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME export PATH export CLASSPATH
source <file>
只对当前shell有效
[root@CentOS-6 ~]# cd /usr/bin [root@CentOS-6 bin]# ln -sf /opt/jdk1.6.0_26/bin/java [root@CentOS-6 bin]# ln -sf /opt/jdk1.6.0_26/bin/javac
【参考资料】
http://www.cppblog.com/wrhwww/archive/2010/07/26/121308.html