Changes to the Ubuntu environment variable path

Source: Internet
Author: User

sudo nano/etc/environment

Environment variables are closely related to the shell, and the user logs on to the system and launches a shell. It's usually bash for Linux, but it can be reset or switched to another Shell. For UNIX, it could be cshelll. Environment variables are set by shell commands, and set environment variables can be used by all current users running programs. For bash, the shell program can use variable names to access the appropriate environment variables, and export to set environment variables. This is illustrated by a few examples below.

1) Etc/profile: This file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time.
and collect the shell settings from the configuration file of the/ETC/PROFILE.D directory.
Note: Here we set the global variables that are available to all users.

2)/ETC/BASHRC: executes this file for each user running the bash shell. When the bash shell is opened, the file is read.

3) ~/.bash_profile: Each user can use this file to enter the shell information dedicated to their own use, when the user log on, the file is only executed once! By default, he sets some environment variables to execute the user's. bashrc file.

Note: ~ Under Linux is the variable representing the home.
In addition to different Linux operating systems, this file may be different, may be ~/.bash_profile, ~/.bash_login or ~/.profile one or several, if there are several, then the order of execution is: ~/.bash_ Profile, ~/.bash_login, ~/.profile. For example, I use Ubuntu, my User folder, the default is only the ~/.profile file.

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

We can now modify the PATH variable:

Method One: Directly modify the ~/.profile file:

That is, by entering Shell:vi ~/.profile to open the file,

At the end of the file, see the following code:

Fi

# set PATH so it includes user ' s private bin if it exists
If [-D "$HOME/bin"]; Then
Path= "$HOME/bin: $PATH"
Fi
In the end, the following code:

Fi
Path= "$HOME/bin: $PATH: #####"
Fi
# # # #代表用户要添加的PATH值, separated by colons (:) in multiple middle.

Method Two: Through the shell command export implementation:

echo $PATH to view the value of the current PATH

Export path= $PATH: #####

Used to set the value of path

If you want to add/HOME/HOUJX to path, you can use the

Export path= $PATH:/HOME/HOUJX

You can see the following results:

Echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Export path= $PATH:/HOME/HOUJX
Echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/houjx

Note: However, it should be noted that the path variable for this setting (method two) is only valid for the current terminal, closing the

Terminal is open, its corresponding path is constant, and

It's/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games.

1) Etc/profile: This file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time.

Note: Here we set the global variables that are available to all users.

2)/ETC/BASHRC:
executes this file for each user running the bash shell. When the bash shell is opened, the file is read.

3) ~/.bash_profile: Each user can use the file to enter shell information dedicated to their own use, when the user logs on, the file executes only once! By default, he sets some environment variables to execute the user's. bashrc file.
Note: ~ Under Linux is the variable that represents the home.
In addition to different Linux operating systems, this file may be different, may be ~/.bash_profile, ~/.bash_login or ~/.profile one or several, if there are several, then the order of execution is: ~/.bash _profile, ~/.bash_login, ~/.profile. For example, I use Ubuntu, my User folder, the default is only the ~/.profile file.


4) ~/.BASHRC: (Note: This file is. Start with, so it is hidden in the folder)
So how do we add our own defined environment variables?
Open the file with Notepad, and then write it in the last:
Export Xiaokang=xiaokang


and then save it so that each time we open a new terminal, we have this variable in effect. Remember, if you have opened a terminal, and then you modify the file, then this terminal will not be effective. In general, the user is best to make changes here, but sometimes it will overwrite the parent variables, such as path is root set, but if you write in this file path=xx, then all of the future path is XX, So we should write in this file as:
Path= $PATH: XX
this adds the original and your own. and note that the Linux system uses: Split to represent side by side, not Windo;

Transfer from http://www.cnblogs.com/xiaofengkang/archive/2011/11/26/2264458.html

http://blog.csdn.net/ylgrgyq/article/details/6955591

Changes to the Ubuntu environment variable 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.