Several ways to set up Linux environment variables __linux

Source: Internet
Author: User
Tags bz2 echo command
Several common environment variable/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin




Export edit this entry is missing Information BarBusiness Card Map, add the relevant content to make the entry more complete, but also can quickly upgrade, hurriedly to edit it. Linux Export Command Feature Description: Set or display environment variables. Syntax: Export [-fnp][variable name]=[variable set value] Supplemental NOTE: When executing a program in a shell, the shell provides a set of environment variables. Export can add, modify, or delete environment variables for use by subsequent programs. The validity of export only extends to the login operation. Parameter:-F represents the function name in the variable name. -n Deletes the specified variable. Variables are not actually deleted, but are not exported to the execution environment of subsequent directives. -p lists all the environment variables that the shell assigns to the program.

How to set environment variables in Linux (export PATH)

In general, you need to specify the path to the compilation tool when configuring the cross-compilation tool chain, where you need to set the environment variable. For example, my MIPS-LINUX-GCC compiler is in the "/opt/au1200_rm/build_tools/bin" directory, Build_tools is my compilation tool, there are three ways to set the environment variable:

1. Direct use of export command:
#export path= $PATH:/opt/au1200_rm/build_tools/bin
Check to see if it is already set up and check it out with the command export:


[Root@localhost bin]# Export
Declare-x bash_env= "/ROOT/.BASHRC"
Declare-x g_broken_filenames= "1"
Declare-x histsize= "1000"
Declare-x home= "/root"
Declare-x hostname= "Localhost.localdomain"
Declare-x inputrc= "/ETC/INPUTRC"
Declare-x lang= "ZH_CN. GB18030 "
Declare-x language= "Zh_CN.GB18030:zh_CN.GB2312:zh_CN"
Declare-x lessopen= "|/usr/bin/lesspipe.sh%s"
Declare-x logname= "Root"
Declare-x ls_colors= "no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi= 01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar= 01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*. Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01 ; 35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35: "
Declare-x mail= "/var/spool/mail/root"
Declare-x oldpwd= "/opt/au1200_rm/build_tools"
Declare-x path= "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/x11r6/bin:/root/bin:/opt/ Au1200_rm/build_tools/bin "
Declare-x pwd= "/opt/au1200_rm/build_tools/bin"
Declare-x shell= "/bin/bash"
Declare-x shlvl= "1"
Declare-x ssh_askpass= "/usr/libexec/openssh/gnome-ssh-askpass"
Declare-x ssh_auth_sock= "/tmp/ssh-xx3lkwhz/agent.4242"
Declare-x ssh_client= "10.3.37.152 2236 22"
Declare-x ssh_connection= "10.3.37.152 2236 10.3.37.186 22"
Declare-x ssh_tty= "/DEV/PTS/2"
Declare-x term= "Linux"
Declare-x user= "Root"
Declare-x username= "Root"


You can see that the gray section has a set path, indicating that the environment variable has been set up, path has already had the compiler I want to add.

2, modify profile file:
#vi/etc/profile
In the inside add:
Export path= "$PATH:/opt/au1200_rm/build_tools/bin"

3. Modify the. bashrc file:
# VI/ROOT/.BASHRC
In the inside add:
Export path= "$PATH:/opt/au1200_rm/build_tools/bin"

The latter two methods generally require a cancellation of the system in order to take effect, and finally can be tested by the echo command:
# echo $PATH
See if there is already a/my_new_path this path in the output.

Other:4. Modify/etc/re.local File:
# vi/etc/re.local
In the inside add:
Export path= "$PATH:/opt/au1200_rm/build_tools/bin"


Export Editor This entry is missing the Information Bar , business card map , add related content to make the entry more complete, but also can quickly upgrade, hurriedly to edit it. Linux Export Command Feature Description: Set or display environment variables. Syntax: Export [-fnp][variable name]=[variable set value] Supplemental NOTE: When executing a program in a shell, the shell provides a set of environment variables. Export can add, modify, or delete environment variables for use by subsequent programs. The validity of export only extends to the login operation. Parameter:-F represents the function name in the variable name. -n Deletes the specified variable. Variables are not actually deleted, but are not exported to the execution environment of subsequent directives. -p lists all the environment variables that the shell assigns to the program.

How to set environment variables in Linux (export PATH)

In general, you need to specify the path to the compilation tool when configuring the cross-compilation tool chain, where you need to set the environment variable. For example, my MIPS-LINUX-GCC compiler is in the "/opt/au1200_rm/build_tools/bin" directory, Build_tools is my compilation tool, there are three ways to set the environment variable:

1. Direct use of export command:
#export path= $PATH:/opt/au1200_rm/build_tools/bin
Check to see if it is already set up and check it out with the command export:


[Root@localhost bin]# Export
Declare-x bash_env= "/ROOT/.BASHRC"
Declare-x g_broken_filenames= "1"
Declare-x histsize= "1000"
Declare-x home= "/root"
Declare-x hostname= "Localhost.localdomain"
Declare-x inputrc= "/ETC/INPUTRC"
Declare-x lang= "ZH_CN. GB18030 "
Declare-x language= "Zh_CN.GB18030:zh_CN.GB2312:zh_CN"
Declare-x lessopen= "|/usr/bin/lesspipe.sh%s"
Declare-x logname= "Root"
Declare-x ls_colors= "no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi= 01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar= 01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*. Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01 ; 35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35: "
Declare-x mail= "/var/spool/mail/root"
Declare-x oldpwd= "/opt/au1200_rm/build_tools"
Declare-x path= "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/x11r6/bin:/root/bin:/opt/ Au1200_rm/build_tools/bin "
Declare-x pwd= "/opt/au1200_rm/build_tools/bin"
Declare-x shell= "/bin/bash"
Declare-x shlvl= "1"
Declare-x ssh_askpass= "/usr/libexec/openssh/gnome-ssh-askpass"
Declare-x ssh_auth_sock= "/tmp/ssh-xx3lkwhz/agent.4242"
Declare-x ssh_client= "10.3.37.152 2236 22"
Declare-x ssh_connection= "10.3.37.152 2236 10.3.37.186 22"
Declare-x ssh_tty= "/DEV/PTS/2"
Declare-x term= "Linux"
Declare-x user= "Root"
Declare-x username= "Root"


You can see that the gray section has a set path, indicating that the environment variable has been set up, path has already had the compiler I want to add.

2, modify profile file:
#vi/etc/profile
In the inside add:
Export path= "$PATH:/opt/au1200_rm/build_tools/bin"

3. Modify the. bashrc file:
# VI/ROOT/.BASHRC
In the inside add:
Export path= "$PATH:/opt/au1200_rm/build_tools/bin"

The latter two methods generally require a cancellation of the system in order to take effect, and finally can be tested by the echo command:
# echo $PATH
See if there is already a/my_new_path this path in the output.

Other:4. Modify/etc/re.local File:
# vi/etc/re.local
In the inside add:
Export path= "$PATH:/opt/au1200_rm/build_tools/bin"

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.