zoukankan      html  css  js  c++  java
  • 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!

  • 相关阅读:
    php使用redis的有序集合zset实现延迟队列
    php使用redis的几种常见方式和用法
    redis缓存雪崩,缓存穿透,缓存击穿的解决方法
    php操作redis数据库方法总结
    mysql 悲观锁与乐观锁的理解
    OAuth2.0 协议的理解
    windows下的mongodb安装与配置
    node.js中对 redis 的安装和基本操作
    node.js中对 mysql 进行增删改查等操作和async,await处理
    node.js中 koa 框架的基本使用方法
  • 原文地址:https://www.cnblogs.com/daysme/p/9975487.html
Copyright © 2011-2022 走看看