Welcome 微信登录

首页 / 操作系统 / Linux / Linux 环境变量配置

Linux 环境,用户通过shell 操作时,系统会为用户初使化环境变量, 比如系统公共资源路径: path , include , bin 等目录。 shell 模式下,执行 export , 查看用户环境变量 , echo $key 查询某个环境变量。设置环境变量,有两种方式,分为临时设置,与永久设置。
a.临时设置(实时生效)
shell 模式执行:
export PATH="$PATH:/opt/au1200_rm/build_tools/bin"b.永久设置
#行尾追加 export...
vi /etc/profile
export PATH="$PATH:/opt/au1200_rm/build_tools/bin"vi /root/.bashrc
export PATH="$PATH:/opt/au1200_rm/build_tools/bin"以上几种方式可以看出,设置环境变量的过程是一致的。shell 模式,直接执行脚本,将环境变量导入内存中,因此实时生效,其它的shell环境 无法使用该环境变量(隔离性)。 永久设置,在/etc/profile  , /root/.bashrc 文件尾追加 export key="value" 这两个文件是用户打开shell 客户端时,自动执行,其中/root/.bashrc 的优先级高于/etc/profile 。 可做如下测试:vi /etc/profile
export TEST="test1"vi /root/.bashrc
export TEST="$TEST:test2"在新的shell 模式下输入 export , 结果:
declare -x TEST="test1:test2"因此 /etc/profile  脚本先于 /root/.bashrc 初使化,后者可以覆盖前者。设置Linux环境变量的方法和区别  http://www.linuxidc.com/Linux/2015-02/113488.htmLinux安装JDK和配置环境变量  http://www.linuxidc.com/Linux/2014-11/109598.htm本文永久更新链接地址