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 添加环境变量的更多相关文章
- 【263】Linux 添加环境变量 & 全局 shell 脚本
Linux电脑添加环境变量 方法一:通过修改 profile 文件添加环境变量 1. 打开终端,输入[vi /etc/profile],如下所示,点击回车 [ocean@ygs-jhyang-w1 L ...
- Linux 添加环境变量和删除环境变量
环境变量是一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息.例如PATH.在交叉编译中,会经常运用到环境变量的设置. 在linux中,查看当前全部的环境变量的命令式env. 当然也 ...
- Linux添加环境变量与GCC编译器添加INCLUDE与LIB环境变量
对所有用户有效在/etc/profile增加以下内容.只对当前用户有效在Home目录下的.bashrc或.bash_profile里增加下面的内容:(注意:等号前面不要加空格,否则可能出现 comma ...
- linux添加环境变量
修改 /当前用户/.bash_profile文件,修改export PATH,添加自己的可执行程序的目录即可 例如: /root/.bash_profile export PATH=$PATH:/u ...
- linux添加环境变量(centos)
1.查看当前环境变量 #echo $PATH 2.增加环境变量 #vi /etc/profile export PATH=/usr/path/bin:$PATH 3.生效 #source /etc/p ...
- linux 添加环境变量(php为例)
find / -name php vim /etc/profile 文件最后添加 export PATH=$PATH:/usr/local/php/bin source /etc/profile p ...
- linux添加环境变量(path)
分为三步 1.sudo vim /etc/profile 2.export PATH="全路径:$PATH" 3.source /etc/profile 我的微信二维码如下,欢迎交 ...
- Linux下查看和添加环境变量
转自:http://blog.sina.com.cn/s/blog_688077cf01013qrk.html $PATH:决定了shell将到哪些目录中寻找命令或程序,PATH的值是一系列目录,当您 ...
- linux命令(11)下查看和添加环境变量
&PATH:决定了shell将到哪些目录中去寻找命令或者程序,PATH值是一系列的目录,当你要运行一个程序时,Linux在这些目录下进行搜寻编译链接. 编辑PATH 声明,其格式为: PATH ...
随机推荐
- centos7开启80和8080端口
开启8080端口 firewall-cmd --permanent --add-port=8080/tcp firewall-cmd --reload 重定向80端口到8080端口firewall-c ...
- 常见查找算法(Java代码实现)
一,顺序查找 查找算法中顺序查找算是最简单的了,无论是有序的还是无序的都可以,只需要一个个对比即可,但其实效率很低.我们来看下代码 public static int search(int[] a, ...
- DCDC参数测量及方法
此文章目的为补充知识,防止遗忘,记录DCDC相关的. 1.拿到一颗DCDC芯片应该测试哪些参数:纹波.电源效率和动态响应. 1)纹波测量方法:示波器偶合方式选择AC:示波器探头的接地也不能用鳄鱼夹,这 ...
- 【actitivi】配置运行上遇到的问题
基础: 需要 问题1:对于activiti-admin,添加mysql-connector-java-5.1.47.jar后: Sun Apr 28 16:09:00 CST 2019 WARN: E ...
- Spark SQL 编程初级实践
一.实验目的 (1) 通过实验掌握 Spark SQL 的基本编程方法: (2) 熟悉 RDD 到 DataFrame 的转化方法: (3) 熟悉利用 Spark ...
- upCode
更新源码 Sub main() Dim str As String str = "这是测试的字符串对话框" MsgBox str Sheets(1).Select End Sub
- js中的this指向问题(小计)
this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定,this最终指向调用它的对象. 1.函数调用模式 当一个函数并非一个对象的属性时,那么它就是被当做函数来调用的.在此种模式下,t ...
- Python实现图像边缘检测算法
title: "Python实现图像边缘检测算法" date: 2018-06-12T17:06:53+08:00 tags: ["图形学"] categori ...
- Delphi中Move、CopyMemory操作
字串转字节数组 一.CopyMemory var s:PAnsiChar; ary:TArray<Byte>; bt:Byte; begin s:='Form Delphi'; SetLe ...
- 0003.5-20180422-自动化第四章-python基础学习笔记--脚本
0003.5-20180422-自动化第四章-python基础学习笔记--脚本 1-shopping """ v = [ {"name": " ...