Ubuntu Linux environment variable PATH setting

  
Ubuntu Linux system environment variable configuration file:

/etc/profile : The first file used by the operating system to customize the user environment when logging in, this file is each of the system The user sets the environment information, which is executed when the user logs in for the first time.

/etc /environment : The second file used by the operating system when logging in. The system sets the environment variables of the environment file before reading your own profile.

~/.profile : The third file used during login is the .profile file. Each user can use this file to enter the shell information dedicated to their own use. When the user logs in, the file is used. Execute only once! By default, he sets some environment variables and executes the user's .bashrc file.

/etc/bashrc : Execute this file for each user running the bash shell. This file is read when the bash shell is opened.

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

Setting method of PASH environment variable:

Method 1: The .profile or .bashrc file in the user's home directory (recommended)

Log in to your user (non-root ), in the terminal input:

$ sudo gedit ~/.profile(or .bashrc)

You can add the PATH settings at the end of this file as follows:

export PATH= & rdquo;$PATH:your path1:your path2 …”

Save the file, log out and log in, the variable takes effect.

The variables added in this mode are only valid for the current user.

Method 2: Profile file in the system directory (cautious)

In the system's etc directory, there is a profile file, edit the file:

$ sudo gedit /Etc/profile

The settings for adding PATH at the end are as follows:

export PATH=”$PATH:your path1:your path2 …”

After restarting the system, the variables take effect.

The variables added in this way are valid for all users.

Method 3: Environment file under the system directory (cautious)

In the system's etc directory, there is an environment file, edit the file:

$ sudo gedit /Etc/environment

Locate the following PATH variable:

PATH=”<……>”

Modify the PATH variable and include yourself in it The path can be, for example:

PATH=”<……>:your path1:your path2 …”

Each path is separated by a colon. The file is also restarted and affects all users.

Note that this is not to add export PATH=…

Method 4: Enter directly under the terminal

$ sudo export PATH=”$PATH:your path1:your path2 …”

Effective, but the settings become invalid after the user logs out or the system restarts, suitable for the setting of temporary variables.

Note: The modifications of methods 2 and 3 need to be cautious, especially through the root user. If the modification is wrong, it may cause some serious system errors. Therefore, I recommend using the first method. In addition, the development of embedded Linux is best not to be done under root (unless you are already familiar with Linux!!), so as to avoid serious system errors caused by improper operation.

Copyright © Windows knowledge All Rights Reserved