First, view environment variables
$ env
Second, view the path
$ echo $PATH
Third, modify path
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"
As you can see, the environment variable is already set up, and the path inside the path already has 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.
--------------------------------------------------------------------------------------------------------------- --------
Paths such as "/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/local/bin", etc., are already in the system environment variable, and if the executable file is in these standard locations, enter the file name and parameters for the software executable at the terminal command line ( If you need a parameter, enter.
If you are not in a standard location, you need to add the full path before the file name. But every time it's too much trouble to run, a "once and for all" approach is to add this path to the environment variables. The command "path= $PATH: Path" can add this path to the environment variable, but the exit command line fails. To be effective permanently, you need to add this line to the environment variable file. There are two files available: "/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" means that the path to the executable file includes the path originally set, as well as all paths from "Path 1" to "Path N". When the user enters a string of characters and presses the carriage return, the shell in turn will find the corresponding executable file in these paths and give it to the system core for execution. The "$PATH" indicates that the previously set path is still valid and that you should not omit it. Some software may also have an environment variable of a type other than "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 pathname in the UNIX class system environment variable is separated by a colon, not a semicolon. In addition, the more installed software, the more environment variables, in order to avoid confusion, we recommend that all statements are added at the end of the file, in the order in which the software is installed.
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 an annotation symbol, written here without any effect except for visual separation.
Setup is complete, log off and log in again, and the settings will take effect. If you do not log off, executing these statements directly in the shell can take effect, but the scope is limited to the shell that executes the statements.
After the relevant environment variables are in effect, you do not have to run into the software executable directory to operate.
Attention:
1,/etc/profile inside the change path is unreasonable, because this variable may be modified by other scripts. So you'd better write in ~/.BASHRC.
2, Export path= $PATH:/tools/bin
Log off and then log back on.
If you write the above sentence in a certain terminal,
That is only in this terminal modified path, and closed the terminal, path or the original path.
What are you