Set environment variables for centos and environment variables for centos
Method 1: Add a variable to the/etc/profile file [effective for all users (permanent )]
Use VI to add a variable to the/etc/profile file. This variable will be valid for all users in Linux and will be "permanent ".
[Root @ CentOS ~] # Vi/etc/profile
Add the following two lines of code to the end of the file:
PATH =/usr/local/webserver/php/bin: $ PATH
Export PATH
#/Etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in/etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# Are doing. It's much better to create a custom. sh shell script in
#/Etc/profile. d/to make custom changes to your environment, as this
# Will prevent the need for merging in future updates.
Pathmunge (){
Case ": $ {PATH}:" in
*: "$1 ":*)
;;
*)
If ["$2" = "after"]; then
PATH = $ PATH: $1
Else
PATH = $1: $ PATH
Fi
Esac
}
If [-x/usr/bin/id]; then
If [-z "$ EUID"]; then
# Ksh workaround
EUID = 'id-U'
UID = 'id-ru'
Fi
USER = "'id-UN '"
LOGNAME = $ USER
MAIL = "/var/spool/mail/$ USER"
Fi
# Path manipulation
If ["$ EUID" = "0"]; then
Pathmunge/sbin
Pathmunge/usr/sbin
Pathmunge/usr/local/sbin
Else
Pathmunge/usr/local/sbin after
Pathmunge/usr/sbin after
Pathmunge/sbin after
Fi
HOSTNAME = '/bin/hostname 2>/dev/null'
History Size = 1000
If ["$ HISTCONTROL" = "ignorespace"]; then
Export HISTCONTROL = ignoreboth
Else
Export HISTCONTROL = ignoredups
Fi
Export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You cocould check uidgid reservation validity in
#/Usr/share/doc/setup-*/uidgid file
If [$ UID-gt 199] & ["'id-gn '" = "'id-un'"]; then
Umask 002
Else
Umask 022
Fi
For I in/etc/profile. d/*. sh; do
If [-r "$ I"]; then
If ["$ {-# * I }"! = "$-"]; Then
. "$ I"
Else
. "$ I">/dev/null 2> & 1
Fi
Fi
Done
Unset I
Unset pathmunge
PATH =/usr/local/webserver/php/bin: $ PATH
Export PATH
If the modification takes effect immediately, run the following code:
[Root @ CentOS ~] # Source/etc/profile
Method 2: Add a variable to the. bash_profile file in the user directory [effective for a single user (permanent )]
Use VI to add a variable to the. bash_profile file in the user directory. The change volume is valid only for the current user and is "permanent ". The specific operation is the same as that in method 1. The code is not listed here.
Method 3: run the export command to define the variable [only valid for the current shell (BASH) (Temporary )]
Use the [export variable name = variable value] to define a variable under the shell command line. This variable is valid only in the current shell (BASH) or its subshell (BASH, when shell is closed, the variable becomes invalid. This variable is not available when a new shell is opened. You need to define the variable again if necessary. For example
Export PATH =/usr/local/webserver/php/bin: $ PATH