• linux 环境变量的配置


    我发现有些人习惯在 /etc/profile 文件里面配置环境变量,在这里配置挺不好的。

    # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
    
    if [ "${PS1-}" ]; then
      if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
        # The file bash.bashrc already sets the default PS1.
        # PS1='h:w$ '
        if [ -f /etc/bash.bashrc ]; then
          . /etc/bash.bashrc
        fi
      else
        if [ "`id -u`" -eq 0 ]; then
          PS1='# '
        else
          PS1='$ '
        fi
      fi
    fi
    
    if [ -d /etc/profile.d ]; then
      for i in /etc/profile.d/*.sh; do
        if [ -r $i ]; then
          . $i
        fi
      done
      unset i
    fi

    通过以上文件可以看到其实也可以在 /etc/profile.d 目录下配置环境变量,这样更容易维护。

    现在以 java 环境变量为例:

    cd /etc/profile.d
    sudo vi java.sh
    ###########################
    JAVA_HOME=/opt/jdk1.8.0_271
    PATH=$JAVA_HOME/bin:$PATH
    export JAVA_HOME PATH
    ###########################
    sudo chmod 755 java.sh

    最后重启一下就可以了。

    如果安装 maven 的话:

    sudo apt install maven
  • 相关阅读:
    要成功先发疯
    情绪ABC理论
    树立和提高威信法
    javaagent
    sonar 使用
    sonar 代码质量管理
    四大思维工具,SWOT、PDCA、DISC、时间管理
    HyperLogLog
    位数组
    git checkout .和git checkout -f的区别;git add . git add -u git add -A的区别
  • 原文地址:https://www.cnblogs.com/M-Anonymous/p/13906828.html
Copyright © 2020-2023  润新知