How to modify environment variables in Linux

Source: Internet
Author: User

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:

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.