Linux environment environment variables (PATH / LD_LIBRARY_PATH)

Press the lifetime of variables to divide, Linux variables can be divided into two categories, they are modified as follows:

(A) permanent

Need to modify the configuration file, variable permanent common profile includes:

(1-1)/etc/profile

Take effect for all users; this file for each user to set environment information system, when a user first logs in, the file is executed; and collect shell settings from the configuration file /etc/profile.d directory
for example: Edit / etc / profile file, add the CLASSPATH variable
# vi / etc / profile

PATH

Add the line:

 

1

PATH="$PATH:/usr/local/hadoop/bin"

(Note that the equal sign (=) on either side with no spaces)
to make the environment variables take effect immediately need to perform the following command:

 

 

1

#source /etc/profile

Or the echo command to test:

 

 

1

$ echo $PATH

 

LD_LIBRARY_PATH: dynamic library search path

You can add a line in / etc / profile in

 

 

1

export LD_LIBRARY_PATH = LD_LIBRARY_PATH: / XXX (but logout after failure)

 

 

 

1

Another export PATH = / opt / ActiveP / lib: $ LD_LIBRARY_PATH

Excuting an order

 

 

1

source /etc/profile

To make the change to take effect
can also be, / etc / ld.so.conf add the following line / usr / local / mysql / lib
and execute

 

 

1

ldconfig

To make the change to take effect

(1-2)/etc/bashrc

Propagate to all users; each user to perform a file operation when the bash shell bash shell is opened, the file is read editing method as described above, will not be repeated.

(1-3)~/.bash_profile

Only will the current user; each user can use the file input information specific to shell their own use, when a user logs in, the file is only performed once
, for example: .bash_profile edit guok user directory under (/ home / guok)
vi / home / guok / .bash.profile add the following: exportCLASSPATH = / JAVAHOME / lib; JAVA_HOME / jre / lib.
after modifications need to perform re-login to take effect, you can execute the command source / etc / profile to take effect

(1-4)~/.bashrc

Only the current user will; when the dedicated file contains the bash shell bash your information, when opening each new log and the shell, the file is read the
editing method as described above, will not be repeated
, and ~ /. bashrc variables (local) can only be set in succession / etc / profile variables in their relationship, "father and son"
review, in the above-mentioned documents to modify, add the variables you need to start a shell (terminal, terminal) , you define variables will effect.

(B) temporary

Use the export command to declare the variable is only in the current shell (BASH) or its sub-shell (BASH) valid, invalid after closing the shell, do not have this variable when opening a new shell, you need to use again if needed defined
using [export variable name = variable value] variable defined directly in the command-line shell

Environment variables View
(1) using the echo command to view a single environment variable. E.g:

 

 

1

echo $PATH

(2) use of env view all environment variables. E.g:

 

 

1

env

(3) View all locally defined using a set of environment variables. E.g:

 

 

1

set

In addition, unset removes the specified environment variable.

Common environment variables

PATH determines the shell to which directories to find commands or programs
HOME current user's home directory
history record number HISTSIZE
LOGNAME current user's login name
HOSTNAME refers to the name of the host
SHELL current user Shell type
LANGUGE language related environment variables, multiple languages can modify this environment variable
MAIL current user's mail store directory
PS1 primary prompt is # for the root user, for the average user is $

Various modifications of difference

At the login case, the general shell will first read / etc / profile, then read .bash_profile. If you are in a non-logins, shell only to read .bashrc.
Modify / etc / profile, are valid for all users;
If you want to change the root environment variables may be modified or /root/.bashrc /root/.bash_profile;
Similarly, if the user wants to modify an environment variable, and can modify / home / user 1 / .bash_profile or / home / user 1 / .bashrc

Guess you like

Origin blog.csdn.net/qq_35886593/article/details/89925919