How to set environment variables in Linux

Source: Internet
Author: User
Tags echo command

In general, you need to specify the path of the compilation tool when configuring the cross-compilation tool chain, and you need to set the environment variables. 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 environment variables:

1. Direct with export command:
#export path= $PATH:/opt/au1200_rm/build_tools/bin
To see if it is already set up, use the command export to view:
[Email protected] 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"
As you can see, the environment variable is already set, and the path of the compiler that I want to add is already in path.

2, modify the profile file:
#vi/etc/profile
Add in:
Export path= "$PATH:/Opt/au1200_rm/build_tools/bin"

3. Modify the. bashrc file:
# VI/ROOT/.BASHRC
Add in:
Export Path= "$PATH:/opt/au1200_rm/build_tools/bin"

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

--------------------------------------------------------------------------------------------------------------- --------

"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/local/bin" and other paths are already in the system environment variables, if the executable file in these standard locations, in the terminal command line enter the software executable file name and parameters ( If parameters are required), enter.

If not in a standard location, the file name needs to be preceded by a full path. But it's too much trouble to run like this every time, a "once and for all" approach is to add this path to the environment variable. The command "path= $PATH: Path" can add this path to an environment variable, but exiting the command line will fail. This line needs to be added to the environment variable file in order to be permanently active. There are two files to choose from: "/etc/profile" and ". Bash_profile" in the user's home directory, "/etc/profile" is valid for all users in the system, and ". Bash_profile" in the user's home directory is only valid for this user.

"Path= $PATH: Path 1: Path 2: ...: path n", which means that the path to the executable file includes the path originally set, and also includes all paths from "Path 1" to "Path N". When the user enters a string of characters and presses ENTER, the shell will find the corresponding executable file in these paths in turn and hand it over to the system core execution. The "$PATH" means that the path originally set is still valid, so be careful not to miss out. Some software may also have an environment variable of type "PATH" that needs to be added, but the method is the same, and you also need to be aware of "$".

Note that, unlike Dos/window, the path names in the UNIX class system environment variables are separated by colons, not semicolons. In addition, the more loaded the software, the more environment variables, in order to avoid confusion, it is recommended that all statements are added at the end of the file, in the software installation order.

The format is as follows ():

# Software Name-version number

Path= $PATH: Path 1: Path 2: ...: path n

Other environment variables =$ other environment variables: ...

In "Profile" and ". Bash_profile", "#" is a comment symbol that is written here without any effect except visual separation.

Setup is complete, log off and log back in, and the settings take effect. If you do not log off, executing these statements directly in the shell can also take effect, but the scope is limited to the shell that executes the statements.

Once the relevant environment variable is in effect, you don't have to run into the software's executable directory.

Transferred from: http://www.cnblogs.com/amboyna/archive/2008/03/08/1096024.html

How to set environment variables in Linux

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.