View and configure linux environment variables


foreword

A Linux environment variable is an object containing a value. If you are familiar with programming languages, then this environment variable is well understood, similar to variables in programming languages. Environment variables are often encountered in both linux development and software installation in linux systems.

1. View environment variables

By viewing the configuration file of the environment variable:

Global environment variable path:

vi /etc/profile

Local (user-level) environment variable paths:

vi ~/.bash_profile

Two, several environment variables commonly used in linux

$USER:当前用户名
$UID:当前用户UID
$SHELL:系统使用的shell
$HOME:主目录
$PWD:当前目录
$PATH:shell将到PATH目录中寻找命令或程序,PATH的值是一系列以冒号分割的目录。
查看PATH 值的方式:echo $PATH

3. Modify the environment variable method

Method 1: Use commands to modify directly, but it can only take effect in the current session. (Take adding java environment variables as an example)

export JAVA_HOME=/usr/local/java   #添加新变量名
export PATH=$PATH:/usr/local/php/bin #修改已有变量名

Check for success:

echo $JAVA_HOME

Method 2: Modify the global configuration file

Edit the global configuration file

vi /etc/profile

Use the Modify Immediately command

source /etc/profile

Method 3: Modify local (user-level) environment variable configuration files

Edit local environment variables

vi ~/.bash_profile 

Use the Modify Immediately command

source ~/.bash_profile

Summarize

Word document download address: Linux environment variable viewing and configuration

Guess you like

Origin blog.csdn.net/ma286388309/article/details/129274656