Linux environment variable settings etc profile

Source: Internet
Author: User

First, Linux Types of variables

According to the lifetime of the variables, the Linux variables can be divided into two categories:

1, permanent: Need to modify the configuration file, the variable is permanently effective.

2, Temporary: Use the Export command declaration, the variable is closed shell failure.

Ii. three ways to set up variables

1. Add the variable "to all users (permanent)" in the/etc/profile file.

Using VI to add a variable to the file/etc/profile file, the variable will be valid for all users under Linux and is "permanent".

Example: Edit the/etc/profile file, add the CLASSPATH variable

# Vi/etc/profile

Export classpath=./java_home/lib; $JAVA _home/jre/lib

Note: If you want to run the file immediately after you modify it, you can only take effect the next time you re-enter the user. Source/etc/profile.

2. Add variable "to single user (permanent)" in. bash_profile file in user directory.

Use VI to add variables to the. bash_profile file in the user directory, and change the amount to be valid only for the current user and be "permanent".

For example: Edit the. Bash_profile under the Guok User directory (/home/guok)

$ vi/home/guok/.bash.profile

Add the following content:

Export classpath=./java_home/lib; $JAVA _home/jre/lib

Note: If you want to take effect immediately after modifying a file, run $ source/home/guok/.bash_profile or you can only take effect the next time you re-enter the user.

3. Run the Export command definition variable "only for current shell (BASH) is active (temporary)"

Use the [export variable name = variable value] directly under the Shell's command line

Define the variable, which is valid only under the current shell (bash) or its child shell (bash), the shell is closed, the variable is invalidated, the new shell is opened without the variable, and needs to be redefined.

Third, PATH declaration, in the form of:

Path= $PATH: <path 1>:<path 2>:<path 3>:------: <path n>

You can add the specified path yourself, separated by a colon. When the environment variable changes, it takes effect the next time the user logs on.

If you want to take effect immediately, you can execute the following statement: $source. bash_profile

It is important to note that it is best not to put the current path "./" in path, which may be subject to unexpected attacks.

When you are finished, you can view the current search path through the echo $PATH. With this customization, you can avoid frequent launches of programs that are outside the path of the shell search.

Linux environment variable settings etc profile

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.