Environment variable configuration file in CentOS, centos environment variable

Source: Internet
Author: User

Environment variable configuration file in CentOS, centos environment variable

CentOS environment variable configuration file system is a hierarchical system, which is similar to other multi-user application system configuration files, including global, user, and shell, in addition, different levels are sometimes similar to inheritance relationships. The following uses the PATH variable as an example.

1. Modifying the/etc/profile file affects global users. /Etc/profile runs when the first user logs on after the system is started. Add

export PATH=/someapplication/bin:$PATH

To make the modification take effect, you can restart the system or execute

source /etc/profile
echo $PATH

2. Modifying/etc/environment will affect the global environment. The difference between the/etc/environment file and the/etc/profile file is:/etc/environment sets the system environment, while/etc/profile sets the environment of all users, that is,/etc/environment is irrelevant to the user and runs at system startup. In the/etc/environment file, add

PATH=/someapplication/bin:$PATH

In CentOS and most Linux systems, $ is used to access the environment variables, and the PATH environment variables are separated by colons. In Windows, two % access environment variables are used, and PATH is separated by semicolons (;). For example:

set PATH=E:\someapplication\bin;%PATH%

3. Modify ~ /. Bash_profile (preferred), which affects the current user. In ~ /Add to the. bash_profile File

export PATH=/someapplication/bin:$PATH

4. Modify/etc/bashrc (/etc/bash. bashrc in Ubuntu and Debian) to affect the bash shell used by all users. /Etc/bashrc is born to initialize the bash shell and runs when the bash shell is opened. Bash shell has different types: logon shell and non-Logon shell. to log on to shell, you need to enter the user password. For example, login shell mode is enabled when logging on to ssh or su-command elevation. The non-login shell does not execute any profiel files. The interactive shell and non-interactive shell provide a command prompt. The interactive shell mode is used to wait for the user to enter the command, and the direct running of the script file is not an interactive shell mode, generally, no bashrc file is executed in non-interactive shell mode. Select whether to modify/etc/bashrc based on the preceding conditions.

5. Modify ~ /. Bashrc, which affects the bash shell used by the current user.

6. Execute the following command on the terminal, which only affects the current terminal.

export PATH=/someapplication/bin:$PATH

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.