zoukankan      html  css  js  c++  java
  • 转载--Ubuntu设置环境变量

     

    Ubuntu设置环境变量并立即生效(以Ubuntu12.04为例)

    标签: UbuntuLinux环境变量
     分类:
     
      
     

    目录(?)[+]

     

    Ubuntu Linux系统包含两类环境变量:系统环境变量和用户环境变量。系统环境变量对所有系统用户都有效,用户环境变量仅仅对当前的用户有效。

    修改用户环境变量

    用户环境变量通常被存储在下面的文件中:

    • ~/.profile

    • ~/.bash_profile 或者 ~./bash_login

    • ~/.bashrc

    上述文件在Ubuntu 10.0以前版本不推荐使用。

    系统环境变量

    系统环境变量一般保存在下面的文件中:

    • /etc/environment

    • /etc/profile

    • /etc/bash.bashrc

    /etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推荐使用。

    加入环境变量

    如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):

    [plain] view plain copy
     
     print?
    1. sudo vi /etc/profile  

    在里面加入:

    [plain] view plain copy
     
     print?
    1. JAVA_HOME=/usr/jdk1.6.0_25  
    2. export JAVA_HOME  
    3. PATH=$PATH:$JAVA_HOME/bin  
    4. export PATH  
    5. CLASSPATH=.:$JAVA_HOME/lib  
    6. export CLASSPATH  

    你可以自己加上指定的多个路径,中间用冒号隔开。环境变量更改后,在用户下次登陆时生效,如果想立刻生效,则可执行下面的语句:

    [plain] view plain copy
     
     print?
    1. source /etc/profile  

    需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。

    其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。

    更详细的说明可以参考这里

    当然如果想使用文本编辑工具修改环境变量,可以使用root权限登录后,直接用文本编辑器打开修改保存

    也可以普通用户权限下把文件复制到桌面等修改后用root权限覆盖回去

    [plain] view plain copy
     
     print?
    1. # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))  
    2.  # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).  
    3.        
    4.  if[ -d /etc/profile.d ]; then  
    5.    fori in/etc/profile.d/*.sh;do  
    6.      if[ -r $i ]; then  
    7.        . $i  
    8.      fi  
    9.    done  
    10.        
    11.  JAVA_HOME=/usr/hadoop/jdk1.6.0_25  
    12.  export JAVA_HOME  
    13.  PATH=$PATH:$JAVA_HOME/bin  
    14.  export PATH  
    15.  CLASSPATH=.:$JAVA_HOME/lib  
    16.  export CLASSPATH  
    17.        
    18.    unseti  
    19.  fi  
    20.        
    21.  if[ "$PS1"]; then  
    22.    if[ "$BASH"]; then  
    23.      # The file bash.bashrc already sets the default PS1.  
    24.      # PS1='h:w$ '  
    25.      if[ -f /etc/bash.bashrc ]; then  
    26.        ./etc/bash.bashrc  
    27.      fi  
    28.    else  
    29.      if[ "`id -u`" -eq0 ]; then  
    30.        PS1='# '  
    31.      else  
    32.        PS1='$ '  
    33.      fi  
    34.    fi  
    35.  fi  

    原文地址:点击打开链接

  • 相关阅读:
    How to install VXDIAG Honda, Toyota and JLR SDD software
    16% off MPPS V16 ECU tuning tool for EDC15 EDC16 EDC17
    Cummins INSITE locked and ask for verification code
    How to use BMW Multi Tool 7.3 to replace lost key for BMW X1
    Bleed Brake Master Cylinder with Intelligent Tester IT2
    Porsche Piwis Tester II “No VCI has been detected”,how to do?
    Creader VIII VS. Creader VII+
    How to solve GM MDI cannot complete the installation
    汽车OBD2诊断程序开发 (原文转载,思路很清晰!)
    汽车节温器单片机开发思路
  • 原文地址:https://www.cnblogs.com/superAng/p/5671114.html
Copyright © 2011-2022 走看看