How to set up environment variables under Linux Path__linux

Source: Internet
Author: User
Ubuntu Linux environment variable path settings0 People collect this article, Collection This article was published 2 hours ago, there have been2Times read a total0A comment0People collect this article Ubuntu Linux system environment variable configuration file:
/etc/profile: The first file that is used when the operating system customizes the user's environment at logon, which sets the environment information for each user of the system, and when the user first logs on, the file is executed.

/etc/environment: The second file that is used by the operating system at logon, the system sets the environment variable for the environment file before reading your own profile.

~/.profile: The third file that you use when you log on is a. profile file that each user can use to enter shell information that is specific to their own use, and that file executes only once when the user logs on! By default, he sets some environment variables, Executes the user's. bashrc file.

/ETC/BASHRC: This file is executed for each user running the bash shell. When the bash shell is opened, the file is read.

~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log in and each time you open a new shell.



Pash environment variable Setting method:

Method one: the. Profile or. bashrc file in the Household Head directory (recommended)

Log in to your user (not root) and enter at the end:
$ sudo gedit ~/.profile (or. bashrc)
The following settings can be added to the path at the end of this file:
Export path= "$PATH: Your path1:your path2 ..."
Save the file, log off and log on, and the variable takes effect.
Variables added in this way are valid only for the current user.

Method Two: Profile files under the system directory (cautious)

In the system's etc directory, there is a profile file, edit the file:
$ sudo gedit/etc/profile
The following settings are added to the path at the end:
Export path= "$PATH: Your path1:your path2 ..."
After the file is edited and saved, reboot the system and the variable takes effect.
The variables added in this way are valid for all users.

Method Three: Environment files under the system directory (cautious)

In the system's etc directory, there is a environment file to edit the file:
$ sudo gedit/etc/environment
Locate the following PATH variable:
Path= "<......>"
Modify the path variable in which you can add your own path, for example:
Path= "<......>:your path1:your path2 ..."
Each path is separated by a colon. The file is also reset effective and affects all users.
Note that this is not the addition of export path= ....

Method Four: Enter directly under the terminal

$ sudo export path= "$PATH: Your path1:your path2 ..."
This way the variable takes effect immediately, but when the user logs out or the system restarts, the settings become invalid, and the settings for the temporary variable are appropriate.


Note: Methods Two and three modifications need to be cautious, especially through root modification, which can lead to some serious system errors if modified incorrectly. Therefore, the author recommends using the first method. In addition, the development of embedded Linux is best not done under root (unless you are already very familiar with Linux). To avoid serious system errors due to improper operation.

The following is an example of a problem caused by an error modification to a environment file and a workaround:

Problem: Because accidentally in the etc/environment set in the environment variable caused unable to log in
Tip: Do not set up export path in etc/environment this will cause the system to log on after reboot
Workaround:
In the login interface alt +CTRL+F1 into command mode, if not the root user needs to type (root user is not so verbose, gedit edit will not be displayed)
/usr/bin/sudo/usr/bin/vi/etc/environment
The cursor moves to the export path** line and deletes the row by two consecutive times D.
Input: Wq save exit;
Then type the/sbin/reboot reboot system (you may be prompted need to boot, at this point direct power off)
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.