Ubuntu Linux environment variable path settings

Source: Internet
Author: User
Ubuntu Linux environment variable path settings
0Add to favoritesArticle,

Add this article to favorites


Posted two hours ago,
Existing 2 Secondary reading
Total 0 Comments
0 Add this article to your favorites:

/Etc/profile: The first file used by the operating system to customize the user environment during login. This file sets environment information for each user in the system. When the user logs on for the first time, the file is executed.

/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, the 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: The. profile or. bashrc file in the user's main directory (recommended)

Log on to your user (non-root) and enter:

$ Sudo gedit ~ /. Profile (or. bashrc)

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

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: profile files in the system directory (Exercise caution)

There is a profile file under the etc directory of the system to edit the file:

$ Sudo gedit/etc/profile

Add the path settings as follows:

Export Path = "$ path: Your path1: Your path2 ..."

After the file is edited and saved, restart the system and the variable takes effect.

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

Method 3: Environment files in the system directory (Exercise caution)

In the etc directory of the system, there is an environment file 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
Caution 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, embedded
Linux development should not be performed 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:

problem: You cannot log on because you accidentally set environment variables in etc/environment.
note: do not set export path in etc/environment. As a result, the system cannot be logged on after the restart.
solution:
On the logon page, press Alt + Ctrl + F1 to enter the command mode. If the user is not the root user, enter the command mode. (the root user is not allowed to enter the command mode. gedit editing will not be displayed)
/usr/bin/sudo/usr/bin/VI/etc/environment
move the cursor to the export path ** line, delete the row two times consecutively by D.
input: WQ save and quit;
type/sbin/reboot to restart the system (need to boot may be prompted, and power off is directly displayed at this time)

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.