Three ways to modify environment variable path path under Linux system

Source: Internet
Author: User

For example, to add the/etc/apache/bin directory to path, there are three methods:

1. #PATH = $PATH:/etc/apache/bin

With this method, only the current session is valid, meaning that the PATH setting is invalidated whenever the system is logged out or logged off

2. #vi/etc/profile

Add Path= $PATH in place:/etc/apache/bin (Note: = There can be no spaces on either side of the equals sign)

This method is best unless you manually force the value of path to change, otherwise it will not be changed

3. #vi ~/.bash_profile

Modify the path line to add/etc/apache/bin

This method is for the user to work

Note: To change path, you must re-login to take effect, the following methods can simplify the work:

If/etc/profile is modified, then the source profile or the Execute Point command is executed after the edit finishes. The value of/profile,path will take effect immediately.

The principle of this method is to execute the/etc/profile shell script again, note that if the use of sh/etc/profile is not possible, because SH is executed in the child shell process, even if the path changes will not be reflected in the current environment, but the source is in the current Shell process, so we can see the change in path.

This way you learn how to modify the environment variable path path under the Linux system.

1, under the Windows system, many software installations need to configure environment variables, such as installing the JDK, if you do not configure environment variables, run the JAVAC command in a directory other than the software installation, you will report a similar error that the file cannot be found.

2. What are environment variables? To put it simply, it is to specify a directory, when running the software, the relevant program will follow the directory to find the relevant files. The most practical function of setting variables is that you don't have to copy some DLL files into the system directory, and path is a system variable that is a series of paths for the system to search for DLL files.

Under the Linux system, if you download and install the application, it is very likely that the "command not found" prompt will appear when you type its name. If you go to the installation directory folder every time, it is too cumbersome to find an executable file to work with. This involves setting the environment variable path, which is also a part of customizing the environment variable under Linux

Three ways to set environment variables under Linux:

If you want to add a path to $path, you can do this as follows:

1, console settings, not in favor of this way, because he only to the current shell function, change a shell setting is invalid:

$PATH = "$PATH":/new_path (Close shell path reverts to the original path)

2, modify the/etc/profile file, if your computer only as a development use of the push to use this method, because all the user's shell has the right to use this environment variable, may bring security issues to the system. This is for all the users, all the shells

Add at the bottom of/etc/profile: Export path= "$PATH:/new_path"

3, modify the BASHRC file, this method is more secure, it can use these environment variables to control the user level, here is for a specific user, if you need to give a user permissions to use these environment variables, you only need to modify their personal user home directory of the. bashrc file on it.

Add the following:

Export path= "$PATH:/new_path"

Three ways to modify environment variable path path under Linux system

Related Article

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.