zoukankan      html  css  js  c++  java
  • Linux 环境变量

    系统:centos6

    1.系统的环境变量配置文件:

    ~/.bash_profile

    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/.local/bin:$HOME/bin
    
    export PATH

    2.定义并管理自己的环境变量配置文件:

    在  /etc/profile.d/  目录下,按照下面的方式,添加自己的目录到环境变量中,多个目录,用冒号隔开 

    # filename:/etc/profile.d/custom-sh.sh
    # my custom path add to system path
    # run this command : source /etc/profile.d/custom-sh.sh
    # if you have some path,user ":" to connect them, not ";".
    # add by liang.20191119.
    
    export PATH="$PATH:/usr/local/python3/bin"

    3.添加完成之后,执行一次 source 命令,让配置立马生效

    source   /etc/profile.d/custom-sh.sh

    4.检查自定义的路径是否添加到了环境变量中!!!

    4.检查自定义的路径是否添加到了环境变量中!!!

    4.检查自定义的路径是否添加到了环境变量中!!!

    export  $PATH

    5.在输出的文本里面查看,PATH 后面是否有我们刚才添加的路径。


    总结一下若干配置文件目录:

    1.自定义的建议放在这个目录下面,命名为.sh 

    /etc/profile.d/

    2.系统自带的若干配置文件

    /etc/profile
    
    /etc/bashrc
    
    ~/.bash_profile
    
    ~/.bashrc

    其他说明1:

    ~代表主目录
    假设你登陆的用户明为user
    ~ 就表示 /home/user

    其他说明2:

    (1)/etc/profile: 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置。

    (2)/etc/bashrc: 为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。

    (3)~/.bash_profile: 每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。

    (4)~/.bashrc: 该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。

    (5) ~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件. 另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承 /etc/profile中的变量,他们是"父子"关系。

    其他说明3:

    执行  export  命令,可以查看全部的环境变量。

  • 相关阅读:
    switch语句
    switch语句
    if语句三种格式
    dowhile语句
    if语句三种格式
    if语句配对
    ansible
    linux系统中网站服务程序(web服务/httpd服务)
    ansible
    ansible
  • 原文地址:https://www.cnblogs.com/music-liang/p/11889602.html
Copyright © 2011-2022 走看看