Linux adds the command to the PATH method

  • 2020-05-15 03:25:54
  • OfStack

linux
LinuxApacheBash

Simply put, PATH is a string variable for a set of paths. When you enter a command with no path, LINUX will look for the command in the path recorded by PATH. If there is, it will be executed. If there is not, the command will not be found. Such as under the root directory/can input command ls, also can input ls in/usr directory, but in fact ls order two directory, not the go/when you enter ls command LINUX bin, / usr/bin, / sbin directory for the command. And PATH is defined/bin: / sbin: / usr bin road king of variables, such as between the colon to the contents of separator.

How to customize the path:

Suppose you new compiler installed a apache under/usr local/apache, every time you want to start without a big knock string of characters (# / usr/local/apache bin/apachectl start) to use it, but directly as ls1 sample directly input like this anywhere (# apachectl start) brief command. At this time, you need to modify the environment variables PATH, accurately is adding a value to PATH usr/local/apache/bin.

Will/usr local apache/bin added to the PATH has three methods:

1. Set PATH directly on the command line

# PATH=$PATH:/usr/local/apache/bin

With this approach, it is only valid for the current session, which means that the PATH setting will fail each time you log out or log out of the system.

2. Set PATH in profile

# vi /etc/profile

Find export line, below 1 line, new content is: export PATH = $PATH: / usr local/apache/bin.

Note: = no Spaces are allowed on both sides of the equal sign. This approach is best, and will not be changed unless the value of PATH is manually forced.

Changes to PATH after editing /etc/profile will not take effect immediately, but you can execute the # source profile command if you need to take effect immediately.

3. Set PATH in the current user's profile

# vi ~/.bash_profile

Modify PATH line, put/usr local/apache bin added, such as: PATH = $PATH: $HOME/bin: / usr local/apache/bin.

# source ~/.bash_profile

Let this change take effect.

Note: this method only works for the current user. The modification is invalid for other users.

Remove custom path:

When you find a new path/usr/local/apache/bin useless or when you don't need, you can be in before the modified/etc/profile or ~ /. bash_profile file you once custom path.


Related articles: