Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

关于环境变量添加位置的建议

强烈建议将环境变量写入 ~/.bashrc

根据其他文章参考资料,环境变量可加入以下四个位置且优先级由高到低:

1、/etc/profile.d/test.sh    #/etc/profile.d/ 目录下脚本均会执行

2、/etc/profile

3、/etc/bashrc

4、~/.bashrc  #用户级

验证:

#测试环境
[root@test ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core) 


[root@test ~]# echo "echo \"/etc/profile say hi\"" >> /etc/profile
[root@test ~]# echo "echo \"/etc/profile.d say hi\"" >> /etc/profile.d/test.sh
[root@test ~]# echo "echo \"~/.bashrc say hi\"" >> ~/.bashrc
[root@test ~]# echo "echo \"/etc/bashrc say hi\"" >> /etc/bashrc 

#登录
Last login: Tue Mar  2 21:32:25 2021 from 10.0.0.101
/etc/profile.d say hi
/etc/profile say hi
/etc/bashrc say hi
~/.bashrc say hi
[root@test ~]# 

为什么建议写入~/.bashrc呢?

今天使用ansible-playbook时,启动zookeeper时总是不成功,最后发现是jdk环境变量没有设置上,当时设置的位置是/etc/profile,后来改为~/.bashrc时问题解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值