Linux & environment variables


Linux & environment variables

1. Introduction

  1. Linux’s environment variables stored in variable PATH, so can use echo $PATH to check

  2. Linux’s environment variables separate by :

    PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>

2. searching

  1. search all PATH value

    export
  2. check PATH environment variable

    echo $PATH
  3. listing all set environemnt variables

    set
  4. in the home folder

    ctrl h find all Hidden files (name begin with .)

    open .bashrc and edit

  5. open .bashrc by command

    vim ~/.bashrc

3. adding

  1. temporarily adding

    export NAME=VALUE

    examples:

    export JAVA_HOME=/opt/openjdk11
    export PATH=/usr/local/nginx/sbin/:$PATH

    adding /usr/local/nginx/sbin/ index adding to the environment temporarily

  2. current user adding permanent

    vim ~/.bashrc

    add export PATH="/usr/local/nginx/sbin/:$PATH" at the end of the file

    source ~/.bashrc
  3. all users adding permanent

    vim /etc/profile

    add export PATH="/usr/local/nginx/sbin/:$PATH" at the end of the file

    source  /etc/profile

4. deleting

unset VARIABLE_NAME

examples:

unset JAVA_HOME

Author: Liang Junyi
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Liang Junyi !
  TOC