1.export 变量名=value
2.变量名=value ; export 变量名
3.declare -x 变量名=value
1.编辑 /etc/profile
<code>vim /etc/profile</code>

2.使定义的全局环境变量生效
root@raspberrypi:~# source /etc/profile
或者
root@raspberrypi:~# . /etc/profile
3.验证
对于用户的 环境变量设置,比较常见的是用户家目录下的 ./.bashrc 和 ./.bash_profile 这两个文件。一般推荐在 .bashrc 中优先设置
常见的全局环境变量的配置文件有:/etc/profile /etc/bashrc /etc/profile.d 。一般推荐在 /etc/bashrc 里优先设置。
若要在登陆后初始化或显示加载内容,则把脚本文件放在/etc/profile.d/下即可(无需加可执行权限)