Linux environment Variable Configuration summary

Source: Internet
Author: User

Ld_library_path: Find path for dynamic libraries
Set up:
Method One: Export ld_library_path=ld_library_path:/xxx but fails after logout
Method Two: Modify~/.BASHRCor ~/.bash_profile orsystem-Level/etc/profile
1. Add For example export path=/opt/activep/lib: $LD _library_path
2. Source. BASHRC (The source command is also known as a "point command", which is a dot symbol (.).) The source command makes it immediately effective without having to log off and log back on.
Method Three: This is not modified Ld_library_path but the effect is the same as the implementation of dynamic library search,
1./etc/ld.so.confAdd a line below/usr/local/mysql/lib
2. After savingLdconfig(The use of the Ldconfig command, mainly in the default search directory (/lib and/usr/lib) and dynamic Library configuration file/etc/ld.so.conf in the directory listed in the search for a shareable dynamic link library (format as described above, lib*.so*), This creates the connection and cache files required by the dynamic loader (ld.so). The cache file defaults to/etc/ld.so.cache, which holds the list of queued dynamic-link library names.
Method Three is slightly cumbersome, and the benefit is that the comparison is not restricted by the user.
For example:
The Ld_library_path for user production is analyzed as follows:
1.[email protected]:~>Echo $LD _library_path
/home/production/cpst/cptools/lib:/home/production/cpst/campost/lib:/home/production/tuxedo/lib:/home/ production/tuxedo/jre/lib/amd64/server:/home/production/tuxedo/jre/jre/bin:/usr/lib:/usr/lib64:/lib:/lib64:/ Usr/local/lib:/usr/local/lib64:/oracle/product/11gr2/db/lib:/oracle/product/11gr2/db/ctx/lib
2. View. Profile:
The. Profile has:. ~/cpst/campost/config/setenv, stating that user startup is running script setenv.
3. The setenv has:
Export Campost_home= $HOME/cpst/campost
Export cptools_root= $HOME/cpst/cptools
Export ld_library_path= $CPTOOLS _root/lib: $CAMPOST _home/lib: $LD _library_path
4, setenv in the $ld_library_path, into the root view:
(1) africa:~ # echo $LD _library_path
/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib:/usr/local/lib64:/oracle/product/11gr2/db/lib:/oracle/product/ 11gr2/db/ctx/lib
(2) The Etc/profile are:
Export ld_library_path=/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib:/usr/local/lib64: $LD _library_path
(3) The/etc/profile.d/oracle.sh are:
ld_library_path=${ld_library_path:+ $LD _library_path:} $ORACLE _home/lib: $ORACLE _home/ctx/lib

Two:

Library_path and ld_library_path are two environment variables under Linux, and their meanings and roles are as follows:

The LIBRARY_PATH environment variable is used to specify the path to find shared libraries when a dynamic link library is found during program compilation , for example, a directory that specifies the dynamic-link libraries that GCC compiles need to use. The Setup method is as follows (where LIBDIR1 and LIBDIR2 are two library directories):

Export LIBRARY_PATH=LIBDIR1:LIBDIR2: $LIBRARY _path

The LD_LIBRARY_PATH environment variable is used to specify a path other than the system default path when locating a dynamic link library during program load run , and note that the path specified in Ld_library_path is found before the system default path. The Setup method is as follows (where LIBDIR1 and LIBDIR2 are two library directories):

Export LD_LIBRARY_PATH=LIBDIR1:LIBDIR2: $LD _library_path

For example, we develop a program, often need to use some or some of the dynamic link library, in order to ensure the portability of the program, you can first put these compiled dynamic link libraries in their own designated directory, and then follow the above way to add these directories into the LD_LIBRARY_PATH environment variable, So that your own program can be dynamically linked after loading the library file to run.

Difference and use:

At development time, set the Library_path so that GCC can find the dynamic link libraries needed at compile time .

When publishing, set Ld_library_path so that the program loads the runtime to automatically find the required dynamic-link libraries.

Three:

The following command allows you to see how the executable file or library file itself is dependent on the library:

$ LDD ~/myprogram
The output is similar to:
Librt.so.1 =/lib/librt.so.1 (0x00002b4eca08e000)
libc.so.6 =/lib/libc.so.6 (0x00002b4eca49f000)
libpthread.so.0 =/lib/libpthread.so.0 (0x00002b4eca7df000)
/lib64/ld-linux-x86-64.so.2 (0x00002b4ec9e72000)
Libmylib.so.1 = not Found
The check results indicate that the linker cannot find the dependent library libmylib.so.1

Four:

1. Display Environment Variables Home

$ echo $HOME

/home/redbooks

2. Set a new environment variable Hello

$ export hello= "hello!"

$ echo $HELLO

Hello!

3. Use the ENV command to display all environment variables

$ env

hostname=redbooks.safe.org

Pvm_rsh=/usr/bin/rsh

Shell=/bin/bash

Term=xterm

histsize=1000

...

4. set shows all locally defined shell variables

$ set

Bash=/bin/bash

bash_versinfo= ([0]= "2" [1]= "05b" [2]= "0" [3]= "1" [4]= "Release" [5]= "I386-redhat-linux-gnu")

Bash_version= ' 2.05b.0 (1)-release '

Colors=/etc/dir_colors.xterm

Columns=80

Dirstack= ()

display=:0.0

...

  

5. Use the unset command to clear environment variables

Set sets the value of an environment variable. Clear the value of the environment variable with the unset command. If no value is specified, the value of the variable is set to NULL. Examples are as follows:

$ export test= "TEST ..." #增加一个环境变量TEST

$ env|grep Test #此命令有输入, proving that the environment variable test already exists

Test=test ...

$ unset $TEST #删除环境变量TEST

$ env|grep Test #此命令没有输出, proving that the environment variable test already exists

6. Set read-only variables using the readonly command

If the readonly command is used, the variable cannot be modified or erased. Examples are as follows:

$ export test= "TEST ..." #增加一个环境变量TEST

$ readonly TEST #将环境变量TEST设为只读

$ unset TEST #会发现此变量不能被删除

-bash:unset:test:cannot unset:readonly Variable

$ test= "New" #会发现此也变量不能被修改

-bash:test:readonly variable

Settings for environment variables are located in the/etc/profile file

If you need to add a new environment variable, you can include a subordinate row

Export path= $path:/PATH1:/PATH2:/PAHTN

6. Common Environment Variables
PATH determines to which directories the shell will look for commands or programs
Home Current User Home directory
Histsize Number of historical records
LOGNAME The 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 storage directory for the current user of mail
PS1 basic prompt, for root user Yes #, for normal user is $

Linux environment Variable Configuration summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.