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 添加环境变量的更多相关文章

  1. 【263】Linux 添加环境变量 & 全局 shell 脚本

    Linux电脑添加环境变量 方法一:通过修改 profile 文件添加环境变量 1. 打开终端,输入[vi /etc/profile],如下所示,点击回车 [ocean@ygs-jhyang-w1 L ...

  2. Linux 添加环境变量和删除环境变量

    环境变量是一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息.例如PATH.在交叉编译中,会经常运用到环境变量的设置. 在linux中,查看当前全部的环境变量的命令式env. 当然也 ...

  3. Linux添加环境变量与GCC编译器添加INCLUDE与LIB环境变量

    对所有用户有效在/etc/profile增加以下内容.只对当前用户有效在Home目录下的.bashrc或.bash_profile里增加下面的内容:(注意:等号前面不要加空格,否则可能出现 comma ...

  4. linux添加环境变量

    修改  /当前用户/.bash_profile文件,修改export PATH,添加自己的可执行程序的目录即可 例如: /root/.bash_profile export PATH=$PATH:/u ...

  5. linux添加环境变量(centos)

    1.查看当前环境变量 #echo $PATH 2.增加环境变量 #vi /etc/profile export PATH=/usr/path/bin:$PATH 3.生效 #source /etc/p ...

  6. linux 添加环境变量(php为例)

    find  / -name php vim /etc/profile 文件最后添加 export PATH=$PATH:/usr/local/php/bin source /etc/profile p ...

  7. linux添加环境变量(path)

    分为三步 1.sudo vim /etc/profile 2.export PATH="全路径:$PATH" 3.source /etc/profile 我的微信二维码如下,欢迎交 ...

  8. Linux下查看和添加环境变量

    转自:http://blog.sina.com.cn/s/blog_688077cf01013qrk.html $PATH:决定了shell将到哪些目录中寻找命令或程序,PATH的值是一系列目录,当您 ...

  9. linux命令(11)下查看和添加环境变量

    &PATH:决定了shell将到哪些目录中去寻找命令或者程序,PATH值是一系列的目录,当你要运行一个程序时,Linux在这些目录下进行搜寻编译链接. 编辑PATH 声明,其格式为: PATH ...

随机推荐

  1. VUE-010-通过声明式导航 router-link 传递 params 参数(路由 name 识别,请求链接不显示参数传递)

    在前端页面表单列表修改时,经常需要在页面切换的时候,传递需要修改的表单内容,除了通过路由进行表单参数的传递,也可通过声明式导航 router-link 进行页面跳转和参数传递. 首先,配置页面跳转路由 ...

  2. Spark 学习笔记

    Spark的前世今生   基础语法详解   3.条件控制与循环   4.函数入门   5.函数入门之默认参数   6.函数入门之边长参数   7.函数入门之过程lazy值和异常   8.数组操作之Ar ...

  3. Oracle程序备份

    --使用root用户备份 su - root mkdir -p /oracle/data_dump/backup_soft nohup tar -cvf /oracle/data_dump/backu ...

  4. 2019CCF-GAIR全球人工智能与机器人峰会于7月在深圳召开

    全球人工智能与机器人峰会(CCF-GAIR)是由中国计算机学会(CCF)主办,雷锋网.香港中文大学(深圳)承办,得到了深圳市政府的大力指导,是国内人工智能和机器人学术界.工业界及投资界三大领域的顶级交 ...

  5. 用python脚本获取运行环境中的module 列表

    由于脚本运行在远程环境,总报错说一些module没有.所以决定彻底对环境进行一次摸底. 于是,用如下代码即可实现: #!/usr/bin/env python import sys try: #pri ...

  6. java mysql连接时出现的问题

    当出现Caused by: java.sql.SQLException: Unknown system variable ‘tx_isolation’ 一般是mysql-connector-java的 ...

  7. linux下如何查看某软件是否已安装

      因为linux安装软件的方式比较多,所以没有一个通用的办法能查到某些软件是否安装了.总结起来就是这样几类: 1.rpm包安装的,可以用rpm -qa看到,如果要查找某软件包是否安装,用 rpm - ...

  8. SQL 一列数据整合为一条数据

    SQL 一列数据整合为一条数据: SELECT  STUFF(( SELECT distinct  ',' + 列名 FROM 表名 where  [条件] FOR XML PATH('') ), 1 ...

  9. 移动App专项测试

    移动App测试实战—专项测试 转自:http://www.51testing.com/html/58/n-3713758.html 我们在进行了手工的功能测试之后,也开发了一些自动化测试用例,并且做了 ...

  10. Saiku资源帖

    一.精选 1.李秋 随笔分类 - pentaho 二.概述 1.Saiku + Kylin 多维分析平台探索 三.Saiku+Kylin 1.使用Saiku+Kylin构建多维分析OLAP平台 2.使 ...