linux 添加环境变量
You have to edit three files to set a permanent environment variable as follow:
-
~/.bashrc
When you open any terminal window this file will be run. Therefore, if you wish to have a permanent environment variable in all of your terminal windows you have to add the following line at the end of this file:
export DISPLAY=0 -
~/.profile
Same as bashrc you have to put the mentioned command line at the end of this file to have your environment variable in the every login of your OS.
-
/etc/environment
If you want your environment variable in every windows or application ( not just terminal window ) you have to edit this file. Add the following command at the end of this file:
DISPLAY=0
Note that in this file you do not have to write export command
Normally you have to restart your computer to apply this changes. But you can apply changes in bashrc and profile by these commands:
$ source ~/.bashrc
$ source ~/.profile
But for /etc/environment you have no choice but restarting ( as far as I know )
* A Simple Solution
I’ve written a simple script for this procedures to do all those work. You just have to set name and value of your environment variable.
#!/bin/bash
echo "Enter variable name: "
read variable_name
echo "Enter variable value: "
read variable_value
echo "adding " $variable_name " to environment variables: " $variable_value
echo "export "$variable_name"="$variable_value>>~/.bashrc
echo $variable_name"="$variable_value>>~/.profile
echo $variable_name"="$variable_value>>/etc/environment
source ~/.bashrc
source ~/.profile
echo "do you want to restart your computer to apply changes in /etc/environment file? yes(y)no(n)"
read restart
case $restart in
y) sudo shutdown -r 0;;
n) echo "don't forget to restart your computer manually";;
esac
exit
Save this lines in a shfile then make it executable and just run it!
相关文章
- 在Linux添加PYTHONPATH方法以及修改环境变量方法
- Kali linux 渗透测试技术之搭建WordPress Turnkey Linux及检测WordPress 应用程序漏洞
- 如何在linux上通过GRUB添加内核参数
- Linux集群和自动化维3.1 Python语言的应用领域
- x86 linux下如何交叉编译?
- linux中如何配置vim的别名为vi?
- linux下split切割的文件如何合并
- Linux命令之read
- 【Linux】手把手教你如何搭建linux环境---云服务器
- linux在菜单中添加SEG选项
- Linux运维面试题之--网页打开缓慢如何优化
- 【嵌入式Linux驱动开发】学习笔记(汇总版)
- Linux 之 arm linux 板子与 ubuntu 使用 nfs 进行 mount 挂载进行文件传输的简单整理
- 【Linux】linux经常使用基本命令
- 【Linux】linux经常使用基本命令
- Linux学习笔记(12)linux文件目录与用户管理
- Linux学习笔记(9)linux网络管理与配置之一——Linux基础网络命令与学习大纲(0)
- Linux中把程序添加到系统服务中
- 【Linux】linux中删除指定日期之前的文件
- Linux QQ
- linux 添加永久ip、路由和开启路由功能
- Linux内核私闯进程地址空间并修改进程内存
- linux系统添加审计用户并进行权限控制
- linux 下find命令 --查找文件名