Linux environment variable settings

 

1, in the Windows system, a lot of software installation is required to configure the environment variables, such as installing jdk, if you do not configure the environment variables, run the javac command in the directory of non-installation of the software, the report will not find the file, similar errors.

2. What is the environment variable? Simply put, is to specify a directory, run the software, the program will look for relevant documents in accordance with that directory. Set the variable most useful features for most people is: do not copy some dll files to the system directory, but this path is a series of system variables dll file system search path

In the Linux system, if you download and install the application, it is likely "command not found" prompt content appears when typing its name. If each time to the installation directory folder, find the executable file to be too cumbersome to operate. This involves setting environmental variable path, and the Path is set in a custom Linux environment variable part

Three methods under Linux environment variable settings :

If you want to join a path to $ PATH, you can do something like this:

It works only for the current shell environment variables

1, the console settings, this is deprecated, because he works only for the current shell, for a shell set is invalid:

Direct console input: $ PATH = "$ PATH": / NEW_PATH (closed shell Path will revert to the original path)

All users are functional environment variables

2, modify / etc / profile file, if your computer is just keep pushing as developed using this approach, since all users have the right to use the shell environment variables, may give the system security issues. This is for all users, all of the shell

vi / etc / profile

Add in the bottom of / etc / profile of: export PATH = "$ PATH: / NEW_PATH"

For the current specific user work environment variables

3, modify bashrc files, this method is more secure, it can have permission to use these environmental variables to control user level, here is tied to a specific user variables if you need to use these environments to a user privileges, you only you need to modify the .bashrc file in their personal user home directory on it.

we ~ / .bashrc

In the following is added:

Export  PATH="$PATH:/NEW_PATH"

 

 

Ubuntu Linux system environment variable configuration file : / 
etc / Profile: when you log in, the first file used by the operating system to customize the user environment settings file for each user environment information system, when a user first logs in, the file is executed. 

/ etc / environment: The second file operating system at login, the system before reading your own profile, set the environment variable environment file. 

~ / .profile: used when logging in the third file is .profile files, each user can use the file input information specific to shell their own use, when a user logs in, the default file is performed only once! next, he set some environment variables, execute .bashrc file users.

/ etc / bashrc:.. execute this file to each user when running the bash shell bash shell is opened, the file is read 

~ / .bashrc: This file contains dedicated to the bash shell bash your information, log on when and when every time you open a new shell, which the file is read. 



PASH environment variable setting method: 

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

to log on to your user (non-root), enter in a terminal: 
$ sudo gedit ~ / .profile (or .bashrc) 
PATH can be added at the end of this file are set as follows: 
Export PATH = "$ PATH: your path1: path2 your ..." 
to save the file, log off and log back variables to take effect. 
Add variable in this manner is valid only for the current user. 

Method two: profile file system directory (cautiously) 

under etc directory system has a profile file, edit the file: 
$ the sudo the gedit / etc / profile 
is provided at the end of addition of the PATH follows: 
Export PATH = "$ PATH: your path1: your path2 ... " 
after editing and saving the file, restart the system variables to take effect. 
Variables added this way are effective for all users. 

Method three: system directory under the environment file (caution) 

in the etc directory of the system, there is an environment file, edit the file: 
$ sudo gedit / etc / environment 
find the PATH variable: 
PATH = "<..... .> " 
modify the pATH variable, to which its own path. For example: 
pATH =" <......>: your path1: path2 your ... " 
between the respective path separated by a colon. The document also restart to take effect, affecting all users. 
Note that this is not to add export PATH = .... 

Method four: direct input in the terminal 

$ sudo export PATH = "$ PATH  : your path1: your path2 ..."
This way variables to take effect immediately, but after users log off or reboot the system settings become invalid, for the provision of temporary variables. 


Note: The modification method of two and three need to be careful, especially modified by the root user, if you modify the error, could lead to some serious system errors. Therefore, we recommend using the first method. Also embedded Linux development is best not to be in the root (unless you are already familiar with !! on Linux), in order to avoid improper operation of the system because a serious error.

Here is an erroneous question of amending the result in the environment file and solutions Example: 

Question: because they do not care etc / environment where in the environment variable you can not sign 
Tip: Do not set after export PATH This will lead to restart login etc / environment in not enter the system 
solution: 
in the login screen alt + ctrl + f1 to enter the command mode, if not the root user needs to type (root users are not allowed so wordy, gedit editor will not be displayed) 
/ usr / bin / sudo / usr / bin / vi / etc / environment 
cursor to export PATH ** line, press d twice in a row to delete the line; 
enter: wq to save and exit; 
then type / sbin / reboot reboot the system (you may be prompted need to boot, this time direct power off)

Guess you like

Origin blog.csdn.net/nicholas_duan/article/details/93397258