Linux下的环境变量设置 # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc pathmunge () { if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi fi } # Path manipulation if [ `id -u` = 0 ]; then pathmunge /sbin pathmunge /usr/sbin pathmunge /usr/local/sbin fi pathmunge /usr/X11R6/bin after unset pathmunge # No core files by default ulimit -S -c 0 > /dev/null 2>&1 USER="`id -un`" LOGNAME=$USER MAIL="/var/spool/mail/$USER" HOSTNAME=`/bin/hostname` HISTSIZE=1000 if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then INPUTRC=/etc/inputrc fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then . $i fi done unset i JAVA_HOME="/opt/j2sdk1.4.2_01" MYSQL_HOME="/var/mysql" CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar PATH=$PATH:$JAVA_HOME/bin:$MYSQL_HOME/bin:/opt/apache-ant-1.5.4/bin export JAVA_HOME CLASSPATH PATH CVSROOT=/cvsroot; export CVSROOT LINUX系统环境变量 /etc/profile对整个系统有效. 确定你使用的是bash 修改~/.bash_profile 把你要设置的环境变量写进去 例如 JAVA_HOME=/usr/local/jdk export JAVA_HOME