linux环境变量

总结

环境变量载入分为三段,如图

                                                                  ↓**********调用***************↓

                                       ↓*********调用***************↓

 /etc/enviroment  ->  /etc/profile  ->  ~/.profile   ->/etc/.bashrc  ->  ~/.bashrc

 ↑ ↑ ↑ ↑ ↑ ↑ ↑开机执行 ↑ ↑ ↑ ↑ ↑ ↑

                                                       ↑ 登录执行 ↑  

                                                                              ↑ ↑每次打开shell执行 ↑ ↑ ↑

  • 系统级环境变量

(1)/etc/environment:系统登录时载入的值,用于所有进程,设置系统环境

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

(2)/etc/profile:对系统所有用户设定环境变量,一般会调用/etc/bash.bashrc文件

/etc/bash.bashrc:系统级bashrc文件,每次打开shell时执行一次

这两个文件修改后一般都要重启系统才能生效。

  • 用户级环境变量

 (1)~/.profile   当前登录用户的环境配置,仅在用户登录时执行一次。一般会设置环境变量和调用用户的.bashrc文件

(2)~/.bashrc  当前用户的bash初始化文件,每次shell打开时都会执行一次,


相关命令

  •  查看所有全局变量
env
printenv
printenv HOME
echo $HOME
echo $PATH
  • 本shell 中添加临时环境变量
export DOWNLOAD=/home/yan/download
export PATH=/home/yan/anaconda2:$PATH
export PATH=$PATH:/home/yan/anaconda2
  • 删除全局变量
unset DOWNLOAD
  • profile中添加,或.bashrc文件中添加

$sudo gedit /etc/profile

$sudo gedit /etc/profile

 打开文件后添加

export  PATH=$PATH:/my_new_path

 保存退出,使之生效

source /etc/profile  #生效

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值