Ubuntu environment variable location [cpp] Ubuntu Linux system environment variable configuration file:/etc/profile: The first file used when the operating system customizes the user environment during logon, this file sets environment information for each user in the system. This file is executed when the user logs on for the first time. /Etc/environment: the second file used by the operating system during logon. Before the System reads your own profile, it sets the environment variable of the environment File. ~ /. Profile: The third file used for logon is. profile file. Each user can use this file to input shell information dedicated to their own use. When a user logs on, this file is only executed once! By default, it sets some environment variables to execute the user's. bashrc file. /Etc/bashrc: execute this file for every user running bash shell. When bash shell is opened, this file is read .~ /. Bashrc: This file contains bash information dedicated to your bash shell. This file is read when you log on and every time you open a new shell. How to Set PASH environment variables: Method 1: Under the user's main directory. profile or. log on to your user (non-root) in the bashrc file (recommended) and enter: $ sudo gedit ~ /. Profile (or. bashrc) You can add the following PATH settings to the end of this file: export PATH = "$ PATH: your path1: your path2... "save the file, log out, and log on again. The variable takes effect. The variables added in this method are only valid for the current user. Method 2: The profile file under the system directory (Exercise caution) has a profile file under the etc directory of the system to edit the file: $ sudo gedit/etc/profile Add the following PATH settings at the end: export PATH = "$ PATH: your path1: your path2... after editing and saving the file, restart the system and the variable takes effect. The variables added in this method are valid for all users. Method 3: The environment file in the system directory (Exercise caution) has an environment file under the etc directory of the system to edit it: $ sudo gedit/etc/environment find the following PATH variable: PATH = "<......> "Modify the PATH variable and add your own path to it, for example, PATH =" <......>: your path1: your path2... "Each path is separated by a colon. This file also takes effect after being restarted, affecting all users. Note that export PATH =… is not added here.... Method 4: Enter $ sudo export PATH = "$ PATH: your path1: your path2... "This method takes effect immediately, but the setting becomes invalid after the user logs out or the system restarts. This method is suitable for setting temporary variables. Note: You must be cautious when modifying methods 2 and 3, especially through the root user. If the modification is incorrect, it may cause some serious system errors. Therefore, the first method is recommended. In addition, it is best not to develop embedded Linux under root (unless you are very familiar with Linux !!), To avoid serious system errors caused by improper operations. The following is an example of the problem caused by incorrect modification to the environment file and the solution: the problem is caused by the failure to log on because the environment variable is accidentally set in the etc/environment file: do not set export PATH in etc/environment. This will cause the system to fail to log on after the restart. Solution: In the logon interface, alt + ctrl + f1 enter the command mode, if it is not the root user, you need to type it (the root user is not allowed to be so arrogant, gedit editing will not be displayed) /usr/bin/sudo/usr/bin/vi/etc/environment move the cursor to the export PATH ** row, and delete the row two times in a row. Input: wq save and exit; then, type/sbin/reboot to restart the system (need to boot may be prompted, and power off directly at this time ~ /. Profilesudo gedit ~ /. Profile and then add: export PATH = "$ PATH: mtpath" to restart the system to run the program in the complete PATH when no environment variable is enabled. View environment variables: echo $ PATH