How to modify environment variables in Linux
In the Linux operating system, sometimes some software is installed in the tutorial. After the installation is successful, I am very happy to prepare to run the corresponding commands of the software, but occasionally encounter "Command not found... "Prompt. The reason is that the software you install requires environment variables to run.
There are three methods to modify environment variables in Linux (taking setting environment variables of jekyll as an example)
1. Direct assignment
Enter
PATH = $ PATH: // usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/bin
This method is only valid for the current session. That is to say, the PATH setting becomes invalid every time the system is logged out or logged out.
2. Modify the/ect/profile file
Add
Export PATH = $ PATH:/usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/bin // note: "=" there cannot be any space on either side of this method is the best, the PATH value will not be changed unless you manually modify it.
3. Modify the. bachrc/. bash_profile file.
Add
Export PATH = $ PATH:/usr/lib64/ruby/gems/2.1.0/gems/jekyll-2.5.3/bin
This method works for the current user. It will also become invalid when you log out of the system.
Note: For method 2 and 3, to make the PATH take effect, you must log on again. The following method can simplify the work: If/etc/profile is modified, after editing, execute source profile or execute the dot command. the/profile PATH value takes effect immediately. The principle of this method is to execute the/etc/profile shell script again. Note that if sh/etc/profile is used, sh is executed in the sub-shell process, even if the PATH is changed, it will not be reflected in the current environment, but the source is executed in the current shell process, so we can see the PATH change.
This article permanently updates the link address: