Linux Software Installation Use (8) path and environment variable __linux

Source: Internet
Author: User
Tags readable

1, Ubuntu Exclusive Way
Edit the/etc/ld.so.conf file, and if the following statement does not exist, join:
Include/etc/ld.so.conf.d/*.conf
Then create a new file below/etc/ld.so.conf.d that ends with. conf.
Write the path you want to set in the new. conf file, for example:
~/mypath/bin

2. bashrc files under the user directory
In the user's home directory, there is a. bashrc file that edits the file:
$gedit ~/.BASHRC
At the end, add the shell statement that requires the variable to be set, for example:
Export Path=~/mypath/bin: $PATH
After the file is saved, it can be immediately taken into effect in the newly opened terminal window.
Variables added in this way can only be used by the current user.

3, the system directory under the profile file
In the system's etc directory, there is a profile file, edit the file:
$gedit/etc/profile
At the end, add the shell statement that requires the variable to be set, for example:
Export Path=~/mypath/bin: $PATH
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.

4, the System directory of environment files
In the system's etc directory, there is a environment file to edit the file:
$gedit/etc/environment
Locate the following PATH variable:
Path= "<......>"
Modify the path variable in which you can add your own path, for example:
Path= "~/mypath/bin:<......>"
Each path is separated by a colon. The file is also reset effective and affects all users.

-------------------------------------------

There are two ways to set the environment variable PATH in the Ubuntu system. The first applies to setting up path for a single user, and the second is to set the path globally.
The first method:
There is a. bashrc file in the user's home directory where you can add PATH to the following settings:
Export path= "$PATH:/your path1/:/your path2/..."
Note: Separate each path with ":".
Log off reboot X on it.
The second method:
Increased in the/etc/profile.
Path= "$PATH:/home/zhengb66/bin"
Export PATH


environment variables are closely related to the shell, and the user starts a shell after logging in to the system. It's usually bash for Linux, but it can be reset or switched to another Shell. For UNIX, it may be cshelll. Environment variables are set through shell commands, and set up environment variables that can be used by programs run by all current users. For bash, the shell program can access the corresponding environment variables through the variable name, setting the environment variable by export. Here are several examples to illustrate.

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

2)/ETC/BASHRC:Execute 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 shell information that is specific to their own use.when the user logs 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 to represent the variable of home.
In addition, under different Linux operating systems, this file may be different, may be
~/.bash_profile ~/.bash_login or ~/.profile one or several of these, if there are several, then the order of execution is: ~/.bash_profile, ~/.bash_login, ~/. Profile For example, I use Ubuntu, my User folder under the default is only ~/.profile files.

4) ~/.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.
(Note: This file is. Started, so it's hidden in the folder)
So how do we add our own defined environment variables?
Open the file in Notepad and write it in the final:
Xiaokang=kangkang
Then save it so that every time we open a new terminal, we have this variable in effect. Remember, if you have opened a terminal and then you have modified the file, it will not work under this terminal.
generally the user is best to make changes here, but sometimes it overrides the parent variable, for example, the path is set by root, but if you write path=xx in this file, all future path will be XX, so we should write in this file as:
Path= $PATH: XX
This adds the original to your own. And note the use of the Linux system: split, rather than windo;
3 and 4 are in the user directory, their only difference is:. Bash_profile can only be started once when you log on. This 3 file doesn't seem to be in my Ubuntu.

5) ~/.bash_logout:Executes the file every time you exit the system (the Bash shell is exited).
In addition, the variables set in the/etc/profile (global) can be applied to any user, while the variables (local) set in ~/.BASHRC can only inherit the variables in/etc/profile, they are/"parent-child/" relationships.

~/.bash_profile is an interactive, login-style entry into bash to run
~/.BASHRC is the interactive non-login way into bash run
Usually the two settings are roughly the same, so the former usually calls the latter.

Well, summarize how they are executed:
when you log in and the login shell is bash, bash first executes the command in the/etc/profile file (if the file exists), and then it looks in order for ~/.bash_profile,~/. Bash_login or ~/.profile files, and executes the commands found in the first readable file. When logon bash exits, it executes the commands in the ~/.bash_logout file.
When you start an interactive bash, it executes the commands in the ~/.BASHRC file (if the file exists and is readable). When you start interactively to run a shell script, bash looks for the BASH_ENV environment variable and determines the name of the execution file.

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.