java环境变量设置

415 阅读1分钟
在文件的最后添加配置
export JAVA_HOME=/usr/local/java/jdk1.8.0_201
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tool.jar

使配置文件立刻生效

source /etc/proflie

环境变量的分类

环境变量可以简单的分成用户自定义的环境变量以及系统级别的环境变量。

  • 用户级别环境变量定义文件:~/.bashrc~/.profile(部分系统为:~/.bash_profile
  • 系统级别环境变量定义文件:/etc/bashrc/etc/profile(部分系统为:/etc/bash_profile)、/etc/environment

另外在用户环境变量中,系统会首先读取~/.bash_profile(或者~/.profile)文件,如果没有该文件则读取~/.bash_login,根据这些文件中内容再去读取~/.bashrc

可以推测出Linux加载环境变量的顺序如下:

  1. /etc/environment
  2. /etc/profile
  3. /etc/bash.bashrc
  4. /etc/profile.d/test.sh
  5. ~/.profile
  6. ~/.bashrc

来源: www.cnblogs.com/youyoui/p/1…

每次打开终端都要 source 环境变量问题

在用户根目录下~,编辑.zshrc文件,后面追加source /etc/profile保存重新打开即可

blog.csdn.net/GYongJia/ar…